all files / modules/extensions/__tests__/ server-test.js

100% Statements 19/19
100% Branches 0/0
100% Functions 9/9
100% Lines 19/19
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 34 35 36 37 38 39                                       
/* jshint -W058 */
const expect = require("expect");
const mach = require("../../index");
 
describe("extensions/server", function () {
    beforeEach(function () {
        mach.extend(require("../server"));
    });
 
    describe("Message#setCookie", function () {
        let message;
        beforeEach(function () {
            message = new mach.Message();
        });
 
        describe("when no cookies have been previously set", function () {
            it("sets the \"Set-Cookie\" header to the appropriate string", function () {
                message.setCookie("cookieName", {value: "cookieValue"});
                expect(message.headers["Set-Cookie"]).toEqual("cookieName=cookieValue");
            });
        });
 
        describe("when cookies have been previously set", function () {
            beforeEach(function () {
                message.setCookie("previousOne", {value: "previousOneValue"});
            });
 
            it("sets the \"Set-Cookie\" header to an array of headers", function () {
                message.setCookie("cookieName", {value: "cookieValue"});
 
                expect(message.headers["Set-Cookie"]).toEqual([
                    "previousOne=previousOneValue",
                    "cookieName=cookieValue"
                ]);
            });
        });
    });
});