-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathifthenelse.test.ts
More file actions
58 lines (44 loc) · 2.38 KB
/
ifthenelse.test.ts
File metadata and controls
58 lines (44 loc) · 2.38 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
import { strict as assert } from "assert";
import { compileSchema } from "../compileSchema";
describe("keyword : if-then-else : get", () => {
describe("object", () => {
it("should step into if-then-property", () => {
const node = compileSchema({
type: "object",
if: { required: ["withHeader"], properties: { withHeader: { const: true } } },
then: { required: ["header"], properties: { header: { type: "string", minLength: 1 } } }
});
const schema = node.getNodeChild("header", { withHeader: true, header: "huhu" })?.node?.schema;
assert.deepEqual(schema, { type: "string", minLength: 1 });
});
it("should NOT step into if-then-property", () => {
const node = compileSchema({
type: "object",
if: { required: ["withHeader"], properties: { withHeader: { const: true } } },
then: { required: ["header"], properties: { header: { type: "string", minLength: 1 } } },
additionalProperties: false
});
const schema = node.getNodeChild("header", { withHeader: false, header: "huhu" })?.node?.schema;
assert.deepEqual(schema, undefined);
});
it("should step into if-else-property", () => {
const node = compileSchema({
type: "object",
if: { required: ["withHeader"], properties: { withHeader: { const: true } } },
else: { required: ["header"], properties: { header: { type: "string", minLength: 1 } } }
});
const schema = node.getNodeChild("header", { withHeader: false, header: "huhu" })?.node?.schema;
assert.deepEqual(schema, { type: "string", minLength: 1 });
});
it("should recursively resolve if-then-else schema", () => {
const node = compileSchema({
type: "object",
if: { required: ["withHeader"], properties: { withHeader: { const: true } } },
then: { allOf: [{ required: ["header"], properties: { header: { type: "string", minLength: 1 } } }] }
});
const schema = node.getNodeChild("header", { withHeader: true, header: "huhu" })?.node?.schema;
assert.deepEqual(schema, { type: "string", minLength: 1 });
});
});
// describe("array", () => {});
});