diff --git a/sof-js/tests/1_basic.test.js b/sof-js/tests/1_basic.test.js index 2745369..8cbc34c 100644 --- a/sof-js/tests/1_basic.test.js +++ b/sof-js/tests/1_basic.test.js @@ -1,6 +1,6 @@ import { expect, test , describe, beforeAll, afterAll} from "bun:test"; import { evaluate, get_columns, row_product } from '../src/index.js' -import { start_case, end_case, add_test, debug, run_test, should_fail, add_throwing_test } from './test_helpers.js' +import { start_case, end_case, add_test, debug, should_fail, add_throwing_test } from './test_helpers.js' test("row_product", () => { expect(row_product([[{a: 1}, {a: 2}], [{b: 1}, {b: 2}]])) diff --git a/sof-js/tests/2_fhirpath.test.js b/sof-js/tests/2_fhirpath.test.js index 0809639..1085461 100644 --- a/sof-js/tests/2_fhirpath.test.js +++ b/sof-js/tests/2_fhirpath.test.js @@ -1,6 +1,6 @@ import { expect, test, describe } from "bun:test"; import { evaluate, row_product } from '../src/index.js' -import { start_case, end_case, add_test, run_test, should_fail } from './test_helpers.js' +import { start_case, end_case, add_test, should_fail } from './test_helpers.js' let l = console.log diff --git a/sof-js/tests/3_foreach.test.js b/sof-js/tests/3_foreach.test.js index 229fb56..b42c687 100644 --- a/sof-js/tests/3_foreach.test.js +++ b/sof-js/tests/3_foreach.test.js @@ -1,5 +1,5 @@ import { expect, test, describe } from "bun:test"; -import { start_case, end_case, run_test,add_test, debug } from './test_helpers.js' +import { start_case, end_case, add_test, debug } from './test_helpers.js' let l = console.log diff --git a/sof-js/tests/test_helpers.js b/sof-js/tests/test_helpers.js index 3d639db..9a5b0c6 100644 --- a/sof-js/tests/test_helpers.js +++ b/sof-js/tests/test_helpers.js @@ -4,6 +4,7 @@ import fs from 'fs' let test_case = null; + export function start_case(name, desc, resources) { test_case = { title: name, @@ -13,19 +14,10 @@ export function start_case(name, desc, resources) { } } -export function run_test(viewdef, result) { - // TODO: dump tests - let res = evaluate( viewdef, test_case.resources) - test_case.tests.push({view: viewdef, expect: result}) - expect(res).toEqual(result); - -} - - export function add_test(opts) { test(opts.title, () => { - const res = evaluate(opts.view, test_case.resources); test_case.tests.push(opts); + const res = evaluate(opts.view, test_case.resources); expect(res).toEqual(opts.expect); }) } @@ -38,10 +30,9 @@ export function add_throwing_test(opts) { } export function invalid_view(opts) { - test(opts.title, ()=>{ + test(opts.title, () => { test_case.tests.push(opts) let errs = errors(opts.view, test_case.resources) - // console.log(errs) expect((errs || []).length > 0).toEqual(true) }) } diff --git a/tests/fn_boundary.json b/tests/fn_boundary.json index c2668a0..4495ecd 100644 --- a/tests/fn_boundary.json +++ b/tests/fn_boundary.json @@ -31,5 +31,146 @@ "status": "final" } ], - "tests": [] + "tests": [ + { + "title": "decimal lowBoundary", + "view": { + "resource": "Observation", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "decimal", + "path": "value.ofType(Quantity).value.lowBoundary()" + } + ] + } + ] + }, + "expect": [ + { + "id": "o1", + "decimal": 0.95 + }, + { + "id": "o2", + "decimal": null + }, + { + "id": "o3", + "decimal": null + } + ] + }, + { + "title": "decimal highBoundary", + "view": { + "resource": "Observation", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "decimal", + "path": "value.ofType(Quantity).value.highBoundary()" + } + ] + } + ] + }, + "expect": [ + { + "id": "o1", + "decimal": 1.05 + }, + { + "id": "o2", + "decimal": null + }, + { + "id": "o3", + "decimal": null + } + ] + }, + { + "title": "datetime lowBoundary", + "view": { + "resource": "Observation", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "datetime", + "path": "value.ofType(DateTime).lowBoundary()" + } + ] + } + ] + }, + "expect": [ + { + "id": "o1", + "decimal": null + }, + { + "id": "o2", + "decimal": "2010-10-10T00:00:00.000+14:00" + }, + { + "id": "o3", + "decimal": null + } + ] + }, + { + "title": "datetime highBoundary", + "view": { + "resource": "Observation", + "status": "active", + "select": [ + { + "column": [ + { + "name": "id", + "path": "id" + }, + { + "name": "datetime", + "path": "value.ofType(DateTime).highBoundary()" + } + ] + } + ] + }, + "expect": [ + { + "id": "o1", + "decimal": null + }, + { + "id": "o2", + "decimal": "2010-10-10T23:59:59.999-12:00" + }, + { + "id": "o3", + "decimal": null + } + ] + } + ] }