"use strict";
/*
 * @adonisjs/core
 *
 * (c) AdonisJS
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.defineTestsBindings = void 0;
/**
 * Define test bindings
 */
function defineTestsBindings(ApiRequest, ApiClient, CookieClient) {
    /**
     * Serializing for parsing response cookies
     */
    ApiClient.cookiesSerializer({
        /**
         * The methods on the Request class encrypts and signs cookies.
         * Therefore, the prepare method returns the value as it is
         */
        prepare(_, value) {
            return value;
        },
        /**
         * Process the server response and convert cookie value to a
         * plain string
         */
        process(key, value) {
            return CookieClient.parse(key, value);
        },
    });
    /**
     * Define cookie
     */
    ApiRequest.macro('cookie', function (key, value) {
        const signedValue = CookieClient.sign(key, value);
        if (signedValue) {
            this.cookiesJar[key] = { name: key, value: signedValue };
        }
        return this;
    });
    /**
     * Define encrypted cookie
     */
    ApiRequest.macro('encryptedCookie', function (key, value) {
        const encryptedValue = CookieClient.encrypt(key, value);
        if (encryptedValue) {
            this.cookiesJar[key] = { name: key, value: encryptedValue };
        }
        return this;
    });
    /**
     * Define plain cookie
     */
    ApiRequest.macro('plainCookie', function (key, value) {
        const encodedValue = CookieClient.encode(key, value);
        if (encodedValue) {
            this.cookiesJar[key] = { name: key, value: encodedValue };
        }
        return this;
    });
}
exports.defineTestsBindings = defineTestsBindings;
