Skip to content

Commit

Permalink
switch to valid FHIR-resources in constant test
Browse files Browse the repository at this point in the history
Co-authored-by: mput <putintsev@gmail.com>
  • Loading branch information
Yngwarr and mput committed Feb 7, 2024
1 parent c4c58f1 commit 0a11f09
Showing 1 changed file with 74 additions and 18 deletions.
92 changes: 74 additions & 18 deletions sof-js/tests/5_constants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
]
}
]
},
Expand All @@ -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"
}
]
}
]
}
Expand Down

0 comments on commit 0a11f09

Please sign in to comment.