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

100% Statements 32/32
100% Branches 0/0
100% Functions 20/20
100% Lines 32/32
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66                                                                    
const expect = require("expect");
const callApp = require("../../utils/callApp");
const modified = require("../modified");
 
describe("middleware/modified", function () {
    let etag, lastModified, app;
    beforeEach(function () {
        etag = "abc";
        lastModified = "Tue, 26 Mar 2013 00:58:16 GMT";
        app = modified(function () {
            return {
                status: 200,
                headers: {
                    ETag: etag,
                    "Last-Modified": lastModified
                },
                content: ""
            };
        });
    });
 
    describe("when a request uses the If-None-Match header", function () {
        describe("that does not match the ETag response header", function () {
            it("returns 200", function () {
                return callApp(app, {headers: {"If-None-Match": "\"def\""}}).then(function (conn) {
                    expect(conn.status).toEqual(200);
                });
            });
        });
 
        describe("that matches the ETag response header", function () {
            it("returns 304", function () {
                return callApp(app, {headers: {"If-None-Match": `"${etag}"`}}).then(function (conn) {
                    expect(conn.status).toEqual(304);
                });
            });
        });
    });
 
    describe("when a request uses the If-Modified-Since header", function () {
        describe("with a value less than the Last-Modified response header", function () {
            it("returns 200", function () {
                return callApp(app, {headers: {"If-Modified-Since": "Tue, 26 Mar 2013 00:58:15 GMT"}}).then(function (conn) {
                    expect(conn.status).toEqual(200);
                });
            });
        });
 
        describe("with a value equal to the Last-Modified response header", function () {
            it("returns 304", function () {
                return callApp(app, {headers: {"If-Modified-Since": "Tue, 26 Mar 2013 00:58:16 GMT"}}).then(function (conn) {
                    expect(conn.status).toEqual(304);
                });
            });
        });
 
        describe("with a value greater than the Last-Modified response header", function () {
            it("returns 304", function () {
                return callApp(app, {headers: {"If-Modified-Since": "Tue, 26 Mar 2013 00:58:17 GMT"}}).then(function (conn) {
                    expect(conn.status).toEqual(304);
                });
            });
        });
    });
});