Merge branch 'v1.3-dev' as v1.3.2
[websub-hub] / test / src / logger.js
1 /* eslint-env mocha */
2 'use strict';
3
4 const assert = require('assert');
5 const Logger = require('../../src/logger');
6 const Config = require('../../config');
7
8 describe('Logger', function () {
9 let config;
10 let logger;
11
12 beforeEach(function () {
13 config = new Config('test');
14 });
15
16 it('logs', function () {
17 logger = new Logger(config);
18 logger.info('testScope', 'message', { baz: 'quux' }, { foo: 1 }, 'more other');
19 });
20
21 it('stubs missing levels', function () {
22 const backend = {};
23 logger = new Logger(config, backend);
24 assert.strictEqual(typeof logger.info, 'function');
25 });
26
27 it('logs BigInts', function () {
28 logger = new Logger(config);
29 logger.info('testScope', 'message', { aBigInteger: BigInt(2) });
30 });
31
32 it('logs Errors', function () {
33 logger = new Logger(config);
34 logger.error('testScope', 'message', { e: new Error('an error') });
35 });
36
37 it('covers config error', function () {
38 config.logger.ignoreBelowLevel = 'not a level';
39 try {
40 logger = new Logger(config);
41 assert.fail('expected RangeError here');
42 } catch (e) {
43 assert(e instanceof RangeError);
44 }
45 });
46
47 it('covers empty fields', function () {
48 logger = new Logger(config);
49 logger.info();
50 });
51
52 it('masks credentials', function () {
53 logger = new Logger(config);
54 logger.info('testScope', 'message', {
55 ctx: {
56 parsedBody: {
57 identity: 'username',
58 credential: 'password',
59 },
60 },
61 });
62 });
63
64 }); // Logger