-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidate.spec.ts
60 lines (56 loc) · 1.45 KB
/
validate.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
import assert from 'node:assert'
import { describe, it } from 'node:test'
import { validate } from './validate.js'
import { validators } from './validators.js'
void describe('validate()', () => {
const v = validate(validators)
void it('should validate a LwM2M object instance', () => {
const object = {
ObjectID: 14201,
ObjectVersion: '1.0',
Resources: {
'0': 62.469414,
'1': 6.151946,
'6': 'Fixed',
'3': 1,
'99': 1710147413,
},
}
const maybeValid = v(object)
assert.deepEqual('object' in maybeValid && maybeValid.object, object)
})
void it('should return an error for an invalid object', () => {
const maybeValid = v({})
assert.equal('error' in maybeValid, true)
})
void it('should validate an object with undefined optional resources', () => {
const object = {
ObjectID: 14203,
ObjectVersion: '1.0',
Resources: {
'0': 'LTE-M GPS',
'1': 20,
'3': 33187,
'4': 52661514,
'5': 24201,
'6': '10.234.105.140',
11: undefined,
'99': 1716988087,
},
}
const maybeValid = v(object)
assert.deepEqual('object' in maybeValid && maybeValid.object, object)
})
void it('should validate an object with multiple instance resource', () => {
const object = {
ObjectID: 14401,
ObjectVersion: '1.0',
Resources: {
'0': ['BOOT', 'MODEM', 'APP'],
'99': 1717409966,
},
}
const maybeValid = v(object)
assert.deepEqual('object' in maybeValid && maybeValid.object, object)
})
})