-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-classes-basic-type.js
More file actions
78 lines (66 loc) · 2.11 KB
/
Copy pathtest-classes-basic-type.js
File metadata and controls
78 lines (66 loc) · 2.11 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
/**
* This file tests the ontoME json API
* https://ontome.net/api/classes-profile.json
*
* The test compares the entityBasicType of each class across all profiles.
*
* If a class has different entityBasicTypes, it will be reported at the end of the script.
*
*/
const fetch = require('node-fetch');
const R = require('ramda');
async function start() {
classesAndBasicTypes = {};
const profiles = await fetchProfiles();
console.log(`fetched ${profiles.length} profiles`);
for (const profile of profiles) {
const classes = await fetchClasses(profile.profileID);
console.log(
`fetched ${classes.length} classes of profile ${profile.profileID}`
);
for (const klass of classes) {
classesAndBasicTypes[klass.classID] = [
...(classesAndBasicTypes[klass.classID] || []),
{
entityBasicType: klass.entityBasicType,
profileID: klass.profileID,
},
];
}
}
const report = [];
for (const key in classesAndBasicTypes) {
const items = classesAndBasicTypes[key];
const reportItem = {
classID: key,
distinctTypes: R.uniqBy((x) => x.entityBasicType, items).length,
profiles: items.map((i) => i.profileID + ': ' + i.entityBasicType),
};
report.push(reportItem);
}
const problematic = report.filter((x) => x.distinctTypes > 1);
console.log('\nREPORT\n');
console.log(
`${report.length - problematic.length} of ${
report.length
} classes have consistent entityBasicType across all profiles`
);
if (problematic.length) {
console.log(`WARNING: ${problematic.length} classes have inconsistent entityBasicTypes across the profiles:`);
console.log(problematic);
}
}
start().catch((e) => console.log(e));
async function fetchProfiles() {
const response = await fetch('https://ontome.net/api/profiles.json');
const profiles = await response.json();
return profiles;
}
async function fetchClasses(profileID) {
const response = await fetch(
'https://ontome.net/api/classes-profile.json?available-in-profile=' +
profileID
);
const classes = await response.json();
return classes;
}