/
log.test.js
87 lines (74 loc) · 2.6 KB
/
log.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use strict';
const { expect } = require('chai');
const { stub, spy } = require('sinon');
const Support = require('../support');
const dialect = Support.getTestDialect();
describe(Support.getTestDialectTeaser('Sequelize'), () => {
describe('log', () => {
beforeEach(function () {
this.stub = stub(console, 'log');
});
afterEach(() => {
console.log.restore();
});
describe('with disabled logging', () => {
beforeEach(function () {
this.sequelize = new Support.Sequelize('db', 'user', 'pw', {
dialect,
logging: false
});
});
it('does not call the log method of the logger', function () {
this.sequelize.log();
expect(this.stub.calledOnce).to.be.false;
});
});
describe('with default logging options', () => {
beforeEach(function () {
this.sequelize = new Support.Sequelize('db', 'user', 'pw', { dialect });
});
describe('called with no arguments', () => {
it('calls the log method', function () {
this.sequelize.log();
expect(this.stub.calledOnce).to.be.true;
});
it('logs an empty string as info event', function () {
this.sequelize.log('');
expect(this.stub.calledOnce).to.be.true;
});
});
describe('called with one argument', () => {
it('logs the passed string as info event', function () {
this.sequelize.log('my message');
expect(this.stub.withArgs('my message').calledOnce).to.be.true;
});
});
describe('called with more than two arguments', () => {
it('passes the arguments to the logger', function () {
this.sequelize.log('error', 'my message', 1, { a: 1 });
expect(this.stub.withArgs('error', 'my message', 1, { a: 1 }).calledOnce).to.be.true;
});
});
});
describe('with a custom function for logging', () => {
beforeEach(function () {
this.spy = spy();
this.sequelize = new Support.Sequelize('db', 'user', 'pw', {
dialect,
logging: this.spy
});
});
it('calls the custom logger method', function () {
this.sequelize.log('om nom');
expect(this.spy.calledOnce).to.be.true;
});
it('calls the custom logger method with options', function () {
const message = 'om nom';
const timeTaken = 5;
const options = { correlationId: 'ABC001' };
this.sequelize.log(message, timeTaken, options);
expect(this.spy.withArgs(message, timeTaken, options).calledOnce).to.be.true;
});
});
});
});