-
Notifications
You must be signed in to change notification settings - Fork 3
/
content-ok.test.ts
39 lines (35 loc) · 1.04 KB
/
content-ok.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
import Ajv from "https://esm.sh/[email protected]";
const DIR = "./events";
const eventSchema = {
type: "object",
properties: {
name: { type: "string" },
room: { type: "string" },
starttime: { type: "string", pattern: "^[12]?\\d:\\d\\d" },
endtime: { type: "string", pattern: "^[12]?\\d:\\d\\d" },
date: { type: "integer", minimum: 1, maximum: 31 },
month: { type: "integer", minimum: 1, maximum: 12 },
year: { type: "integer", minimum: 2015, maximum: 2100 },
},
required: ["name", "room", "starttime", "endtime", "date", "month", "year"],
additionalProperties: false,
};
const ajv = new Ajv();
const validate = ajv.compile(eventSchema);
for (const filename of Deno.readDirSync(DIR)) {
Deno.test({
name: filename.name,
fn() {
const content = JSON.parse(
Deno.readTextFileSync(`${DIR}/${filename.name}`),
) as unknown[];
// console.log(content)
for (const event of content) {
if (!validate(event)) {
console.error(event, validate.errors);
throw new Error("does not comply to json schema");
}
}
},
});
}