all files / modules/middleware/__tests__/ logger-test.js

100% Statements 20/20
100% Branches 0/0
100% Functions 7/7
100% Lines 20/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                          
const assert = require("assert");
const expect = require("expect");
const callApp = require("../../utils/callApp");
const logger = require("../logger");
 
function zeroLength() {
    return {headers: {"Content-Length": 0}};
}
 
describe("middleware/logger", function () {
    describe("when a response has Content-Length of 100", function () {
        let messages, messageHandler;
        beforeEach(function () {
            messages = [];
            messageHandler = function (message) {
                messages.push(message);
            };
        });
 
        it("logs a content length of 0", function () {
            return callApp(logger(zeroLength, messageHandler)).then(function () {
                assert(messages[0]);
 
                const match = messages[0].match(/\b(\d+) ([0-9\.]+)\b$/);
                assert(match);
 
                const contentLength = match[1];
                expect(contentLength).toEqual("0");
            });
        });
    });
});