forked from codyogden/killedbygoogle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraveyard.test.ts
62 lines (54 loc) · 1.97 KB
/
graveyard.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
import moment from "moment";
import slugify from "slugify";
import data from "./graveyard.json";
slugify.extend({
"+": "plus",
"@": "at",
});
describe("graveyard", () => {
it("objects should be valid", () => {
data.forEach((product) => {
// All data is present for each product
expect(product.dateClose).not.toBeNull();
expect(product.dateOpen).not.toBeNull();
expect(product.description).not.toBeNull();
expect(product.link).not.toBeNull();
expect(product.name).not.toBeNull();
expect(product.type).not.toBeNull();
// Check `dateClose` format
// Format: YYYY-MM-DD
expect(product.dateClose.split("-")).toHaveLength(3);
// Format Year: YYYY
expect(product.dateClose.split("-")[0]).toHaveLength(4);
// Format Month: MM
expect(product.dateClose.split("-")[1]).toHaveLength(2);
// Format Day: DD
expect(product.dateClose.split("-")[2]).toHaveLength(2);
// Check `dateOpen` format
// Format: YYYY-MM-DD
expect(product.dateOpen.split("-")).toHaveLength(3);
// Format Year: YYYY
expect(product.dateOpen.split("-")[0]).toHaveLength(4);
// Format Month: MM
expect(product.dateOpen.split("-")[1]).toHaveLength(2);
// Format Day: DD
expect(product.dateOpen.split("-")[2]).toHaveLength(2);
// Dates are Chronologically Correct
const dateClose = moment(product.dateClose);
const dateOpen = moment(product.dateOpen);
expect(dateClose.isValid()).toBe(true);
expect(dateOpen.isValid()).toBe(true);
expect(dateClose.isAfter(dateOpen)).toBe(true);
});
});
it("names are unique", () => {
// Slug for each name
const slugs = data.map((item: Record<string, string>) =>
slugify(item.name, { lower: true })
);
// Create a set (removes any duplicate slugs)
const slugSet = new Set(slugs);
// Both the data and items arr should have the same length
expect(slugSet.size).toBe(data.length);
});
});