update dependencies and devDependencies
[squeep-authentication-module] / test / lib / common.js
1 /* eslint-env mocha */
2 'use strict';
3
4 const assert = require('assert');
5 const sinon = require('sinon');
6 const stubLogger = require('../stub-logger');
7 const common = require('../../lib/common');
8
9 describe('Common', function () {
10
11 describe('freezeDeep', function () {
12 it('covers', function () {
13 const obj = {
14 value: true,
15 subObj: {
16 subValue: true,
17 },
18 };
19 common.freezeDeep(obj);
20 assert.throws(() => obj.value = false, TypeError);
21 assert.throws(() => obj.subObj.subValue = false, TypeError);
22 });
23 }); // freezeDeep
24
25 describe('omit', function () {
26 it('does the expected', function () {
27 const orig = {
28 foo: 'foo',
29 bar: 23,
30 quux: { squawk: true },
31 zounds: false,
32 };
33 const omitted = ['foo', 'quux'];
34 const expected = {
35 bar: 23,
36 zounds: false,
37 };
38 const result = common.omit(orig, omitted);
39 assert.deepStrictEqual(result, expected);
40 });
41 }); // omit
42
43 describe('mysteryBoxLogger', function () {
44 let mbl;
45 beforeEach(function () {
46 stubLogger._reset();
47 mbl = common.mysteryBoxLogger(stubLogger, 'test:scope');
48 });
49 afterEach(function () {
50 sinon.restore();
51 });
52 it('covers', function () {
53 const stat = {
54 packageName: 'fake-mystery-box',
55 packageVersion: '0.0.0',
56 method: 'pack',
57 data: 'exists',
58 };
59 mbl(stat);
60 assert(stubLogger.debug.called);
61 });
62 }); // mysteryBoxLogger
63
64 describe('obscureAuthorizationHeader', function () {
65 it('blurs Bearer token', function () {
66 const result = common.obscureAuthorizationHeader('Bearer foo');
67 assert.strictEqual(result, 'Bearer ***');
68 });
69 it('blurs entire string for other', function () {
70 const result = common.obscureAuthorizationHeader('abcdef');
71 assert.strictEqual(result, '******');
72 });
73 it('covers empty string', function () {
74 const a = '';
75 const result = common.obscureAuthorizationHeader(a);
76 assert.strictEqual(result, a);
77
78 });
79 });
80
81 }); // Common