-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathschema.test.ts
114 lines (108 loc) · 3.33 KB
/
schema.test.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { nullOptionalsAllowed, conjoin, mergeOrders, applyOrder } from './schema';
it('nullOptionals simple', () => {
let nopts = nullOptionalsAllowed({
type: 'string'
});
expect(nopts['type']).toEqual([ 'string', 'null' ]);
});
it('nullOptionals properties', () => {
let nopts = nullOptionalsAllowed({
type: 'object',
properties: {
'propA': {
'type': 'string'
},
'propB': {
'type': ['date', 'boolean']
}
}
});
expect(nopts['properties']['propA']['type']).toEqual(['string', 'null']);
expect(nopts['properties']['propB']['type']).toEqual(['date', 'boolean', 'null']);
})
it('conjoin minimal', () => {
let simple0 = {
properties: {
propA: {
type: 'string'
}
}
};
let simple1 = {
properties: {
propB: {
type: 'string'
}
}
};
let conj = conjoin(simple0, simple1) || {};
expect(conj['properties']['propA']['type']).toBe('string');
expect(conj['properties']['propB']['type']).toBe('string');
});
it('conjoin maximal', () => {
let maxl0 = {
properties: {
propA: {
properties: {
propAA: {
type: 'number'
}
}
},
propB: {
type: 'string'
},
propArr: {
type: 'array',
items: {
properties: {
propArrA: {
type: 'string'
}
}
}
}
}
};
let maxl1 = {
properties: {
propA: {
properties: {
propAB: {
type: 'string'
}
}
},
propB: {
format: 'email'
},
propArr: {
type: 'array',
items: {
properties: {
propArrA: {
type: 'string'
}
}
}
}
}
};
let conj = conjoin(maxl0, maxl1) || {};
expect(conj['properties']['propB']['type']).toBe('string');
expect(conj['properties']['propB']['format']).toBe('email');
expect(conj['properties']['propA']['properties']['propAA']['type']).toBe('number');
expect(conj['properties']['propA']['properties']['propAB']['type']).toBe('string');
expect(conj['properties']['propArr']['items']['properties']['propArrA']['type']).toBe('string');
})
it("merge orders", () => {
let merged = mergeOrders([ "one", "two", "three" ], [ "two", "two and a half" ]);
expect(merged[2]).toBe('two and a half');
merged = mergeOrders([ "one", "two", "three", "four", "five" ], [ "two", "two and a third", "two and 2 thirds", "four", "four and a half" ]);
expect(merged[3]).toBe("two and 2 thirds");
expect(merged[6]).toBe("four and a half");
});
it("apply order", () => {
let ordered = applyOrder([[ "x", 1 ], [ "y", 2 ], [ "z", 3 ]], ([key, _]) => key.toString(), [ "z", "y" ]);
expect(ordered).toEqual([[ "z", 3], [ "y", 2], [ "x", 1 ]]);
});