|
1
|
|
|
'use strict' |
|
2
|
|
|
|
|
3
|
|
|
const nock = require('nock') |
|
4
|
|
|
const winston = require('winston') |
|
5
|
|
|
|
|
6
|
|
|
require('..') |
|
7
|
|
|
|
|
8
|
|
|
let url, path, scope, logger |
|
9
|
|
|
|
|
10
|
|
|
beforeAll(() => { |
|
11
|
|
|
url = 'http://localhost:5555' |
|
12
|
|
|
path = '/' |
|
13
|
|
|
scope = nock(url).post(path).reply(200) |
|
14
|
|
|
logger = new winston.Logger({ |
|
15
|
|
|
transports: [ |
|
16
|
|
|
new winston.transports.WinstonRestify({ |
|
17
|
|
|
silent: true, |
|
18
|
|
|
client: { |
|
19
|
|
|
url |
|
20
|
|
|
} |
|
21
|
|
|
}) |
|
22
|
|
|
] |
|
23
|
|
|
}) |
|
24
|
|
|
}) |
|
25
|
|
|
|
|
26
|
|
|
describe('winston-restify tests', () => { |
|
27
|
|
|
test('logs a string to specified endpoint', done => { |
|
28
|
|
|
logger.info('hello.', { |
|
29
|
|
|
path |
|
30
|
|
|
}, () => expect(scope.isDone()).toEqual(true)) |
|
31
|
|
|
done() |
|
32
|
|
|
}) |
|
33
|
|
|
|
|
34
|
|
|
// only methods POST, PUT |
|
35
|
|
|
test('can send data', done => { |
|
36
|
|
|
logger.info('hello.', { |
|
37
|
|
|
path, |
|
38
|
|
|
data: { |
|
39
|
|
|
a: 1 |
|
40
|
|
|
} |
|
41
|
|
|
}, () => expect(scope.isDone()).toEqual(true)) |
|
42
|
|
|
done() |
|
43
|
|
|
}) |
|
44
|
|
|
|
|
45
|
|
|
// methods GET, HEAD, POST, PUT, DEL |
|
46
|
|
|
test('can change http method', done => { |
|
47
|
|
|
const getScope = nock(url).get('/').reply(200) |
|
48
|
|
|
logger.info('hello.', { |
|
49
|
|
|
method: 'get', |
|
50
|
|
|
path |
|
51
|
|
|
}, () => expect(getScope.isDone()).toEqual(true)) |
|
52
|
|
|
done() |
|
53
|
|
|
}) |
|
54
|
|
|
|
|
55
|
|
|
test('with options', done => { |
|
56
|
|
|
const putScope = nock(url).put('/').reply(200) |
|
57
|
|
|
logger.info('hello.', { |
|
58
|
|
|
method: 'put', |
|
59
|
|
|
options: { |
|
60
|
|
|
path |
|
61
|
|
|
} |
|
62
|
|
|
}, () => expect(putScope.isDone()).toEqual(true)) |
|
63
|
|
|
done() |
|
64
|
|
|
}) |
|
65
|
|
|
|
|
66
|
|
|
afterEach(() => { |
|
67
|
|
|
nock.removeInterceptor(scope) |
|
68
|
|
|
}) |
|
69
|
|
|
}) |
|
70
|
|
|
|