-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmetrics.service.spec.ts
65 lines (54 loc) · 1.64 KB
/
metrics.service.spec.ts
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
import { Test, TestingModule } from '@nestjs/testing'
import MockDate from 'mockdate'
import { MetricsService } from './metrics.service'
import { MetricsRepository } from './repository/metrics-repository'
MockDate.set('2010-01-01')
describe('MetricsService', () => {
let metrics: MetricsService
let repository: MetricsRepository
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [MetricsRepository, MetricsService],
}).compile()
metrics = module.get(MetricsService)
repository = module.get(MetricsRepository)
})
describe('increase()', () => {
test('existing metric', () => {
repository.create({ id: 'foo', yes: 0, no: 0, createdAt: new Date() })
metrics.increase('foo', false)
metrics.increase('foo', true)
metrics.increase('foo', false)
expect(repository.find('foo')).toMatchInlineSnapshot(`
Object {
"createdAt": 2010-01-01T00:00:00.000Z,
"id": "foo",
"no": 2,
"yes": 1,
}
`)
})
test('new metric (enabled)', () => {
metrics.increase('new', true)
expect(repository.find('new')).toMatchInlineSnapshot(`
MetricEntity {
"createdAt": 2010-01-01T00:00:00.000Z,
"id": "new",
"no": 0,
"yes": 1,
}
`)
})
test('new metric (not enabled)', () => {
metrics.increase('new', false)
expect(repository.find('new')).toMatchInlineSnapshot(`
MetricEntity {
"createdAt": 2010-01-01T00:00:00.000Z,
"id": "new",
"no": 1,
"yes": 0,
}
`)
})
})
})