Skip to content

Commit cc44535

Browse files
committed
New schema builder test
1 parent a3758ba commit cc44535

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

Diff for: engine/schema/builder.test.ts

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/// <reference no-default-lib="true"/>
2+
/// <reference lib="deno.ns" />
3+
/// <reference lib="esnext" />
4+
/// <reference lib="dom" />
5+
/// <reference lib="dom.iterable" />
6+
7+
import {
8+
assertArrayIncludes,
9+
assertEquals,
10+
assertObjectMatch,
11+
fail,
12+
} from "@std/assert";
13+
import { newSchemaBuilder } from "./builder.ts";
14+
15+
Deno.test("DataUri type generation", () => {
16+
const schema = {
17+
schema: {
18+
definitions: {
19+
exampleDefinition: {
20+
type: "object" as const,
21+
properties: {
22+
id: { type: "string" as const },
23+
name: { type: "string" as const },
24+
},
25+
required: ["id", "name"],
26+
},
27+
exampleArrayDefinition: {
28+
type: "array" as const,
29+
items: { $ref: "#/definitions/exampleDefinition" },
30+
},
31+
exampleArrayArrayDefinition: {
32+
type: "array" as const,
33+
items: { $ref: "#/definitions/exampleArrayDefinition" },
34+
},
35+
exampleAnyOfDefinition: {
36+
anyOf: [
37+
{ type: "string" as const },
38+
{ type: "number" as const },
39+
{ type: "boolean" as const },
40+
],
41+
},
42+
nestedAnyOfDefinitionIside: {
43+
anyOf: [
44+
{ type: "string" as const },
45+
{ type: "number" as const },
46+
{
47+
anyOf: [
48+
{ type: "boolean" as const },
49+
{ type: "null" as const },
50+
],
51+
},
52+
],
53+
},
54+
},
55+
root: {
56+
base: {
57+
type: "object" as const,
58+
properties: {
59+
data: { $ref: "#/definitions/exampleDefinition" },
60+
},
61+
required: ["data"],
62+
},
63+
},
64+
},
65+
blockModules: [{
66+
blockType: "exampleBlock",
67+
functionKey: "exampleNamespace.exampleFunction",
68+
inputSchema: {
69+
type: "object" as const,
70+
name: "inputobj",
71+
value: {
72+
input: {
73+
title: "input",
74+
schemeable: {
75+
type: "inline" as const,
76+
name: "test",
77+
value: {
78+
type: "object" as const,
79+
properties: {
80+
id: { type: "string" as const },
81+
name: { type: "string" as const },
82+
},
83+
required: ["id", "name"],
84+
},
85+
},
86+
required: false,
87+
},
88+
},
89+
},
90+
outputSchema: {
91+
type: "object" as const,
92+
name: "inputobj",
93+
value: {
94+
input: {
95+
title: "input",
96+
schemeable: {
97+
type: "inline" as const,
98+
name: "test",
99+
value: {
100+
type: "object" as const,
101+
properties: {
102+
id: { type: "string" as const },
103+
name: { type: "string" as const },
104+
},
105+
required: ["id", "name"],
106+
},
107+
},
108+
required: false,
109+
},
110+
},
111+
},
112+
functionJSDoc: {
113+
type: "object" as const,
114+
properties: {
115+
description: { type: "string" as const },
116+
},
117+
},
118+
}],
119+
entrypoints: [],
120+
};
121+
const schemaBuilder = newSchemaBuilder(schema);
122+
const resultSchema = schemaBuilder.build();
123+
124+
assertEquals(
125+
Object.keys(resultSchema.definitions).length,
126+
7,
127+
"4 definitions, nestedAnyOfDefinitionIside, resolvable and one block",
128+
);
129+
assertArrayIncludes(
130+
Object.keys(resultSchema.definitions),
131+
Object.keys(schema.schema.definitions),
132+
);
133+
});

0 commit comments

Comments
 (0)