Commit a1fd532e authored by Ruben Seggers's avatar Ruben Seggers
Browse files

Merge branch 'tests' into 'dev'

Tests

See merge request memri/schema!10
parents d1d603b2 f8dee45d
Showing with 56 additions and 15 deletions
+56 -15
# Output files
*schema.swift
*schema_target.swift
*schema_target2.swift
*schema.ts
*schema_target.ts
*autogenerated_database_schema.json
......
......@@ -10,56 +10,96 @@ let predicateHierarchy = {};
await helpers.getHierarchy(entityHierarchyPath, entityHierarchy, entityHierarchyPath, 'Item');
await helpers.getHierarchy(predicateHierarchyPath, predicateHierarchy, predicateHierarchyPath, 'EdgeOrProperty');
console.log('Check if properties of entities exist...');
console.log('\nCheck if properties of entities exist...');
for (const entity of Object.keys(entityHierarchy)) {
for (let property of entityHierarchy[entity]['properties']) {
if (!Object.keys(predicateHierarchy).includes(property)) {
console.log(`-> Type: '${entity}', has non-existent property: '${property}'`);
console.log(`E: Type: '${entity}', has non-existent property: '${property}'`);
}
}
}
console.log('Check if relations of entities exist...');
console.log('\nCheck if relations of entities exist...');
for (const entity of Object.keys(entityHierarchy)) {
for (let relation of Object.keys(entityHierarchy[entity]['relations'])) {
if (!Object.keys(predicateHierarchy).includes(relation)) {
console.log(`-> Type: '${entity}', has non-existent relation: '${relation}'`);
console.log(`E: Type: '${entity}', has non-existent relation: '${relation}'`);
}
}
}
console.log('Check if types of predicates exist...');
console.log('\nCheck if types of predicates exist...');
for (const predicate of Object.keys(predicateHierarchy)) {
if (predicateHierarchy[predicate]['type']) {
let type = predicateHierarchy[predicate]['type'];
if (!Object.keys(entityHierarchy).includes(type) && !helpers.PRIMITIVE_TYPES.includes(type) && type !== 'any') {
console.log(`-> Edge / Property: '${predicateHierarchy[predicate]['path']}', expects non-existent type: '${type}'`);
console.log(`E: Edge / Property: '${predicateHierarchy[predicate]['path']}', expects non-existent type: '${type}'`);
}
} else {
if (!predicateHierarchy[predicate]['children']) {
console.log(`-> Edge / Property: '${predicateHierarchy[predicate]['path']}', has no type.`);
console.log(`E: Edge / Property: '${predicateHierarchy[predicate]['path']}', has no type.`);
}
}
}
console.log('Check for duplicate properties and edges (inherited and redefined)...');
console.log('\nCheck for duplicate properties and edges (inherited and redefined)...');
for (const entity of Object.keys(entityHierarchy)) {
if (entityHierarchy[entity]['children']) {
const fields = entityHierarchy[entity]['properties'].concat(Object.keys(entityHierarchy[entity]['relations']))
const fields = entityHierarchy[entity]['properties'].concat(Object.keys(entityHierarchy[entity]['relations']));
for (const child of entityHierarchy[entity]['children']) {
const childFields = entityHierarchy[child]['properties'].concat(Object.keys(entityHierarchy[child]['relations']))
const childFields = entityHierarchy[child]['properties'].concat(Object.keys(entityHierarchy[child]['relations']));
for (const childField of childFields) {
if (fields.includes(childField)) {
console.log(`-> ${child} redefines ${childField} that is already in ${entity}.`)
console.log(`E: ${child} redefines ${childField} that is already in ${entity}.`);
}
}
}
}
}
// TODO check if lower cased properties and relations don't clash: they can't have different types
// TODO check if props are `double`, i.e. already inherited
// TODO check if there are unused Items
// TODO check if there are unused relationships/properties
console.log('\nCheck for unused Items...');
let usedTypes = new Set();
for (const predicate of Object.values(predicateHierarchy)) {
if (predicate['type']) usedTypes.add(predicate['type']);
}
for (const entity of Object.keys(entityHierarchy)) {
if (!usedTypes.has(entity)) {
console.log(`W: No Edge uses Item ${entity}`);
}
}
console.log('\nCheck for unused Edges...');
let usedEdges = new Set();
for (const entity of Object.values(entityHierarchy)) {
for (const relation of Object.keys(entity['relations'])) {
usedEdges.add(relation);
}
}
for (const edge of Object.keys(predicateHierarchy)) {
if (!(usedEdges.has(edge) || helpers.PRIMITIVE_TYPES.includes(predicateHierarchy[edge]['type']))) {
console.log(`W: No Item uses Edge ${edge}`);
}
}
console.log('\nCheck for TBDs...');
for (const entity of Object.keys(entityHierarchy)) {
if (entityHierarchy[entity]['description']) {
if (entityHierarchy[entity]['description'].toLowerCase().includes('tbd')) {
console.log(`W: Item ${entity} has TBD in description.`);
}
} else {
console.log(`W: Item ${entity} is missing a description.`);
}
}
for (const predicate of Object.keys(predicateHierarchy)) {
if (predicateHierarchy[predicate]['description']) {
if (predicateHierarchy[predicate]['description'].toLowerCase().includes('tbd')) {
console.log(`W: Edge / Property ${predicate} has TBD in description.`);
}
} else {
console.log(`W: Edge / Property ${predicate} is missing a description.`);
}
}
// TODO check if properties are shared over all children of an Item, so they could be inherited
})();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment