-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update evaluate cache to use a smaller key (#2939)
* update evaluate cache to use a smaller key * [pre-commit.ci] auto fixes from pre-commit hooks * use const instead of let Co-authored-by: Mary McGrath <[email protected]> * update clear-local to call seed scripts docker compose * point dockerfile to new version of fhir converter * update save to look at fhirBundle.id instead of first entry * update key and use map instead of object * fix tests to match correct ID * test: update snapshots * Update containers/ecr-viewer/src/app/view-data/utils/evaluate.ts Co-authored-by: Mary McGrath <[email protected]> * simplify evaluate logic * revert change to clear-local * Revert "point dockerfile to new version of fhir converter" This reverts commit 54b5979. * Revert "update save to look at fhirBundle.id instead of first entry" This reverts commit 2eb853b. * Revert "test: update snapshots" This reverts commit 81f49a4. * Revert "fix tests to match correct ID" This reverts commit c1a3369. * use keyword bundle * [pre-commit.ci] auto fixes from pre-commit hooks * simplify key * replace beforeEach clear evaluate cache with a global one * change to use spy * fix lab info test by using beforeAll * revert change to package-lock --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Mary McGrath <[email protected]>
- Loading branch information
1 parent
68c3d35
commit 16e578f
Showing
5 changed files
with
115 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 67 additions & 9 deletions
76
containers/ecr-viewer/src/app/view-data/utils/evaluate.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,88 @@ | ||
import { evaluate } from "@/app/view-data/utils/evaluate"; | ||
import { evaluate as fhirPathEvaluate } from "fhirpath"; | ||
|
||
jest.mock("fhirpath", () => ({ | ||
evaluate: jest.fn(), | ||
})); | ||
|
||
describe("evaluate", () => { | ||
let fhirPathEvaluateSpy: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
fhirPathEvaluateSpy = jest.spyOn(require("fhirpath"), "evaluate"); | ||
}); | ||
|
||
afterEach(() => { | ||
// Clear the mock implementation and calls after each test | ||
jest.clearAllMocks(); | ||
fhirPathEvaluateSpy.mockRestore(); | ||
}); | ||
|
||
it("fhirpath should be called 1 time when 1 call is made ", () => { | ||
evaluate({ id: "1234" }, "id"); | ||
|
||
expect(fhirPathEvaluate).toHaveBeenCalledOnce(); | ||
expect(fhirPathEvaluateSpy).toHaveBeenCalledExactlyOnceWith( | ||
{ id: "1234" }, | ||
"id", | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
); | ||
}); | ||
it("should call fhirpath.evaluate 1 time when the same call is made 2 times", () => { | ||
evaluate({ id: "2345" }, "id"); | ||
evaluate({ id: "2345" }, "id"); | ||
|
||
expect(fhirPathEvaluate).toHaveBeenCalledOnce(); | ||
expect(fhirPathEvaluateSpy).toHaveBeenCalledExactlyOnceWith( | ||
{ id: "2345" }, | ||
"id", | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
); | ||
}); | ||
it("should call fhirpath.evaluate 2 time when the context is different", () => { | ||
evaluate({ id: "%id" }, "id", { id: 1 }); | ||
evaluate({ id: "%id" }, "id", { id: 2 }); | ||
|
||
expect(fhirPathEvaluate).toHaveBeenCalledTimes(2); | ||
expect(fhirPathEvaluateSpy).toHaveBeenCalledTimes(2); | ||
expect(fhirPathEvaluateSpy).toHaveBeenNthCalledWith( | ||
1, | ||
{ id: "%id" }, | ||
"id", | ||
{ id: 1 }, | ||
undefined, | ||
undefined, | ||
); | ||
expect(fhirPathEvaluateSpy).toHaveBeenNthCalledWith( | ||
2, | ||
{ id: "%id" }, | ||
"id", | ||
{ id: 2 }, | ||
undefined, | ||
undefined, | ||
); | ||
}); | ||
|
||
it("should call once if resource type is bundle", () => { | ||
evaluate({ resourceType: "Bundle" }, "name"); | ||
evaluate({ resourceType: "Bundle" }, "name"); | ||
|
||
expect(fhirPathEvaluateSpy).toHaveBeenCalledExactlyOnceWith( | ||
{ resourceType: "Bundle" }, | ||
"name", | ||
undefined, | ||
undefined, | ||
undefined, | ||
); | ||
}); | ||
|
||
it("should call once if id is the same", () => { | ||
evaluate({ id: 1234 }, "name"); | ||
evaluate({ id: 1234, resourceType: "Observation" }, "name"); | ||
|
||
expect(fhirPathEvaluateSpy).toHaveBeenCalledExactlyOnceWith( | ||
{ id: 1234 }, | ||
"name", | ||
undefined, | ||
undefined, | ||
undefined, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters