diff --git a/curriculum-basis b/curriculum-basis index 534df3e..ce330e9 160000 --- a/curriculum-basis +++ b/curriculum-basis @@ -1 +1 @@ -Subproject commit 534df3e2d0ef0cb2f449473963bd7b323df38f3a +Subproject commit ce330e92515570d884c83a8ff6eb8632b0b01389 diff --git a/package.json b/package.json index 8e90685..dce8230 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,14 @@ "description": "Curriculum Context: Referentiekader nederlandse taal en rekenen", "main": "context.json", "scripts": { - "test": "node test/test.js" + "test": "node test/test.mjs" }, "author": "SLO", "license": "MIT", "dependencies": { "ajv": "^6.5.5", "jsondiffpatch": "^0.3.11", - "uuid": "^3.3.2" + "uuid": "^3.3.2", + "curriculum-js": "^0.4.1" } } diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 327a90c..0000000 --- a/test/test.js +++ /dev/null @@ -1,36 +0,0 @@ - var Ajv = require('ajv'); - var ajv = new Ajv({ - 'extendRefs': true, - 'allErrors': true, - 'jsonPointers': true - }); - var validate = null; - - ajv.addKeyword('itemTypeReference', { - validate: function(schema, data, parentSchema, dataPath, parentData, propertyName, rootData) { - var matches = /.*\#\/definitions\/(.*)/g.exec(schema); - if (matches) { - var result = curriculum.types[data] == matches[1]; - return result; - } - console.log('Unknown #ref definition: '+schema); - } - }); - - var curriculum = require('../curriculum-basis/lib/curriculum.js'); - var schema = curriculum.loadSchema('context.json'); - var basisSchema = curriculum.loadSchema('curriculum-basis/context.json', 'curriculum-basis/'); - - var valid = ajv.addSchema(basisSchema, 'https://opendata.slo.nl/curriculum/schemas/curriculum-basis/context.json') - .addSchema(schema, 'https://opendata.slo.nl/curriculum/schemas/curriculum-referentiekader/context.json') - .validate('https://opendata.slo.nl/curriculum/schemas/curriculum-referentiekader/context.json', curriculum.data); - - if (!valid) { - ajv.errors.forEach(function(error) { - console.log(error.dataPath+': '+error.message); - }); - console.log('data is invalid'); - process.exit(1); - } else { - console.log('data is valid!'); - } diff --git a/test/test.mjs b/test/test.mjs new file mode 100644 index 0000000..b2fa4ec --- /dev/null +++ b/test/test.mjs @@ -0,0 +1,22 @@ +import Curriculum from 'curriculum-js' + +async function validate() { + + var curriculum = new Curriculum() + var basisSchema = await curriculum.loadContextFromFile('curriculum-basis', 'curriculum-basis/context.json'); + var schema = await curriculum.loadContextFromFile('curriculum-referentiekader', 'context.json'); + try { + let result = await curriculum.validate(schema) + console.log('Data is valid!') + } catch(error) { + if (!error.validationErrors) { + console.error(error) + } else { + error.validationErrors.forEach(error => { + console.error(error.instancePath+': '+error.message) + }) + } + } +} + +validate()