-
Notifications
You must be signed in to change notification settings - Fork 388
/
graveyard.test.ts
74 lines (64 loc) · 2.38 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
63
64
65
66
67
68
69
70
71
72
73
74
import { expect } from '@playwright/test';
import { describe, test } from '@jest/globals';
import moment from 'moment';
import slugify from 'slugify';
import { Product, ProductType } from './types/Product';
import graveyard from './graveyard.json';
const data = graveyard as Product[];
slugify.extend({
'+': 'plus',
'@': 'at',
});
describe('graveyard.json', () => {
test('All values are complete', () => {
data.forEach((product: 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();
});
});
test('Only allowed categories', () => {
data.forEach((product: Product) => {
expect(Object.values(ProductType).includes(product.type)).toBe(true);
});
});
test('Unique product names', () => {
const slugs = data.map((product: Product) => slugify(product.name, { lower: true }));
const slugSet = new Set(slugs);
expect(slugSet.size).toBe(data.length);
});
describe('Dates', () => {
test('Formatted correctly (yyyy-mm-dd)', () => {
data.forEach((product: Product) => {
// Check `dateClose` format
expect(product.dateClose.split("-")).toHaveLength(3);
expect(product.dateClose.split("-")[0]).toHaveLength(4);
expect(product.dateClose.split("-")[1]).toHaveLength(2);
expect(product.dateClose.split("-")[2]).toHaveLength(2);
// Check `dateOpen` format
expect(product.dateOpen.split("-")).toHaveLength(3);
expect(product.dateOpen.split("-")[0]).toHaveLength(4);
expect(product.dateOpen.split("-")[1]).toHaveLength(2);
expect(product.dateOpen.split("-")[2]).toHaveLength(2);
});
});
test('Dates are valid', () => {
data.forEach((product: Product) => {
const dateClose = moment(product.dateClose);
const dateOpen = moment(product.dateOpen);
expect(dateClose.isValid()).toBe(true);
expect(dateOpen.isValid()).toBe(true);
});
});
test('`dateClose` is after `dateOpen`', () => {
data.forEach((product: Product) => {
const dateClose = moment(product.dateClose);
const dateOpen = moment(product.dateOpen);
expect(dateClose.isAfter(dateOpen)).toBe(true);
});
});
});
});