X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Flib%2Fcommon.js;h=68f2599791c12faf5d106656200fd23cb7c55947;hb=356f9a3b45d5b6bbcc310a2b37b6f59dfd76b923;hp=15e9c4adb07652b1e0376327f5aa4a5e55426bf2;hpb=031c170bdaf1d9c331e6f6fc701ce6540c0e6941;p=squeep-api-dingus diff --git a/test/lib/common.js b/test/lib/common.js index 15e9c4a..68f2599 100644 --- a/test/lib/common.js +++ b/test/lib/common.js @@ -1,27 +1,12 @@ -/* eslint-disable capitalized-comments */ -/* eslint-env mocha */ 'use strict'; -const assert = require('assert'); -const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require +const assert = require('node:assert'); +const sinon = require('sinon'); const common = require('../../lib/common'); describe('common', function () { - describe('fileScope', function () { - it('names a file path', function () { - const filename = 'lib/foo/bar.js'; - const result = common.fileScope(filename)('baz'); - assert.strictEqual(result, 'bar:baz'); - }); - it('names an index path', function () { - const filename = 'lib/foo/index.js'; - const result = common.fileScope(filename)('baz'); - assert.strictEqual(result, 'foo:baz'); - }); - }); // fileScope - describe('generateETag', function () { it('generates a tag from data', function () { const expected = '"RHUvNyculE/SyROjU0LqzN0arxibrlBnazAashP8UGE"'; @@ -364,4 +349,41 @@ describe('common', function () { }); }); // unfoldHeaderLines + describe('addCookie', function () { + let res, name, value; + beforeEach(function () { + res = { + appendHeader: sinon.stub(), + }; + name = 'someCookieName'; + value = 'someCookieValue'; + }); + it('covers no options', function () { + common.addCookie(res, name, value, {}); + assert(res.appendHeader.called); + }); + it('covers all options', function () { + common.addCookie(res, name, value, { + domain: 'example.com', + expires: new Date(), + httpOnly: true, + maxAge: 9999999, + path: '/foo', + sameSite: 'Lax', + secure: true, + }); + assert(res.appendHeader.called); + }); + it('covers invalid expires', function () { + assert.throws(() => common.addCookie(res, name, value, { expires: 'never' }), TypeError); + }); + it('covers invalid sameSite', function () { + assert.throws(() => common.addCookie(res, name, value, { sameSite: 'Whatever' })); + }); + it('covers no options', function () { + common.addCookie(res, name, value); + assert(res.appendHeader.called); + }); + }); // addCookie + });