|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { CSI, ENV } from 'constants/backend-constants'; |
| 3 | +import { PDMResourceAvailable } from 'digital-letters-events'; |
| 4 | +import messagePDMResourceAvailableValidator from 'digital-letters-events/PDMResourceAvailable.js'; |
| 5 | +import { getLogsFromCloudwatch } from 'helpers/cloudwatch-helpers'; |
| 6 | +import { getTtl } from 'helpers/dynamodb-helpers'; |
| 7 | +import eventPublisher from 'helpers/event-bus-helpers'; |
| 8 | +import expectToPassEventually from 'helpers/expectations'; |
| 9 | +import { expectMessageContainingString, purgeQueue } from 'helpers/sqs-helpers'; |
| 10 | +import {SenderManagement} from 'sender-management'; |
| 11 | +import { v4 as uuidv4 } from 'uuid'; |
| 12 | +import { ParameterStoreCache } from 'utils'; |
| 13 | + |
| 14 | +const senderIdInvokingNotify = 'componentTestSender_RoutingConfig'; |
| 15 | +const senderIdThatSkipsNotify = 'componentTestSender_NoRoutingConfig'; |
| 16 | +const EVENT_BUS_LOG_GROUP_NAME = `/aws/vendedlogs/events/event-bus/${ENV}`; |
| 17 | +const CORE_NOTIFIER_LAMBDA_LOG_GROUP_NAME = `/aws/lambda/${CSI}-core-notifier`; |
| 18 | + |
| 19 | +test.describe('Digital Letters - Core Notify', () => { |
| 20 | + const handleCoreNotifierDlqName = `${CSI}-core-notifier-errors-queue`; |
| 21 | + const parameterStore = new ParameterStoreCache(); |
| 22 | + const senderManagement = SenderManagement({ |
| 23 | + parameterStore, |
| 24 | + }); |
| 25 | + |
| 26 | + async function deleteSendersIfExist(){ |
| 27 | + senderManagement.deleteSender({senderId: senderIdInvokingNotify}); |
| 28 | + senderManagement.deleteSender({senderId: senderIdThatSkipsNotify}); |
| 29 | + }; |
| 30 | + |
| 31 | + test.beforeAll(async () => { |
| 32 | + await purgeQueue(handleCoreNotifierDlqName); |
| 33 | + await deleteSendersIfExist(); |
| 34 | + senderManagement.putSender({ |
| 35 | + senderId: senderIdInvokingNotify, |
| 36 | + senderName: 'componentTestSender_RoutingConfig', |
| 37 | + meshMailboxSenderId: 'meshMailboxSender1', |
| 38 | + meshMailboxReportsId: 'meshMailboxReports1', |
| 39 | + routingConfigId: 'routing-config-1', |
| 40 | + fallbackWaitTimeSeconds: 100, |
| 41 | + }); |
| 42 | + |
| 43 | + senderManagement.putSender({ |
| 44 | + senderId: senderIdThatSkipsNotify, |
| 45 | + senderName: 'componentTestSender_WithoutRoutingConfig', |
| 46 | + meshMailboxSenderId: 'meshMailboxSender2', |
| 47 | + meshMailboxReportsId: 'meshMailboxReports2', |
| 48 | + fallbackWaitTimeSeconds: 100, |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + test.afterAll(async () => { |
| 53 | + await purgeQueue(handleCoreNotifierDlqName); |
| 54 | + await deleteSendersIfExist(); |
| 55 | + }); |
| 56 | + |
| 57 | + |
| 58 | + test('given PDMResourceAvailable event, when client has routingConfigId then a message is sent to core Notify', async () => { |
| 59 | + const letterId = uuidv4(); |
| 60 | + |
| 61 | + await eventPublisher.sendEvents<PDMResourceAvailable>( |
| 62 | + [ |
| 63 | + { |
| 64 | + id: letterId, |
| 65 | + specversion: '1.0', |
| 66 | + source: |
| 67 | + '/nhs/england/notify/production/primary/data-plane/digitalletters/pdm', |
| 68 | + subject: |
| 69 | + 'customer/920fca11-596a-4eca-9c47-99f624614658/recipient/769acdd4-6a47-496f-999f-76a6fd2c3959', |
| 70 | + type: 'uk.nhs.notify.digital.letters.pdm.resource.available.v1', |
| 71 | + time: '2023-06-20T12:00:00Z', |
| 72 | + recordedtime: '2023-06-20T12:00:00.250Z', |
| 73 | + severitynumber: 2, |
| 74 | + traceparent: |
| 75 | + '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01', |
| 76 | + datacontenttype: 'application/json', |
| 77 | + dataschema: |
| 78 | + 'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-pdm-resource-available-data.schema.json', |
| 79 | + severitytext: 'INFO', |
| 80 | + data: { |
| 81 | + messageReference: 'ref1', |
| 82 | + senderId: senderIdInvokingNotify, |
| 83 | + resourceId: 'resource-123', |
| 84 | + nhsNumber: '9991234566', |
| 85 | + odsCode: 'A12345', |
| 86 | + }, |
| 87 | + }, |
| 88 | + ], |
| 89 | + messagePDMResourceAvailableValidator, |
| 90 | + ); |
| 91 | + |
| 92 | + // Verify the event happ |
| 93 | + await expectToPassEventually(async () => { |
| 94 | + const filteredLogs = await getLogsFromCloudwatch( |
| 95 | + CORE_NOTIFIER_LAMBDA_LOG_GROUP_NAME, |
| 96 | + [ |
| 97 | + '$.message.description = "1 of 1 records processed successfully"', |
| 98 | + ], |
| 99 | + ); |
| 100 | + |
| 101 | + expect(filteredLogs.length).toEqual(1); |
| 102 | + }, 120); |
| 103 | + // more assertions needed, i.e. the event published |
| 104 | + }); |
| 105 | + // create following tests |
| 106 | + // when the sender has no routingConfigId then the Skipped message is published |
| 107 | + // when fails repeatedly then goes to DLQ |
| 108 | +}); |
0 commit comments