-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathmain.spec.js
52 lines (48 loc) · 1.58 KB
/
main.spec.js
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
/* eslint-disable no-useless-escape */
import data from "@/assets/data.json";
import { matchers } from "jest-json-schema";
expect.extend(matchers);
describe("Data", () => {
it("should validate JSON", () => {
const schema = {
type: "array",
additionalProperties: false,
items: {
type: "object",
properties: {
name: {
type: "string",
minLength: 1,
maxLength: 40,
pattern: "^[a-zA-Z0-9-]*$"
},
text: {
type: "string",
minLength: 1,
maxLength: 22,
pattern:
"^[a-zA-Z0-9\u10A0-\u10FF[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2694-\u2697]|\uD83E[\uDD10-\uDD5D] @#!.?-]*$"
// "^[a-zA-Z0-9\u10A0-\u10FF\u1f900-\u1f9ff @#!.?[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2694-\u2697]|\uD83E[\uDD10-\uDD5D])]*$"
},
cart: {
type: "integer",
enum: [0, 1, 2, 3, 4, 5, 6]
}
},
required: ["name", "text", "cart"]
}
};
expect(data).toMatchSchema(schema);
});
it("should have only one instance of username", async () => {
let seen = new Set();
const hasDuplicates = data.some(el => {
return seen.size === seen.add(el.name).size;
});
expect(hasDuplicates).toBeFalsy();
});
it("should not contain HTML", async () => {
const hasHTML = data.some(el => /<\/?[a-z][\s\S]*>/i.test(el.text));
expect(hasHTML).toBeFalsy();
});
});