Skip to content

Commit d526e61

Browse files
committed
Add send message policy to the update prescription lambda
1 parent b994b2b commit d526e61

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

SAMtemplates/functions/main.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ Resources:
6363
CodeUri: ../../packages
6464
Handler: updatePrescriptionStatus.handler
6565
Role: !GetAtt UpdatePrescriptionStatusResources.Outputs.LambdaRoleArn
66+
Policies:
67+
- Statement:
68+
Effect: Allow
69+
Action:
70+
- sqs:SendMessage
71+
Resource:
72+
- !Ref NHSNotifyPrescriptionsSQSQueueArn
6673
Environment:
6774
Variables:
6875
TABLE_NAME: !Ref PrescriptionStatusUpdatesTableName

packages/updatePrescriptionStatus/tests/testHandler.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,21 @@ describe("Integration tests for updatePrescriptionStatus handler", () => {
413413
})
414414

415415
it("when the notification SQS push fails, the response still succeeds", async () => {
416-
// TODO: I'm not convinced this is working...
416+
sqsMockSend.mockImplementation(
417+
async () => {
418+
throw new Error("Test error")
419+
}
420+
)
421+
422+
const event: APIGatewayProxyEvent = generateMockEvent(requestDispatched)
423+
const response: APIGatewayProxyResult = await handler(event, {})
424+
expect(response.statusCode).toBe(201)
425+
})
426+
427+
it("when SQS environment variables are not set, the response still succeeds", async () => {
428+
process.env.NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL = undefined
429+
process.env.AWS_REGION = undefined
430+
417431
sqsMockSend.mockImplementation(
418432
async () => {
419433
throw new Error("Test error")

0 commit comments

Comments
 (0)