-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Summary Dispensing systems will send updatePrescriptionStatus requests to the PSU API to provide status updates on prescription items which are being processed by pharmacies using the system. The status updates will include a last updated time stamp and the NPPT service is only interested in the tracking status with the most recent time stamp. Although all status updates will be recorded in the data store, duplicate updates must be rejected. https://nhsd-jira.digital.nhs.uk/browse/AEA-4021 - ✨ New Feature
- Loading branch information
1 parent
7fe1e79
commit 438ff3c
Showing
8 changed files
with
211 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
68 changes: 68 additions & 0 deletions
68
packages/updatePrescriptionStatus/tests/testDatabaseClient.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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
expect, | ||
describe, | ||
it, | ||
jest | ||
} from "@jest/globals" | ||
|
||
import {TransactionCanceledException} from "@aws-sdk/client-dynamodb" | ||
import {mockDynamoDBClient} from "./utils/testUtils" | ||
|
||
const {mockSend} = mockDynamoDBClient() | ||
const {persistDataItems, logger} = await import("../src/utils/databaseClient") | ||
|
||
describe("Unit test persistDataItems", () => { | ||
beforeEach(() => { | ||
jest.resetModules() | ||
jest.clearAllMocks() | ||
}) | ||
it("when the conditional check fails, an error is thrown", async () => { | ||
const dataItems = [ | ||
{ | ||
LastModified: "2023-01-01T00:00:00Z", | ||
LineItemID: "LineItemID_1", | ||
PatientNHSNumber: "PatientNHSNumber_1", | ||
PharmacyODSCode: "PharmacyODSCode_1", | ||
PrescriptionID: "PrescriptionID_1", | ||
RequestID: "RequestID_1", | ||
Status: "Status_1", | ||
TaskID: "TaskID_1", | ||
TerminalStatus: "TerminalStatus_1", | ||
ApplicationName: "name" | ||
}, | ||
{ | ||
LastModified: "2023-01-02T00:00:00Z", | ||
LineItemID: "LineItemID_2", | ||
PatientNHSNumber: "PatientNHSNumber_2", | ||
PharmacyODSCode: "PharmacyODSCode_2", | ||
PrescriptionID: "PrescriptionID_1", | ||
RequestID: "RequestID_2", | ||
Status: "Status_2", | ||
TaskID: "TaskID_1", | ||
TerminalStatus: "TerminalStatus_2", | ||
ApplicationName: "name" | ||
} | ||
] | ||
|
||
mockSend.mockRejectedValue( | ||
new TransactionCanceledException({ | ||
$metadata: {}, | ||
message: "DynamoDB transaction cancelled due to conditional check failure.", | ||
CancellationReasons: [{Code: "ConditionalCheckFailedException"}] | ||
}) as never | ||
) | ||
const loggerSpy = jest.spyOn(logger, "error") | ||
|
||
await expect(persistDataItems(dataItems)).rejects.toThrow( | ||
new TransactionCanceledException({ | ||
$metadata: {}, | ||
message: "DynamoDB transaction cancelled due to conditional check failure.", | ||
CancellationReasons: [{Code: "ConditionalCheckFailedException"}] | ||
}) as never | ||
) | ||
|
||
expect(loggerSpy).toHaveBeenCalledWith("DynamoDB transaction cancelled due to conditional check failure.", { | ||
reasons: [{Code: "ConditionalCheckFailedException"}] | ||
}) | ||
}) | ||
}) |
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