-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidation.spec.ts
55 lines (51 loc) · 1.41 KB
/
validation.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
import assert from 'node:assert'
import { describe, it } from 'node:test'
import {
MultipleInstanceResource,
OptionalResource,
StringResource,
} from './validation.js'
void describe('MultipleInstanceResource()', () => {
void it('should validate a multiple instance resource', () => {
assert.equal(
true,
MultipleInstanceResource(StringResource)(['BOOT', 'MODEM', 'APP']),
)
})
})
void describe('StringResource()', () => {
void it('should validate a string', () => {
assert.equal(true, StringResource('test'))
})
})
void describe('OptionalResource()', () => {
void it('should validate an undefined resource', () => {
assert.equal(true, OptionalResource(StringResource)(undefined))
})
void it('should validate an defined resource', () => {
assert.equal(true, OptionalResource(StringResource)('foo'))
})
void it('should not validate an invalid defined resource', () => {
assert.equal(false, OptionalResource(StringResource)(true))
})
})
void describe('combination', () => {
void it('should validate OptionalResource(MultipleInstanceResource(StringResource))', () => {
assert.equal(
true,
OptionalResource(MultipleInstanceResource(StringResource))([
'BOOT',
'MODEM',
'APP',
]),
)
assert.equal(
true,
OptionalResource(MultipleInstanceResource(StringResource))(undefined),
)
assert.equal(
false,
OptionalResource(MultipleInstanceResource(StringResource))('foo'),
)
})
})