Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
51 lines (40 loc) · 1.97 KB
/
Copy pathtest.js
File metadata and controls
51 lines (40 loc) · 1.97 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
const assert = require("assert");
const api = require("./index.js");
const EXPECTED_TERM_COUNT = 18355;
const EXPECTED_DOMAIN_COUNT = 19;
const RES_MIN_TERMS = 345;
assert.strictEqual(api.meta.termCount, EXPECTED_TERM_COUNT, `termCount should be ${EXPECTED_TERM_COUNT}`);
assert.strictEqual(api.terms.length, EXPECTED_TERM_COUNT);
const cs1 = api.byId("ACS-CS-0001");
assert(cs1 && cs1.DOMAIN === "Computer Science", "byId should find ACS-CS-0001");
assert.strictEqual(typeof api.createApi, "function", "createApi should be exported for flexible API creation");
const customApi = api.createApi();
assert(customApi && typeof customApi.search === "function", "createApi should return a usable API object");
const res = api.search("algorithm", { limit: 5 });
assert(Array.isArray(res) && res.length > 0, "search should return results");
const law = api.byDomain("Law", { limit: 3 });
assert(law.length === 3 && law[0].DOMAIN === "Law", "byDomain should filter Law");
const doms = api.domains();
assert.strictEqual(doms.length, EXPECTED_DOMAIN_COUNT, `should have ${EXPECTED_DOMAIN_COUNT} domains`);
const resDom = doms.find((d) => d.name === "Renewable Energy and Sustainability");
assert(resDom, "Renewable Energy and Sustainability domain should exist");
assert(
resDom.count >= RES_MIN_TERMS,
`RES domain should hold at least ${RES_MIN_TERMS} terms (found ${resDom.count})`
);
const res1 = api.byId("ACS-RES-0001");
assert(res1 && res1.DOMAIN === "Renewable Energy and Sustainability", "byId should find ACS-RES-0001");
assert(
res1.SOURCE.includes("Energy Information Administration"),
"RES terms must cite a real source"
);
const resTerms = api.byDomain("Renewable Energy and Sustainability", { limit: 1000 });
assert(
resTerms.every((t) => t.SOURCE && t.SOURCE.length > 10),
"every RES term must carry a named source"
);
assert(
resTerms.every((t) => t.DEFINITION_AR && t.DEFINITION_EN),
"every RES term must have both Arabic and English definitions"
);
console.log("All tests passed ✓");