This repository has been archived by the owner on Apr 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Logger.test.js
65 lines (48 loc) · 1.73 KB
/
Logger.test.js
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
const sinon = require('sinon');
const { expect } = require('chai');
const { Logger: nodeJsLogger } = require('@hmcts/nodejs-logging');
const Logger = require('./Logger');
const sinonStubPromise = require('sinon-stub-promise');
sinonStubPromise(sinon);
describe('logger', () => {
let fakeLogger = null;
let passedInLogger = null;
beforeEach(() => {
fakeLogger = { error: sinon.stub(), info: sinon.stub() };
passedInLogger = { exception: sinon.stub(), request: sinon.stub() };
sinon.stub(nodeJsLogger, 'getLogger').returns(fakeLogger);
});
afterEach(() => {
nodeJsLogger.getLogger.restore();
});
describe('error', () => {
it('calls nodejs-logging if no logger setup', () => {
const logger = new Logger({});
const message = 'message';
logger.error(message);
expect(fakeLogger.error.calledWith(message)).to.equal(true);
});
it('calls logger from args', () => {
const logger = new Logger({ logger: passedInLogger });
const message = 'message';
logger.error(message);
expect(fakeLogger.error.callCount).to.equal(0);
expect(passedInLogger.exception.calledWith(message)).to.equal(true);
});
});
describe('info', () => {
it('calls nodejs-logging if no logger setup', () => {
const logger = new Logger({});
const message = 'message';
logger.info(message);
expect(fakeLogger.info.calledWith(message)).to.equal(true);
});
it('calls logger from args', () => {
const logger = new Logger({ logger: passedInLogger });
const message = 'message';
logger.info(message);
expect(fakeLogger.info.callCount).to.equal(0);
expect(passedInLogger.request.calledWith(message)).to.eql(true);
});
});
});