Skip to content

Commit

Permalink
Merge branch 'test-schema' into aehrc-master
Browse files Browse the repository at this point in the history
  • Loading branch information
johngrimes committed Feb 23, 2024
2 parents ec827cb + ff90e11 commit 98cc93d
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
- name: Check formatting
working-directory: sof-js
run: bun run check-fmt
- name: Validate JSON tests
working-directory: sof-js
run: bun run validate
- name: Run tests
working-directory: sof-js
run: bun test
Expand Down
3 changes: 2 additions & 1 deletion sof-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"type": "module",
"scripts": {
"fmt": "prettier -w ../tests",
"check-fmt": "prettier -c ../tests"
"check-fmt": "prettier -c ../tests",
"validate": "ajv -s ../tests.schema.json -d \"../tests/*.json\""
},
"author": "niquola,jmandel",
"license": "ISC",
Expand Down
50 changes: 27 additions & 23 deletions sof-js/tests/validation.test.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,65 @@
import { describe } from "bun:test";
import { start_case, end_case, invalid_view, debug, add_throwing_test } from './test_helpers.js'

import { describe } from 'bun:test'
import { add_throwing_test, end_case, invalid_view, start_case } from './test_helpers.js'

let resources = [
{
resourceType: 'Patient',
name: [
{ family: 'F1.1' },
],
id: 'pt1'
name: [{ family: 'F1.1' }],
id: 'pt1',
},
{
resourceType: 'Patient',
id: 'pt2'
id: 'pt2',
},
]

start_case('validate', 'TBD', resources)

describe("validate", () => {

describe('validate', () => {
invalid_view({
title: 'empty',
view: {},
expectError: true
});
expectError: true,
})

invalid_view({
title: 'missing resource',
view: {
select: [{ column: [{ name: 'id', path: 'id' }] }],
},
expectError: true,
})

invalid_view({
title: 'wrong fhirpath',
view: {
resource: 'Patient',
status: 'active',
select: [{forEach: '@@'}]
select: [{ forEach: '@@' }],
},
expectError: true
});
expectError: true,
})

invalid_view({
title: 'wrong type in forEach',
view: {
resource: 'Patient',
status: 'active',
select: [{forEach: 1}]
select: [{ forEach: 1 }],
},
expectError: true
});
expectError: true,
})

add_throwing_test({
title: 'where with path resolving to not boolean',
view: {
resource: 'Patient',
status: 'active',
select: [{column: [{name: 'id', path: 'id'}]}],
where: [{path: "name.family"}]
select: [{ column: [{ name: 'id', path: 'id' }] }],
where: [{ path: 'name.family' }],
},
expectError: true
});
expectError: true,
})

end_case()
});
})
109 changes: 109 additions & 0 deletions tests.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"$id": "http://hl7.org/fhir/uv/sql-on-fhir/tests",
"title": "SQL on FHIR tests schema",
"description": "Standard format for JSON test definitions used to validate SQL on FHIR view runner implementations.",
"type": "object",
"required": [
"title",
"resources",
"tests"
],
"properties": {
"title": {
"type": "string",
"description": "The name of the test suite."
},
"description": {
"type": "string",
"description": "A description of the test suite."
},
"allowExtendedFhirpath": {
"type": "boolean",
"description": "If true, the test runner should allow the use of FHIRPath functions outside of the restricted subset defined in the specification."
},
"authors": {
"type": "array",
"items": {
"type": "string"
},
"description": "The authors of the test suite."
},
"generated": {
"type": "boolean",
"description": "If true, the test suite was generated by a tool and should not be edited directly."
},
"resources": {
"type": "array",
"items": {
"type": "object"
},
"description": "A list of FHIR resources that are used in the tests. There can be multiple different resource types in the list. Each should be a valid FHIR resource."
},
"tests": {
"type": "array",
"description": "A list of tests to run against the view.",
"minItems": 1,
"items": {
"type": "object",
"required": [
"title",
"view"
],
"oneOf": [
{
"required": [
"expect"
]
},
{
"required": [
"expectCount"
]
},
{
"required": [
"expectError"
]
}
],
"properties": {
"title": {
"type": "string",
"description": "The name of the test."
},
"description": {
"type": "string",
"description": "A description of the test."
},
"view": {
"type": "object",
"description": "The view to run the test against."
},
"expect": {
"type": "array",
"description": "The expected result of the test. Each object within the array represents a row in the result set, with column names as keys.",
"items": {
"type": "object"
}
},
"expectCount": {
"type": "number",
"description": "The expected number of rows in the result."
},
"expectError": {
"type": "boolean",
"description": "If true, the test is expected to throw an error."
},
"expectColumns": {
"type": "array",
"description": "The expected columns in the result set.",
"items": {
"type": "string"
},
"minItems": 1
}
}
}
}
}
}
16 changes: 16 additions & 0 deletions tests/validate.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@
"view": {},
"expectError": true
},
{
"title": "missing resource",
"view": {
"select": [
{
"column": [
{
"name": "id",
"path": "id"
}
]
}
]
},
"expectError": true
},
{
"title": "wrong fhirpath",
"view": {
Expand Down

0 comments on commit 98cc93d

Please sign in to comment.