-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvalidate-model.spec.ts
More file actions
37 lines (34 loc) · 1.33 KB
/
validate-model.spec.ts
File metadata and controls
37 lines (34 loc) · 1.33 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
import { test } from 'vitest'
import { likec4model } from './likec4-model'
test('Every service has a link to the repository', ({ expect }) => {
expect.hasAssertions()
for (const e of likec4model.elementsOfKind('service')) {
// expect.soft allows to accumulate all failures
expect.soft(
e.links.find(l => l.title === 'Repository'),
`Service "${e.id}" has no link to the repository`
).toBeDefined()
}
})
test('Many-to-many relationship allowed only between DB Tables', ({ expect }) => {
for (const r of likec4model.relationshipsWhere({ kind: 'many-to-many' })) {
expect.soft(
r.source.kind === 'db-table',
`Many-to-many relationship "${r.source.id}"->"${r.target.id}" has invalid source`
).toBe(true)
expect.soft(
r.target.kind === 'db-table',
`Many-to-many relationship "${r.source.id}"->"${r.target.id}" has invalid target`
).toBe(true)
}
})
// With `test.for` we generate tests for each element of kind `component`
// This improves the output, showing each test failure separately
test.for(
// Select elements of kind `app`
[...likec4model.elementsWhere({ kind: 'component' })]
// Map to array of [id, element] tuples, we need it for test names
.map(e => [e.id, e] as const)
)('Component "%s" has technology', ([, e], { expect }) => {
expect(e.technology).toBeTruthy()
})