Skip to content

Commit

Permalink
AEA-4047 Test additions for update scenarios.
Browse files Browse the repository at this point in the history
  • Loading branch information
originalphil committed Jul 9, 2024
1 parent 5c1c223 commit a243555
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SAMtemplates/functions/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Resources:
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
GET_STATUS_UPDATES: !Ref ToggleGetStatusUpdates
EXPECT_STATUS_UPDATES: !Ref ToggleGetStatusUpdates
Metadata:
BuildMethod: esbuild
BuildProperties:
Expand Down
2 changes: 1 addition & 1 deletion packages/enrichPrescriptions/src/statusUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const TEMPORARILY_UNAVAILABLE_STATUS = "Tracking Temporarily Unavailable"
export const APPROVED_STATUS = "Prescriber Approved"
export const CANCELLED_STATUS = "Prescriber Cancelled"

export const expectStatusUpdates = () => process.env.GET_STATUS_UPDATES === "true"
export const expectStatusUpdates = () => process.env.EXPECT_STATUS_UPDATES === "true"

type MedicationRequestStatus = "completed" | "active"

Expand Down
15 changes: 12 additions & 3 deletions packages/enrichPrescriptions/tests/testHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {lambdaHandler} from "../src/enrichPrescriptions"
describe("Unit tests for handler", function () {
beforeEach(() => {
jest.useFakeTimers().setSystemTime(SYSTEM_DATETIME)
process.env.GET_STATUS_UPDATES = "true"
process.env.EXPECT_STATUS_UPDATES = "true"
})

it("when event contains a bundle with one prescription, one MedicationRequest and status updates, updates are applied", async () => {
Expand Down Expand Up @@ -53,17 +53,26 @@ describe("Unit tests for handler", function () {
expect(actualResponse).toEqual(expectedResponse)
})

it("when no status update data (call to GetStatusUpdates toggled-off), no updates are applied", async () => {
it("when no status update data (GetStatusUpdates toggled-off), no updates are applied", async () => {
process.env.EXPECT_STATUS_UPDATES = "false"
const {event, expectedResponse} = noUpdateDataEventAndResponse()
const actualResponse = await lambdaHandler(event)

expect(actualResponse).toEqual(expectedResponse)
})

it("when status update is unsuccessful (call to GetStatusUpdates fails), temporary updates are applied", async () => {
it("when status updates are expected but unsuccessful (GetStatusUpdates fails at code level), temporary updates are applied", async () => {
const {event, expectedResponse} = getStatusUpdatesFailedEventAndResponse()
const actualResponse = await lambdaHandler(event)

expect(actualResponse).toEqual(expectedResponse)
})

it("when status updates are expected but not present (GetStatusUpdates fails at state machine level), temporary updates are applied", async () => {
const {event, expectedResponse} = getStatusUpdatesFailedEventAndResponse()
delete event.StatusUpdates
const actualResponse = await lambdaHandler(event)

expect(actualResponse).toEqual(expectedResponse)
})
})
17 changes: 16 additions & 1 deletion packages/enrichPrescriptions/tests/testStatusUpdate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import {
ONE_WEEK_IN_MS,
StatusUpdates,
TEMPORARILY_UNAVAILABLE_STATUS,
UpdatesScenario,
applyStatusUpdates,
applyTemporaryStatusUpdates,
delayWithPharmacyStatus,
getStatusDate
getStatusDate,
getUpdatesScenario
} from "../src/statusUpdates"
import {Bundle, MedicationRequest} from "fhir/r4"
import {Logger} from "@aws-lambda-powertools/logger"
Expand Down Expand Up @@ -482,4 +484,17 @@ describe("Unit tests for statusUpdate", function () {
expect(allMedicationRequests.length).toEqual(6)
expect(allMedicationRequestsWithTemporaryUpdates.length).toEqual(3)
})

it.each([
{expectUpdates: true, updatesPresent: true, expected: UpdatesScenario.Present},
{expectUpdates: true, updatesPresent: false, expected: UpdatesScenario.ExpectedButAbsent},
{expectUpdates: false, updatesPresent: false, expected: UpdatesScenario.NotExpected}
])("getUpdatesScenario returns as expected", async ({expectUpdates, updatesPresent, expected}) => {
process.env.EXPECT_STATUS_UPDATES = expectUpdates ? "true" : "false"
const statusUpdates = updatesPresent ? {isSuccess: true, prescriptions: [], schemaVersion: 1} : undefined

const scenario = getUpdatesScenario(statusUpdates)

expect(scenario).toEqual(expected)
})
})

0 comments on commit a243555

Please sign in to comment.