1
|
|
|
import * as nAutoMetrics from '@financial-times/n-auto-metrics'; |
2
|
|
|
|
3
|
|
|
import setupMonitor from '../setup'; |
4
|
|
|
import { monitorService, monitorModule } from '../action'; |
5
|
|
|
|
6
|
|
|
jest.mock('@financial-times/n-auto-metrics', () => ({ |
|
|
|
|
7
|
|
|
tagService: () => inputFunction => inputFunction, |
8
|
|
|
metricsAction: jest.fn(inputFunction => inputFunction), |
|
|
|
|
9
|
|
|
initAutoMetrics: jest.fn(), |
10
|
|
|
})); |
11
|
|
|
|
12
|
|
|
describe('monitorService', () => { |
13
|
|
|
afterEach(() => { |
14
|
|
|
jest.clearAllMocks(); |
|
|
|
|
15
|
|
|
}); |
16
|
|
|
|
17
|
|
|
const app = { |
18
|
|
|
use: jest.fn(), |
|
|
|
|
19
|
|
|
}; |
20
|
|
|
|
21
|
|
|
const metrics = {}; |
22
|
|
|
|
23
|
|
|
it('disable metricsAction if metrics instance is not set', () => { |
24
|
|
|
setupMonitor({ app }); |
25
|
|
|
const serviceActions = { |
26
|
|
|
method: () => {}, |
27
|
|
|
}; |
28
|
|
|
monitorService('mock-service', serviceActions); |
29
|
|
|
expect(nAutoMetrics.metricsAction.mock.calls).toMatchSnapshot(); |
30
|
|
|
}); |
31
|
|
|
|
32
|
|
|
it('enable metricsAction if metrics instance is set', () => { |
33
|
|
|
setupMonitor({ app, metrics }); |
34
|
|
|
const serviceActions = { |
35
|
|
|
method: () => {}, |
36
|
|
|
}; |
37
|
|
|
monitorService('mock-service', serviceActions); |
38
|
|
|
expect(nAutoMetrics.metricsAction.mock.calls).toMatchSnapshot(); |
39
|
|
|
}); |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
describe('monitorModule', () => { |
43
|
|
|
afterEach(() => { |
44
|
|
|
jest.clearAllMocks(); |
|
|
|
|
45
|
|
|
}); |
46
|
|
|
|
47
|
|
|
const app = { |
48
|
|
|
use: jest.fn(), |
|
|
|
|
49
|
|
|
}; |
50
|
|
|
|
51
|
|
|
const metrics = {}; |
52
|
|
|
|
53
|
|
|
it('disable metricsAction if metrics instance is not set', () => { |
54
|
|
|
setupMonitor({ app }); |
55
|
|
|
const moduleFunctions = { |
56
|
|
|
method: () => {}, |
57
|
|
|
}; |
58
|
|
|
monitorModule(moduleFunctions); |
59
|
|
|
expect(nAutoMetrics.metricsAction.mock.calls).toMatchSnapshot(); |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
it('enable metricsAction if metrics instance is set', () => { |
63
|
|
|
setupMonitor({ app, metrics }); |
64
|
|
|
const moduleFunctions = { |
65
|
|
|
method: () => {}, |
66
|
|
|
}; |
67
|
|
|
monitorModule(moduleFunctions); |
68
|
|
|
expect(nAutoMetrics.metricsAction.mock.calls).toMatchSnapshot(); |
69
|
|
|
}); |
70
|
|
|
}); |
71
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.