Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: [AEA-4207] - Set the isTerminalState field to bool #481

Merged
merged 10 commits into from
Jul 5, 2024
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: String(singleUpdate.TerminalStatus),
isTerminalState: String(singleUpdate.TerminalStatus) === "completed",
lastUpdateDateTime: String(singleUpdate.LastModified)
}))
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gsul/src/schema/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const itemSchema = {
type: "string"
},
isTerminalState: {
type: "string"
type: "boolean"
},
lastUpdateDateTime: {
type: "string"
Expand Down
22 changes: 11 additions & 11 deletions packages/gsul/tests/testBuildResult.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const scenarios: Array<scenariosType> = [
{
itemId: "item_1",
latestStatus: "latest_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1970-01-01T00:00:00Z"
}
],
Expand All @@ -30,7 +30,7 @@ const scenarios: Array<scenariosType> = [
{
itemId: "item_1",
latestStatus: "latest_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1970-01-01T00:00:00Z"
}
]
Expand Down Expand Up @@ -59,13 +59,13 @@ const scenarios: Array<scenariosType> = [
{
itemId: "item_1",
latestStatus: "early_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1970-01-01T00:00:00Z"
},
{
itemId: "item_1",
latestStatus: "latest_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1971-01-01T00:00:00Z"
}
],
Expand All @@ -76,7 +76,7 @@ const scenarios: Array<scenariosType> = [
{
itemId: "item_1",
latestStatus: "latest_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1971-01-01T00:00:00Z"
}
]
Expand All @@ -92,25 +92,25 @@ const scenarios: Array<scenariosType> = [
{
itemId: "item_1",
latestStatus: "item_1_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1970-01-01T00:00:00Z"
},
{
itemId: "item_1",
latestStatus: "latest_item_1_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1972-01-01T00:00:00Z"
},
{
itemId: "item_2",
latestStatus: "item_2_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1971-01-01T00:00:00Z"
},
{
itemId: "item_2",
latestStatus: "early_item_2_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1970-01-01T00:00:00Z"
}
],
Expand All @@ -121,13 +121,13 @@ const scenarios: Array<scenariosType> = [
{
itemId: "item_1",
latestStatus: "latest_item_1_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1972-01-01T00:00:00Z"
},
{
itemId: "item_2",
latestStatus: "item_2_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1971-01-01T00:00:00Z"
}
]
Expand Down
192 changes: 126 additions & 66 deletions packages/gsul/tests/testHander.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,74 +29,134 @@ describe("test handler", () => {
jest.clearAllMocks()
})

it("respond with error when schema version is 2", async () => {
const response = await handler({
"schemaVersion": 2,
"prescriptions": [{
prescriptionID: "abc",
odsCode: "123"
}]
}, dummyContext)
expect(response).toMatchObject({
schemaVersion: 1,
isSuccess: false,
prescriptions: []
})
})

it("respond with success for empty request", async () => {
const mockReply = {
Count: 0,
Items: []
}
jest.spyOn(DynamoDBDocumentClient.prototype, "send").mockResolvedValue(mockReply as never)

const response = await handler(
{
"schemaVersion": 1,
"prescriptions": []
}, dummyContext)
expect(response).toMatchObject({
schemaVersion: 1,
isSuccess: true,
prescriptions: []
})
})

it("respond with success when data passed in", async () => {
const mockReply = {
Count: 1,
Items: [{
PrescriptionID: "abc",
LineItemID: "item_1",
Status: "latest_status",
TerminalStatus: "terminal",
LastModified: "1970-01-01T00:00:00Z"
}]
const testCases = [
{
description: "responds with error when schema version is 2",
event: {
schemaVersion: 2,
prescriptions: [
{
prescriptionID: "abc",
odsCode: "123"
}
]
},
mockReply: null,
expectedResponse: {
schemaVersion: 1,
isSuccess: false,
prescriptions: []
}
},
{
description: "responds with success for empty request",
event: {
schemaVersion: 1,
prescriptions: []
},
mockReply: {
Count: 0,
Items: []
},
expectedResponse: {
schemaVersion: 1,
isSuccess: true,
prescriptions: []
}
},
{
description: "responds with success when data passed in with a terminal status 'completed'",
event: {
schemaVersion: 1,
prescriptions: [
{
prescriptionID: "abc",
odsCode: "123"
}
]
},
mockReply: {
Count: 1,
Items: [
{
PrescriptionID: "abc",
LineItemID: "item_1",
Status: "latest_status",
TerminalStatus: "completed",
LastModified: "1970-01-01T00:00:00Z"
}
]
},
expectedResponse: {
schemaVersion: 1,
isSuccess: true,
prescriptions: [
{
prescriptionID: "abc",
onboarded: true,
items: [
{
itemId: "item_1",
latestStatus: "latest_status",
isTerminalState: true,
lastUpdateDateTime: "1970-01-01T00:00:00Z"
}
]
}
]
}
},
{
description: "responds with success when data passed in with a terminal status 'in-progress'",
event: {
schemaVersion: 1,
prescriptions: [
{
prescriptionID: "abc",
odsCode: "123"
}
]
},
mockReply: {
Count: 1,
Items: [
{
PrescriptionID: "abc",
LineItemID: "item_1",
Status: "latest_status",
TerminalStatus: "in-progress",
LastModified: "1970-01-01T00:00:00Z"
}
]
},
expectedResponse: {
schemaVersion: 1,
isSuccess: true,
prescriptions: [
{
prescriptionID: "abc",
onboarded: true,
items: [
{
itemId: "item_1",
latestStatus: "latest_status",
isTerminalState: false,
lastUpdateDateTime: "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: "terminal",
lastUpdateDateTime: "1970-01-01T00:00:00Z"
}]
}]
testCases.forEach(({description, event, mockReply, expectedResponse}) => {
it(description, async () => {
if (mockReply) {
jest.spyOn(DynamoDBDocumentClient.prototype, "send").mockResolvedValue(mockReply as never)
}
const response = await handler(event, dummyContext)
expect(response).toMatchObject(expectedResponse)
})
})
})
12 changes: 6 additions & 6 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: "is_terminal_status",
TerminalStatus: "completed",
LastModified: "1970-01-01T00:00:00Z"
}
]
Expand All @@ -37,7 +37,7 @@ describe("testing dynamoDBClient", () => {
{
itemId: "item_1",
latestStatus: "latest_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "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: "is_terminal_status",
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: "is_terminal_status",
TerminalStatus: "completed",
LastModified: "1970-01-01T00:00:00Z"
}
]
Expand All @@ -106,13 +106,13 @@ describe("testing pagination in dynamoDBClient", () => {
{
itemId: "item_1",
latestStatus: "first_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1970-01-01T00:00:00Z"
},
{
itemId: "item_1",
latestStatus: "second_status",
isTerminalState: "is_terminal_status",
isTerminalState: true,
lastUpdateDateTime: "1970-01-01T00:00:00Z"
}
])
Expand Down
Loading