diff --git a/sof-js/tests/5_constants.test.js b/sof-js/tests/5_constants.test.js index 1453b47..4ef99ac 100644 --- a/sof-js/tests/5_constants.test.js +++ b/sof-js/tests/5_constants.test.js @@ -8,49 +8,100 @@ import { } from "./test_helpers.js"; const resources = [ - { id: "pt1", name: "Dragan" }, - { id: "pt2", name: "Ivona" } + { + resourceType: "Patient", + id: "pt1", + name: [ + { + family: "Block", + use: "usual" + }, + { + family: "Smith", + use: "official" + } + ] + }, + { + resourceType: "Patient", + id: "pt2", + name: [{ + family: "Johnson", + use: "usual" + }] + } ]; start_case("constant", "constant substitution", resources); describe("constant", () => { add_test({ - title: "basic constants", + title: "constant in path", view: { - constant: [{ name: "name", valueString: "Dragan" }], + constant: [{ name: "name_use", valueString: "official" }], select: [ { - forEach: "where(name = %name)", - column: [{ name: "id", path: "id" }] + column: [ + { name: "id", path: "id" }, + { + name: "official_name", + path: "name.where(use = %name_use).family" + } + ] } ] }, - expect: [{ id: "pt1" }] + expect: [ + { id: "pt1", official_name: "Smith" }, + { id: "pt2", official_name: null } + ] }); add_test({ - title: "in global where", + title: "constant in forEach", view: { - constant: [{ name: "name", valueString: "Dragan" }], + constant: [{ name: "name_use", valueString: "official" }], select: [ { - column: [{ name: "id", path: "id" }] + forEach: "name.where(use = %name_use)", + column: [ + { name: "official_name", path: "family" } + ] + } + ] + }, + expect: [ + { official_name: "Smith" } + ] + }); + + add_test({ + title: "constant in where element", + view: { + constant: [{ name: "name_use", valueString: "official" }], + select: [ + { + column: [ + { name: "id", path: "id" }, + { name: "name", path: "name.family.join(', ')" }, + ] } ], - where: [{ path: "name = %name" }] + where: [{ path: "name.where(use = %name_use)" }] }, - expect: [{ id: "pt1" }] + expect: [{ id: "pt1", name: "Block, Smith" }] }); add_throwing_test({ title: "accessing an undefined constant", view: { - constant: [{ name: "name", valueString: "Dragan" }], + constant: [{ name: "name_use", valueString: "official" }], select: [ { - forEach: "where(name = %the_name)", - column: [{ name: "id", path: "id" }] + forEach: "name.where(use = %wrong_name)", + column: [ + { name: "official_name", path: "family" } + ] } ] }, @@ -60,11 +111,16 @@ describe("constant", () => { invalid_view({ title: "incorrect constant definition", view: { - constant: [{ name: "name" }], + constant: [{ name: "name_use" }], select: [ { - forEach: "where(name = %name)", - column: [{ name: "id", path: "id" }] + column: [ + { name: "id", path: "id" }, + { + name: "official_name", + path: "name.where(use = %name_use).family" + } + ] } ] }