forked from patternfly/patternfly-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.json.test.ts
More file actions
49 lines (42 loc) · 1.72 KB
/
Copy pathdocs.json.test.ts
File metadata and controls
49 lines (42 loc) · 1.72 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
import docs from '../docs.json';
describe('docs.json', () => {
it('should have metadata reflective of its content and unique links per each entry', () => {
const allLinks = new Set<string>();
const baseHashes = new Set<string | undefined>();
const flatDocs = Object.values(docs.docs).flat();
let totalDocs = 0;
flatDocs.forEach(entry => {
totalDocs += 1;
allLinks.add(entry.path);
if (entry.path.includes('documentation:')) {
baseHashes.add('documentation:');
} else if (entry.path.includes('/patternfly/patternfly-org/')) {
baseHashes.add(entry.path.split('/patternfly/patternfly-org/')[1]?.split('/')[0]);
} else if (entry.path.includes('/patternfly/patternfly-react/')) {
baseHashes.add(entry.path.split('/patternfly/patternfly-react/')[1]?.split('/')[0]);
} else {
baseHashes.add(`new-resource-${entry.path}`);
}
});
expect(docs.meta.totalEntries).toBeDefined();
expect(docs.meta.totalDocs).toBeDefined();
expect(Object.entries(docs.docs).length).toBe(docs.meta.totalEntries);
/**
* Confirm we have limited hashes, avoid variation within pf versions
* If this increases, hashes need to be realigned. Do not randomly change this value.
* 1 (v6 org) + 1 (v6 react) + 1 (v5 org) + 1 (local)
*/
expect(baseHashes.size).toBe(4);
/**
* Confirm total docs count matches metadata
* Update the JSON metadata accordingly
*/
expect(totalDocs).toBe(docs.meta.totalDocs);
/**
* Confirm unique links against metadata totals
* Update the JSON metadata accordingly
*/
expect(allLinks.size).toBe(flatDocs.length);
expect(allLinks.size).toBe(docs.meta.totalDocs);
});
});