|
1 | 1 | import { expect, test } from '@playwright/test'; |
| 2 | +import { ENV } from 'constants/backend-constants'; |
2 | 3 | import { MESHInboxMessageDownloaded } from 'digital-letters-events'; |
3 | 4 | import messageDownloadedValidator from 'digital-letters-events/MESHInboxMessageDownloaded.js'; |
| 5 | +import { getLogsFromCloudwatch } from 'helpers/cloudwatch-helpers'; |
4 | 6 | import { getTtl } from 'helpers/dynamodb-helpers'; |
5 | 7 | import eventPublisher from 'helpers/event-bus-helpers'; |
6 | 8 | import expectToPassEventually from 'helpers/expectations'; |
7 | 9 | import { v4 as uuidv4 } from 'uuid'; |
8 | 10 |
|
9 | 11 | test.describe('Digital Letters - Create TTL', () => { |
10 | | - test('should create TTL following downloaded message event', async () => { |
| 12 | + test('should create TTL and publish item enqueued event following message downloaded event', async () => { |
11 | 13 | const letterId = uuidv4(); |
12 | 14 | const messageUri = `https://example.com/ttl/resource/${letterId}`; |
13 | 15 |
|
@@ -40,10 +42,25 @@ test.describe('Digital Letters - Create TTL', () => { |
40 | 42 | messageDownloadedValidator, |
41 | 43 | ); |
42 | 44 |
|
| 45 | + // Verify TTL created |
43 | 46 | await expectToPassEventually(async () => { |
44 | 47 | const ttl = await getTtl(messageUri); |
45 | 48 |
|
46 | 49 | expect(ttl.length).toBe(1); |
47 | 50 | }); |
| 51 | + |
| 52 | + // Verify item enqueued event published |
| 53 | + await expectToPassEventually(async () => { |
| 54 | + const eventLogEntry = await getLogsFromCloudwatch( |
| 55 | + `/aws/vendedlogs/events/event-bus/nhs-${ENV}-dl`, |
| 56 | + [ |
| 57 | + '$.message_type = "EVENT_RECEIPT"', |
| 58 | + '$.details.detail_type = "uk.nhs.notify.digital.letters.queue.item.enqueued.v1"', |
| 59 | + `$.details.event_detail = "*\\"messageUri\\":\\"${messageUri}\\"*"`, |
| 60 | + ], |
| 61 | + ); |
| 62 | + |
| 63 | + expect(eventLogEntry.length).toEqual(1); |
| 64 | + }); |
48 | 65 | }); |
49 | 66 | }); |
0 commit comments