-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
107 lines (77 loc) · 2.64 KB
/
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var churchill = require('./index.js');
var sinon = require('sinon'),
chai = require('chai'),
should = chai.should(),
sinonChai = require('sinon-chai');
chai.use(sinonChai);
describe('Churchill', function(){
var req, res, next;
beforeEach(function () {
req = {
method: 'GET',
originalUrl: 'http://imaurl.com/myroute?queryParam=queryParamValue&queryParam2=queryParamValue2',
query: {
queryParam: 'queryParamValue',
queryParam2: 'queryParamValue2'
}
};
res = {
statusCode: 200,
end: sinon.stub(),
get: sinon.stub().returns('100')
};
next = sinon.stub();
});
it('logs request', function () {
var logSpy = sinon.spy();
churchill.add({
log: logSpy
})(req, res, next);
res.end();
var responseTime = logSpy.lastCall.args[1].response_time;
logSpy.should.have.been.calledWith('info', sinon.match({
method: 'GET',
status: 200,
response_time: responseTime,
url: 'http://imaurl.com/myroute?queryParam=queryParamValue&queryParam2=queryParamValue2',
content_length: '100'
}));
});
it('logs request without the get params if configured to do so', function () {
var logSpy = sinon.spy();
churchill.options.logGetParams = false;
churchill.add({
log: logSpy
})(req, res, next);
res.end();
var responseTime = logSpy.lastCall.args[1].response_time;
logSpy.should.have.been.calledWith('info', sinon.match({
method: 'GET',
status: 200,
response_time: responseTime,
url: 'http://imaurl.com/myroute',
content_length: '100'
}));
});
describe('when the the url is not complete', function () {
beforeEach(function () {
req.originalUrl = '/myroute?queryParam=queryParamValue&queryParam2=queryParamValue2';
});
it('logs request without the get params if configured to do so', function () {
var logSpy = sinon.spy();
churchill.options.logGetParams = false;
churchill.add({
log: logSpy
})(req, res, next);
res.end();
var responseTime = logSpy.lastCall.args[1].response_time;
logSpy.should.have.been.calledWith('info', sinon.match({
method: 'GET',
status: 200,
response_time: responseTime,
url: '/myroute',
content_length: '100'
}));
});
});
});