-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtestHelpers.ts
More file actions
60 lines (54 loc) · 1.64 KB
/
testHelpers.ts
File metadata and controls
60 lines (54 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {jest} from "@jest/globals"
import * as sqs from "@aws-sdk/client-sqs"
import {PSUDataItem} from "@psu-common/commonTypes"
import {NotifyDataItemMessage} from "../src/utils"
// Similarly mock the SQS client
export function mockSQSClient() {
const mockSend = jest.fn()
jest.unstable_mockModule("@aws-sdk/client-sqs", () => {
return {
...sqs,
SQSClient: jest.fn().mockImplementation(() => ({
send: mockSend
}))
}
})
return {mockSend}
}
export function constructMessage(overrides: Partial<sqs.Message> = {}): sqs.Message {
return {
MessageId: "messageId",
Attributes: {
MessageDeduplicationId: crypto.randomUUID()
},
Body: JSON.stringify(constructPSUDataItem()),
...overrides
}
}
export function constructPSUDataItemMessage(overrides: Partial<NotifyDataItemMessage> = {}): NotifyDataItemMessage {
return {
...constructMessage(),
PSUDataItem: constructPSUDataItem(),
messageBatchReference: crypto.randomUUID(),
messageReference: crypto.randomUUID(),
notifyMessageId: crypto.randomUUID(),
...overrides
}
}
export function constructPSUDataItem(overrides: Partial<PSUDataItem> = {}): PSUDataItem {
return {
LastModified: "2023-01-02T00:00:00Z",
LineItemID: "spamandeggs",
PatientNHSNumber: "0123456789",
PharmacyODSCode: "ABC123",
PrescriptionID: "abcdef-ghijkl-mnopqr",
RequestID: "x-request-id",
Status: "ready to collect",
TaskID: "mnopqr-ghijkl-abcdef",
TerminalStatus: "ready to collect",
ApplicationName: "Jim's Pills",
ApplicationID: "550e8400-e29b-41d4-a716-446655440000",
ExpiryTime: 123,
...overrides
}
}