-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathitem_test.ts
More file actions
82 lines (75 loc) · 2.42 KB
/
item_test.ts
File metadata and controls
82 lines (75 loc) · 2.42 KB
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
import { assertEquals, assertNotEquals } from "./deps.ts";
import HnItem from "./adapters/hn.ts";
import hnExampleJson from "./example/current/1-raw/2022/08/22/en_hn_2022_08_22_32407873.json" with { type: "json" };
import { parseItemIdentifier } from "./util.ts";
import ItemAdapter from "./adapters/mod.ts";
const list = [
{
class: HnItem,
originalItem: hnExampleJson,
},
];
for (const testItem of list) {
Deno.test("parse item valid #1", async (t) => {
const item = new testItem.class(testItem.originalItem);
await t.step(`${item.getType()} id must not empty`, () => {
assertNotEquals(item.getId(), "");
});
// published must initial
await t.step(`${item.getType()} published must initial`, () => {
assertNotEquals(item.getOriginalPublishedDate(), new Date(0));
});
// published modified must equal
await t.step(`${item.getType()} published modified must equal`, () => {
assertEquals(item.getPublishedDay(), item.getPublishedDay());
});
// title mush not empty
await t.step(`${item.getType()} title must not empty`, () => {
assertNotEquals(item.getTitle(), "");
});
// url must not empty
await t.step(`${item.getType()} url must not empty`, () => {
assertNotEquals(item.getUrl(), "");
});
// languatge must not empty
await t.step(`${item.getType()} languatge must not empty`, () => {
assertNotEquals(item.getOriginalLanguage(), "");
});
// source type must not empty
await t.step(`${item.getType()} source type must not item`, () => {
assertNotEquals(item.getType(), "item");
});
});
}
Deno.test("parseItemIdentifier #10", () => {
const parsed = parseItemIdentifier("en_hn_2022_08_26__32407873");
assertEquals(parsed, {
type: "hn",
id: "32407873",
year: "2022",
month: "08",
day: "26",
language: "en",
});
});
Deno.test("parseItemIdentifier #11", () => {
const parsed = parseItemIdentifier("en_hn_2022_08_23___32407873_-1223");
assertEquals(parsed, {
type: "hn",
id: "_32407873_-1223",
year: "2022",
month: "08",
day: "23",
language: "en",
});
});
Deno.test("item adapter class name equal with filename #12", () => {
const adapters = Object.keys(ItemAdapter);
for (const adapter of adapters) {
const adapterInstance = new ItemAdapter[adapter](
{} as unknown,
"example.com",
);
assertEquals(adapter, adapterInstance.getType());
}
});