-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add unit tests for the quality extension (#96)
* feat: add unit tests for the quality extension * fix: description * fix: description * fix: add extra path check to tests * fix: removed larger timeout for tests
- Loading branch information
1 parent
da277db
commit 282312c
Showing
4 changed files
with
109 additions
and
147 deletions.
There are no files selected for viewing
50 changes: 0 additions & 50 deletions
50
extensions/quality/non-examples/incorrect_accuracy_type.json
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
extensions/quality/non-examples/incorrect_description.json
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
extensions/quality/non-examples/missing_lineage_description.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import o from 'ospec'; | ||
import Ajv from 'ajv'; | ||
import { dirname, join } from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { promises as fs } from 'fs'; | ||
import { AjvOptions } from '../../validation.js'; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
const schemaPath = join(__dirname, '..', 'schema.json'); | ||
const exampleCollectionPath = join(__dirname, '..', 'examples/collection.json'); | ||
|
||
o.spec('quality-collection', () => { | ||
let validate; | ||
const ajv = new Ajv(AjvOptions); | ||
|
||
o.before(async () => { | ||
const data = JSON.parse(await fs.readFile(schemaPath)); | ||
validate = await ajv.compileAsync(data); | ||
}); | ||
|
||
o('Collection should pass validation', async () => { | ||
// given | ||
const qualityCollectionExample = JSON.parse(await fs.readFile(exampleCollectionPath)); | ||
|
||
// when | ||
let valid = validate(qualityCollectionExample); | ||
|
||
// then | ||
o(valid).equals(true)(JSON.stringify(validate.errors, null, 2)); | ||
}); | ||
|
||
o("Collection without the mandatory 'quality:lineage' field should fail validation", async () => { | ||
// given | ||
const qualityCollectionExample = JSON.parse(await fs.readFile(exampleCollectionPath)); | ||
delete qualityCollectionExample['quality:lineage']; | ||
|
||
// when | ||
let valid = validate(qualityCollectionExample); | ||
|
||
// then | ||
o(valid).equals(false); | ||
o( | ||
validate.errors.some( | ||
(error) => error.dataPath === '' && error.message === "should have required property 'quality:lineage'", | ||
), | ||
).equals(true)(JSON.stringify(validate.errors)); | ||
}); | ||
|
||
o("Collection with an incorrect 'quality:description' field should fail validation", async () => { | ||
// given | ||
const qualityCollectionExample = JSON.parse(await fs.readFile(exampleCollectionPath)); | ||
qualityCollectionExample['quality:description'] = 1234; | ||
|
||
// when | ||
let valid = validate(qualityCollectionExample); | ||
|
||
// then | ||
o(valid).equals(false); | ||
o( | ||
validate.errors.some( | ||
(error) => error.dataPath === "['quality:description']" && error.message === 'should be string', | ||
), | ||
).equals(true)(JSON.stringify(validate.errors)); | ||
}); | ||
|
||
o( | ||
"Collection which contains a value for the 'quality:horizontal_accuracy_type' field which isn't one of the enumerated values should fail validation", | ||
async () => { | ||
// given | ||
const qualityCollectionExample = JSON.parse(await fs.readFile(exampleCollectionPath)); | ||
qualityCollectionExample['quality:horizontal_accuracy_type'] = 'Good'; | ||
|
||
// when | ||
let valid = validate(qualityCollectionExample); | ||
|
||
// then | ||
o(valid).equals(false); | ||
o( | ||
validate.errors.some( | ||
(error) => | ||
error.dataPath === "['quality:horizontal_accuracy_type']" && | ||
error.message === 'should be equal to one of the allowed values', | ||
), | ||
).equals(true)(JSON.stringify(validate.errors)); | ||
}, | ||
); | ||
|
||
o( | ||
"Collection which contains a value for the 'quality:vertical_accuracy_type' field which isn't one of the enumerated values should fail validation", | ||
async () => { | ||
// given | ||
const qualityCollectionExample = JSON.parse(await fs.readFile(exampleCollectionPath)); | ||
qualityCollectionExample['quality:vertical_accuracy_type'] = 'Good'; | ||
|
||
// when | ||
let valid = validate(qualityCollectionExample); | ||
|
||
// then | ||
o(valid).equals(false); | ||
o( | ||
validate.errors.some( | ||
(error) => | ||
error.dataPath === "['quality:vertical_accuracy_type']" && | ||
error.message === 'should be equal to one of the allowed values', | ||
), | ||
).equals(true)(JSON.stringify(validate.errors)); | ||
}, | ||
); | ||
}); |