Skip to content

Commit

Permalink
Change the isTerminalState field to boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-szlapa committed Jul 4, 2024
1 parent 2854640 commit 8e038d7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 53 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: String(singleUpdate.TerminalStatus),
isTerminalState: Boolean(singleUpdate.TerminalStatus),
lastUpdateDateTime: String(singleUpdate.LastModified)
}))
}
Expand Down
3 changes: 1 addition & 2 deletions packages/gsul/src/schema/response.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {FromSchema} from "json-schema-to-ts"

// Set the isTerminalState field to bool
const itemSchema = {
type: "object",
required: ["itemId", "latestStatus", "isTerminalState", "lastUpdateDateTime"],
Expand All @@ -12,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
83 changes: 50 additions & 33 deletions packages/gsul/tests/testHander.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ describe("test handler", () => {
})

it("respond with error when schema version is 2", async () => {
const response = await handler({
"schemaVersion": 2,
"prescriptions": [{
prescriptionID: "abc",
odsCode: "123"
}]
}, dummyContext)
const response = await handler(
{
schemaVersion: 2,
prescriptions: [
{
prescriptionID: "abc",
odsCode: "123"
}
]
},
dummyContext
)
expect(response).toMatchObject({
schemaVersion: 1,
isSuccess: false,
Expand All @@ -53,9 +58,11 @@ describe("test handler", () => {

const response = await handler(
{
"schemaVersion": 1,
"prescriptions": []
}, dummyContext)
schemaVersion: 1,
prescriptions: []
},
dummyContext
)
expect(response).toMatchObject({
schemaVersion: 1,
isSuccess: true,
Expand All @@ -66,37 +73,47 @@ describe("test handler", () => {
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"
}]
Items: [
{
PrescriptionID: "abc",
LineItemID: "item_1",
Status: "latest_status",
TerminalStatus: true,
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)
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"
}]
}]
prescriptions: [
{
prescriptionID: "abc",
onboarded: true,
items: [
{
itemId: "item_1",
latestStatus: "latest_status",
isTerminalState: true,
lastUpdateDateTime: "1970-01-01T00:00:00Z"
}
]
}
]
})
})
})
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: true,
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: true,
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: true,
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

0 comments on commit 8e038d7

Please sign in to comment.