-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathstatus-page-service.spec.ts
More file actions
66 lines (56 loc) · 2.03 KB
/
status-page-service.spec.ts
File metadata and controls
66 lines (56 loc) · 2.03 KB
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
import { describe, it, expect } from 'vitest'
import { StatusPageService, Diagnostics } from '../index'
import { Project, Session } from '../project'
describe('StatusPageService', () => {
it('should produce a diagnostic if the same logicalId is used twice', async () => {
const project = new Project('project-id', {
name: 'Test Project',
repoUrl: 'https://github.com/checkly/checkly-cli',
})
Session.project = project
new StatusPageService('foo', {
name: 'foo',
})
new StatusPageService('foo', {
name: 'foo',
})
const diagnostics = new Diagnostics()
await project.validate(diagnostics)
expect(diagnostics.isFatal()).toBe(true)
expect(diagnostics.observations).toEqual(expect.arrayContaining([
expect.objectContaining({
message: expect.stringContaining('already exists'),
}),
]))
})
it('should not throw if the same fromId() is used twice', () => {
Session.project = new Project('project-id', {
name: 'Test Project',
repoUrl: 'https://github.com/checkly/checkly-cli',
})
const add = () => {
StatusPageService.fromId('e79b4cf8-467e-4902-917d-82b155b42024')
}
expect(add).not.toThrow()
expect(add).not.toThrow()
})
it('should validate that fromId() receives a valid UUID', async () => {
Session.project = new Project('project-id', {
name: 'Test Project',
repoUrl: 'https://github.com/checkly/checkly-cli',
})
const valid = StatusPageService.fromId('e79b4cf8-467e-4902-917d-82b155b42024')
const validDiags = new Diagnostics()
await valid.validate(validDiags)
expect(validDiags.isFatal()).toEqual(false)
const invalid = StatusPageService.fromId('not-a-uuid')
const invalidDiags = new Diagnostics()
await invalid.validate(invalidDiags)
expect(invalidDiags.isFatal()).toEqual(true)
expect(invalidDiags.observations).toEqual(expect.arrayContaining([
expect.objectContaining({
message: expect.stringContaining('Value must be a valid UUID.'),
}),
]))
})
})