Files
habitica/test/api/v3/unit/libs/logger.js
Matteo Pagliazzi 45c31a2bcf Deprecate API v2 (#7761)
* deprecate api-v2

* remove v2 test helpers

* remove unused string
2016-07-16 19:56:18 +02:00

58 lines
1.5 KiB
JavaScript

import winston from 'winston';
import requireAgain from 'require-again';
/* eslint-disable global-require */
describe('logger', () => {
let pathToLoggerLib = '../../../../../website/server/libs/logger';
let infoSpy;
let errorSpy;
beforeEach(() => {
infoSpy = sandbox.stub();
errorSpy = sandbox.stub();
sandbox.stub(winston, 'Logger').returns({
info: infoSpy,
error: errorSpy,
});
});
afterEach(() => {
sandbox.restore();
});
it('info', () => {
let attachLogger = requireAgain(pathToLoggerLib);
attachLogger.info(1, 2, 3);
expect(infoSpy).to.be.calledOnce;
expect(infoSpy).to.be.calledWith(1, 2, 3);
});
describe('error', () => {
it('with custom arguments', () => {
let attachLogger = requireAgain(pathToLoggerLib);
attachLogger.error(1, 2, 3, 4);
expect(errorSpy).to.be.calledOnce;
expect(errorSpy).to.be.calledWith(1, 2, 3, 4);
});
it('with error', () => {
let attachLogger = requireAgain(pathToLoggerLib);
let errInstance = new Error('An error.');
attachLogger.error(errInstance, {
data: 1,
}, 2, 3);
expect(errorSpy).to.be.calledOnce;
// using calledWith doesn't work
let lastCallArgs = errorSpy.lastCall.args;
expect(lastCallArgs[3]).to.equal(3);
expect(lastCallArgs[2]).to.equal(2);
expect(lastCallArgs[1]).to.eql({
data: 1,
fullError: errInstance,
});
expect(lastCallArgs[0]).to.eql(errInstance.stack);
});
});
});