-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsend-external-submission-message.test.js
More file actions
103 lines (87 loc) · 2.94 KB
/
send-external-submission-message.test.js
File metadata and controls
103 lines (87 loc) · 2.94 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { describe, test, expect, beforeEach, vi } from 'vitest'
vi.mock('@aws-sdk/client-sqs', () => ({
SendMessageCommand: vi.fn(function SendMessageCommand(input) {
this.input = input
})
}))
vi.mock('../../../config.js', () => ({
config: {
get: vi.fn((key) => {
if (key === 'sqsExternalSubmission.queueUrl') {
return 'http://localhost:4566/000000000000/pafs_external_submission'
}
return null
})
}
}))
const { SendMessageCommand } = await import('@aws-sdk/client-sqs')
const { sendExternalSubmissionMessage } =
await import('./send-external-submission-message.js')
describe('sendExternalSubmissionMessage', () => {
let mockSqsClient
beforeEach(() => {
vi.clearAllMocks()
mockSqsClient = { send: vi.fn().mockResolvedValue({}) }
})
test('sends a SendMessageCommand to the configured queue URL', async () => {
await sendExternalSubmissionMessage(
mockSqsClient,
'LCR/123/456',
BigInt(99)
)
expect(mockSqsClient.send).toHaveBeenCalledOnce()
expect(mockSqsClient.send).toHaveBeenCalledWith(
expect.objectContaining({
input: expect.objectContaining({
QueueUrl:
'http://localhost:4566/000000000000/pafs_external_submission'
})
})
)
})
test('message body contains referenceNumber and projectId as a string', async () => {
await sendExternalSubmissionMessage(
mockSqsClient,
'LCR/123/456',
BigInt(99)
)
const [command] = mockSqsClient.send.mock.calls[0]
const body = JSON.parse(command.input.MessageBody)
expect(body.referenceNumber).toBe('LCR/123/456')
expect(body.projectId).toBe('99')
})
test('serialises BigInt projectId to string (not a number)', async () => {
await sendExternalSubmissionMessage(
mockSqsClient,
'EA/999/AAA/2025',
BigInt('9007199254740993') // exceeds Number.MAX_SAFE_INTEGER — must use string to preserve precision
)
const [command] = mockSqsClient.send.mock.calls[0]
// Use the raw MessageBody string — JSON.parse would silently lose precision
// for integers beyond MAX_SAFE_INTEGER
expect(command.input.MessageBody).toContain(
'"projectId":"9007199254740993"'
)
})
test('constructs a SendMessageCommand with the correct shape', async () => {
await sendExternalSubmissionMessage(
mockSqsClient,
'LCR/123/456',
BigInt(42)
)
expect(SendMessageCommand).toHaveBeenCalledWith({
QueueUrl: 'http://localhost:4566/000000000000/pafs_external_submission',
MessageBody: JSON.stringify({
referenceNumber: 'LCR/123/456',
projectId: '42'
})
})
})
test('propagates errors thrown by sqsClient.send', async () => {
const sqsError = new Error('SQS unavailable')
mockSqsClient.send.mockRejectedValue(sqsError)
await expect(
sendExternalSubmissionMessage(mockSqsClient, 'LCR/123/456', BigInt(1))
).rejects.toThrow('SQS unavailable')
})
})