Skip to content

Commit

Permalink
Add a check whether the item has reached a terminal state completed
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-szlapa committed Jul 5, 2024
1 parent 83f24b6 commit ecaf529
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/gsul/src/dynamoDBclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function getItemsUpdatesForPrescription(
return items.map((singleUpdate) => ({
itemId: String(singleUpdate.LineItemID),
latestStatus: String(singleUpdate.Status),
isTerminalState: Boolean(singleUpdate.TerminalStatus),
isTerminalState: String(singleUpdate.TerminalStatus) === "completed",
lastUpdateDateTime: String(singleUpdate.LastModified)
}))
}
Expand Down
51 changes: 49 additions & 2 deletions packages/gsul/tests/testHander.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ describe("test handler", () => {
})
})

it("respond with success when data passed in", async () => {
it("respond with success when data passed in with a terminal status 'completed'", async () => {
const mockReply = {
Count: 1,
Items: [
{
PrescriptionID: "abc",
LineItemID: "item_1",
Status: "latest_status",
TerminalStatus: true,
TerminalStatus: "completed",
LastModified: "1970-01-01T00:00:00Z"
}
]
Expand Down Expand Up @@ -116,4 +116,51 @@ describe("test handler", () => {
]
})
})

it("respond with success when data passed in with a terminal status 'in-progress'", async () => {
const mockReply = {
Count: 1,
Items: [
{
PrescriptionID: "abc",
LineItemID: "item_1",
Status: "latest_status",
TerminalStatus: "in-progress",
LastModified: "1970-01-01T00:00:00Z"
}
]
}
jest.spyOn(DynamoDBDocumentClient.prototype, "send").mockResolvedValue(mockReply as never)

const response = await handler(
{
schemaVersion: 1,
prescriptions: [
{
prescriptionID: "abc",
odsCode: "123"
}
]
},
dummyContext
)
expect(response).toMatchObject({
schemaVersion: 1,
isSuccess: true,
prescriptions: [
{
prescriptionID: "abc",
onboarded: true,
items: [
{
itemId: "item_1",
latestStatus: "latest_status",
isTerminalState: false,
lastUpdateDateTime: "1970-01-01T00:00:00Z"
}
]
}
]
})
})
})
6 changes: 3 additions & 3 deletions packages/gsul/tests/testRunDynamoDBQueries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("testing dynamoDBClient", () => {
PrescriptionID: "abc",
LineItemID: "item_1",
Status: "latest_status",
TerminalStatus: true,
TerminalStatus: "completed",
LastModified: "1970-01-01T00:00:00Z"
}
]
Expand Down Expand Up @@ -71,7 +71,7 @@ describe("testing pagination in dynamoDBClient", () => {
PrescriptionID: "abc",
LineItemID: "item_1",
Status: "first_status",
TerminalStatus: true,
TerminalStatus: "completed",
LastModified: "1970-01-01T00:00:00Z"
}
],
Expand All @@ -88,7 +88,7 @@ describe("testing pagination in dynamoDBClient", () => {
PrescriptionID: "abc",
LineItemID: "item_1",
Status: "second_status",
TerminalStatus: true,
TerminalStatus: "completed",
LastModified: "1970-01-01T00:00:00Z"
}
]
Expand Down

0 comments on commit ecaf529

Please sign in to comment.