-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathvalidate-catalog.test.ts
244 lines (235 loc) · 7.05 KB
/
validate-catalog.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import { expect } from "chai";
import { validateCatalog } from "../src/validateCatalog";
describe("Validate catalog", () => {
const validSchema = "openacr-catalog-0.1.0.json";
const invalidSchema = "openacr-catalog-invalid.json";
const validJSON = {
title: "VPAT 2.4 edition 508/WCAG 2.0",
lang: "en",
standards: [
{
id: "wcag-2.0",
label: "Web Content Accessibility Guidelines 2.0",
report_heading: "WCAG 2.0 Report",
url: "https://www.w3.org/TR/WCAG20/",
chapters: ["success_criteria_level_a"],
},
{
id: "508",
label:
"Revised Section 508 standards published January 18, 2017 and corrected January 22, 2018",
report_heading: "Revised Section 508 Report",
url: "https://www.access-board.gov/ict/",
chapters: ["hardware"],
},
],
chapters: [
{
id: "success_criteria_level_a",
label: "Success Criteria, Level A",
order: 1,
criteria: [
{
id: "1.1.1",
handle: "Non-text Content (Level A)",
alt_id: "text-equiv",
components: [
"web",
"electronic-docs",
"software",
"authoring-tool",
],
},
{
id: "1.2.2",
handle: "1.2.2 Captions (Prerecorded) (Level A)",
alt_id: "media-equiv",
components: [
"web",
"electronic-docs",
"software",
"authoring-tool",
],
},
],
},
{
id: "hardware",
label: "Hardware",
order: 4,
criteria: [
{
id: "402",
handle: "Closed Functionality",
alt_id: "402-closed-functionality",
components: [],
},
{
id: "402.1",
handle: "General",
alt_id: "402.1",
components: [],
},
],
},
],
components: [
{
id: "web",
label: "Web",
},
{
id: "electronic-docs",
label: "Electronic Documents",
},
{
id: "software",
label: "Software",
},
{
id: "authoring-tool",
label: "Authoring Tool",
},
{
id: "none",
label: "",
},
],
terms: [
{
id: "supports",
label: "Supports",
description:
"The functionality of the product has at least one method that meets the criterion without known defects or meets with equivalent facilitation.",
},
{
id: "partially-supports",
label: "Partially Supports",
description:
"Some functionality of the product does not meet the criterion.",
},
{
id: "does-not-support",
label: "Does Not Support",
description:
"The majority of product functionality does not meet the criterion.",
},
{
id: "not-applicable",
label: "Not Applicable",
description: "The criterion is not relevant to the product.",
},
{
id: "not-evaluated",
label: "Not Evaluated",
description:
"The product has not been evaluated against the criterion. This can be used only in WCAG 2.0 Level AAA.",
},
],
};
const invalidJSON = { foo: 2, bar: 4 };
const invalidJSON1 = {
title: "VPAT 2.4 edition 508/WCAG 2.0",
lang: "en",
chapters: {
id: "success_criteria_level_a",
label: "Success Criteria, Level A",
order: 1,
},
};
const invalidJSON2 = {
title: "VPAT 2.4 edition 508/WCAG 2.0",
lang: "en",
chapters: [
{
id: "success_criteria_level_a",
label: "Success Criteria, Level A",
criteria: ["1.1.1", "1.2.2"],
},
],
};
const invalidJSON3 = {
title: "VPAT 2.4 edition 508/WCAG 2.0",
lang: "en",
components: [
{
web: "Web",
},
{
"electronic-docs": "Electronic Documents",
},
],
};
const invalidJSON4 = {
title: "VPAT 2.4 edition 508/WCAG 2.0",
lang: "en",
terms: [
{
supports: "Supports",
},
{
"does-not-support": "Does not support",
},
],
};
let result = null;
it("pass valid JSON with valid schema should return valid message", () => {
result = validateCatalog(validJSON, validSchema);
expect(result.result).to.equal(true);
expect(result.message).to.equal("Valid!");
});
it("pass invalid JSON with valid schema should return invalid JSON message", () => {
result = validateCatalog(invalidJSON, validSchema);
expect(result.result).to.equal(false);
expect(result.message).to.equal(
"Invalid: catalog data must have required property 'title', " +
"data must have required property 'lang'"
);
});
it("pass valid JSON with invalid schema should return invalid schema message", () => {
result = validateCatalog(validJSON, invalidSchema);
expect(result.result).to.equal(false);
expect(result.message).to.equal("Invalid: catalog schema is not valid");
});
it("pass invalid JSON with invalid schema should return invalid schema message", () => {
result = validateCatalog(invalidJSON, invalidSchema);
expect(result.result).to.equal(false);
expect(result.message).to.equal("Invalid: catalog schema is not valid");
});
it("pass invalid chapters JSON should return invalid JSON message", () => {
result = validateCatalog(invalidJSON1, validSchema);
expect(result.result).to.equal(false);
expect(result.message).to.equal(
"Invalid: catalog data/chapters must be array"
);
});
it("pass invalid criteria JSON should return invalid JSON message", () => {
result = validateCatalog(invalidJSON2, validSchema);
expect(result.result).to.equal(false);
expect(result.message).to.equal(
"Invalid: catalog data/chapters/0 must have required property 'order', " +
"data/chapters/0/criteria/0 must be object, " +
"data/chapters/0/criteria/1 must be object"
);
});
it("pass invalid components JSON should return invalid JSON message", () => {
result = validateCatalog(invalidJSON3, validSchema);
expect(result.result).to.equal(false);
expect(result.message).to.equal(
"Invalid: catalog data/components/0 must have required property 'id', " +
"data/components/0 must have required property 'label', " +
"data/components/1 must have required property 'id', " +
"data/components/1 must have required property 'label'"
);
});
it("pass invalid terms JSON should return invalid JSON message", () => {
result = validateCatalog(invalidJSON4, validSchema);
expect(result.result).to.equal(false);
expect(result.message).to.equal(
"Invalid: catalog data/terms/0 must have required property 'id', " +
"data/terms/0 must have required property 'label', " +
"data/terms/1 must have required property 'id', " +
"data/terms/1 must have required property 'label'"
);
});
});