Skip to content

Commit

Permalink
test multiple schema with allOf
Browse files Browse the repository at this point in the history
  • Loading branch information
theisuru committed Sep 4, 2023
1 parent 774ec5c commit 60e2436
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/bioschemasDefinedterm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const fs = require("fs");
const BioValidator = require('../src/core/biovalidator-core');

test(" -> BioSchemas DefinedTerm", () => {
let schema = JSON.parse(
fs.readFileSync("test/resources/bioschemas/schema.json").toString());
let data = JSON.parse(
fs.readFileSync("test/resources/bioschemas/data.json").toString());
let referencedSchemaPath = "test/resources/bioschemas/schema_bioschemas_definedterm.json";

const validator = new BioValidator(referencedSchemaPath);
return validator._validate(schema, data).then((result) => {
expect(result).toBeDefined()
expect(result.length).toBe(0);
});
});

test(" -> BioSchemas DefinedTerm invalid", () => {
let schema = JSON.parse(
fs.readFileSync("test/resources/bioschemas/schema.json").toString());
let data = JSON.parse(
fs.readFileSync("test/resources/bioschemas/data_invalid.json").toString());
let referencedSchemaPath = "test/resources/bioschemas/schema_bioschemas_definedterm.json";

const validator = new BioValidator(referencedSchemaPath);
return validator._validate(schema, data).then((result) => {
expect(result).toBeDefined();
expect(result.length).toBe(1);
// expect(result[0].message).toContain('Provided term is not child of');
expect(result[0].message).toContain('should have required property');
});
});

15 changes: 15 additions & 0 deletions test/resources/bioschemas/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"@type": "DefinedTerm",
"@id": "http://purl.obolibrary.org/obo/CHMO_0000230",
"termCode": "CHMO_0000230",
"name": "alpha-particle spectroscopy",
"identifier": "http://purl.obolibrary.org/obo/CHMO_0000230",
"url": "http://purl.obolibrary.org/obo/CHMO_0000230",
"inDefinedTermSet": {
"@type": "DefinedTermSet",
"@id": "http://purl.bioontology.org/ontology/CHMO",
"name": "Chemical Methods Ontology",
"identifier": "http://purl.bioontology.org/ontology/CHMO",
"url": "https://github.com/rsc-ontologies/rsc-cmo"
}
}
14 changes: 14 additions & 0 deletions test/resources/bioschemas/data_invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"@type": "DefinedTerm",
"@id": "http://purl.obolibrary.org/obo/CHMO_0000230",
"termCode": "MONDO:0018177",
"identifier": "http://purl.obolibrary.org/obo/CHMO_0000230",
"url": "http://purl.obolibrary.org/obo/CHMO_0000230",
"inDefinedTermSet": {
"@type": "DefinedTermSet",
"@id": "http://purl.bioontology.org/ontology/CHMO",
"name": "Chemical Methods Ontology",
"identifier": "http://purl.bioontology.org/ontology/CHMO",
"url": "https://github.com/rsc-ontologies/rsc-cmo"
}
}
27 changes: 27 additions & 0 deletions test/resources/bioschemas/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$id": "BioSchema/plus/customSchema/for/DefinedTerm",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"description": "Use custom schema on top of BioSchema to validate BioSchema type",
"type": "object",
"$allOf": [
{
"$ref": "bioschemas/definedterm"
},
{
"description": "My custom schema for DefinedTerm",
"type": "object",
"properties": {
"termCode": {
"type": "string",
"isChildTermOf": {
"parentTerm": "http://purl.obolibrary.org/obo/CHMO_0000800",
"ontologyId": "chmo"
}
}
},
"required": [
"termCode"
]
}
]
}
45 changes: 45 additions & 0 deletions test/resources/bioschemas/schema_bioschemas_definedterm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"$id": "bioschemas/definedterm",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "BioSchemas to validate BioSchema type",
"definitions": {
"definedtermset": {
"@type": "DefinedTermSet",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"identifier": {
"type": "string"
},
"url": {
"type": "string",
"format": "uri"
}
},
"required": []
}
},
"@type": "DefinedTerm",
"type": "object",
"properties": {
"url": {
"type": "string",
"format": "uri"
},
"name": {
"type": "string"
},
"termCode": {
"type": "string"
},
"identifier": {
"type": "string"
},
"inDefinedTermSet": {
"$ref": "#/definitions/definedtermset"
}
},
"required": ["name"]
}

0 comments on commit 60e2436

Please sign in to comment.