-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontent-ok.test.ts
More file actions
38 lines (33 loc) · 899 Bytes
/
content-ok.test.ts
File metadata and controls
38 lines (33 loc) · 899 Bytes
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
import { Ajv } from "ajv";
const DIR = "./events";
const datePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/.source;
const eventSchema = {
type: "object",
properties: {
name: { type: "string" },
location: { type: "string" },
start: { type: "string", pattern: datePattern },
end: { type: "string", pattern: datePattern },
},
required: ["name", "location", "start", "end"],
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");
}
}
},
});
}