"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.installStandardHooks = installStandardHooks;
exports.resetSrcModuleCache = resetSrcModuleCache;
exports.makeMockRequest = makeMockRequest;
const __ΩRecord = ['K', 'T', 'Record', 'l\'e#"Rb!b"Pde"!N#!w#y'];
const node_test_1 = require("node:test");
const http_1 = require("@deepkit/http");
const mysql_1 = require("@deepkit/mysql");
const postgres_1 = require("@deepkit/postgres");
const _1 = require(".");
function installDbRejectionHooks() {
    node_test_1.mock.method(mysql_1.MySQLConnectionPool.prototype, 'getConnection', () => {
        throw new Error('Database is not enabled in testing mode');
    });
    node_test_1.mock.method(mysql_1.MySQLDatabaseAdapter.prototype, 'disconnect', () => { });
    node_test_1.mock.method(postgres_1.PostgresConnectionPool.prototype, 'getConnection', () => {
        throw new Error('Database is not enabled in testing mode');
    });
    node_test_1.mock.method(postgres_1.PostgresDatabaseAdapter.prototype, 'disconnect', () => { });
}
installDbRejectionHooks.__type = ['installDbRejectionHooks', 'P"/!'];
function installStandardHooks(tf) {
    (0, node_test_1.before)(() => tf.start());
    (0, node_test_1.after)(() => tf.stop());
    if (!tf.options?.enableDatabase) {
        (0, node_test_1.beforeEach)(() => installDbRejectionHooks());
        (0, node_test_1.afterEach)(() => tf.sql.clearMocks());
    }
    (0, node_test_1.beforeEach)(() => tf.resetToSeed());
    (0, node_test_1.afterEach)(() => {
        node_test_1.mock.timers.reset();
        node_test_1.mock.restoreAll();
    });
}
installStandardHooks.__type = [() => _1.TestingFacade, 'tf', 'installStandardHooks', 'PP7!2""/#'];
function resetSrcModuleCache() {
    for (const key of Object.keys(require.cache)) {
        if (key.includes('/dist/') || key.includes('/src/')) {
            delete require.cache[key];
        }
    }
}
resetSrcModuleCache.__type = ['resetSrcModuleCache', 'P"/!'];
const __ΩMockMethod = ["GET", "PUT", "POST", "DELETE", 'MockMethod', 'P.!.".#.$Jw%y'];
const __ΩMockBody = [() => __ΩRecord, 'MockBody', '&"o!#w"y'];
makeMockRequest.__type = [() => _1.TestingFacade, 'tf', () => __ΩMockMethod, 'method', 'url', () => __ΩMockBody, 'body', () => http_1.MemoryHttpResponse, 'makeMockRequest', 'PP7!2"n#2$&2%n&2\'P7(`/)'];
makeMockRequest.__type = [() => _1.TestingFacade, 'tf', () => __ΩMockMethod, 'method', 'url', () => __ΩRecord, 'headers', () => __ΩMockBody, 'body', () => http_1.MemoryHttpResponse, 'makeMockRequest', 'PP7!2"n#2$&2%&&o&#2\'n(2)P7*`/+'];
async function makeMockRequest(tf, method, url, headersOrBody, body) {
    const headers = body ? headersOrBody : tf.options?.defaultTestHeaders;
    return tf.request(http_1.HttpRequest[method](url)
        .headers({ 'content-type': 'application/json', ...headers })
        .body(JSON.stringify(body ?? headersOrBody)));
}
makeMockRequest.__type = [() => _1.TestingFacade, 'tf', () => __ΩMockMethod, 'method', 'url', () => __ΩRecord, () => __ΩMockBody, 'headersOrBody', () => __ΩMockBody, 'body', () => http_1.MemoryHttpResponse, 'makeMockRequest', 'PP7!2"n#2$&2%P&&o&#n\'J2(n)2*8P7+`/,'];
//# sourceMappingURL=requests.js.map