{"size": 2014, "ext": "js", "max_stars_repo_path": "dist/test/unit/server/middleware/log-request.test.js", "max_stars_repo_name": "alphabitdev/Node-TypeScript-Koa-TypeOrm-API-Boilerplate", "max_stars_repo_stars_event_min_datetime": "2021-02-19T02:44:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-19T02:44:11.000Z", "max_issues_repo_path": "dist/test/unit/server/middleware/log-request.test.js", "max_issues_repo_name": "alphabitdev/Node-TypeScript-Koa-TypeOrm-API-Boilerplate", "max_issues_repo_issues_event_min_datetime": "2021-03-02T01:16:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T03:09:19.000Z", "max_forks_repo_path": "dist/test/unit/server/middleware/log-request.test.js", "max_forks_repo_name": "alphabitdev/node-typescript-koa-typeorm-api-boilerplate", "max_forks_repo_forks_event_min_datetime": "2020-04-22T20:03:32.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-22T20:03:32.000Z"}
{"max_stars_count": 1, "max_issues_count": 3, "max_forks_count": 1, "avg_line_length": 45.7727272727, "max_line_length": 99, "alphanum_fraction": 0.632571996}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const pino_1 = __importDefault(require("pino"));
const sinon = __importStar(require("sinon"));
const mocha_1 = require("mocha");
const log_request_1 = __importDefault(require("../../../../src/server/middleware/log-request"));
mocha_1.describe('logRequest', () => {
    const sandbox = sinon.createSandbox();
    mocha_1.afterEach(() => {
        sandbox.restore();
    });
    mocha_1.it('Should log info level when no errors', async () => {
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        const ctx = {};
        const logger = pino_1.default({ name: 'test', level: 'silent' });
        const spy = sinon.spy(logger, 'info');
        const logMiddleware = log_request_1.default(logger);
        await logMiddleware(ctx, () => Promise.resolve());
        chai_1.expect(spy.calledOnce).equals(true);
        chai_1.expect(spy.args[0].length).equals(2);
    });
    mocha_1.it('Should log error level when status code is >= 400', async () => {
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        const ctx = { status: 500 };
        const logger = pino_1.default({ name: 'test', level: 'silent' });
        const spy = sinon.spy(logger, 'error');
        const logMiddleware = log_request_1.default(logger);
        await logMiddleware(ctx, () => Promise.resolve());
        chai_1.expect(spy.calledOnce).equals(true);
        chai_1.expect(spy.args[0].length).equals(3);
    });
});
//# sourceMappingURL=log-request.test.js.map