|
| 1 | +import { ListTopicsCommand, PublishCommand } from "@aws-sdk/client-sns"; |
| 2 | +import { expect, test } from "@playwright/test"; |
| 3 | +import getRestApiGatewayBaseUrl from "tests/helpers/aws-gateway-helper"; |
| 4 | +import { snsClient } from "tests/helpers/aws-sns-helper"; |
| 5 | + |
| 6 | +// prepared letter (Core) |
| 7 | +const preparedLetter = `{ |
| 8 | + "data": { |
| 9 | + "campaignId": "campaign_456", |
| 10 | + "clientId": "00f3b388-bbe9-41c9-9e76-052d37ee8988", |
| 11 | + "createdAt": "2025-08-28T08:45:00.000Z", |
| 12 | + "domainId": "letter1", |
| 13 | + "letterVariantId": "lv1", |
| 14 | + "pageCount": 2, |
| 15 | + "requestId": "0o5Fs0EELR0fUjHjbCnEtdUwQe3", |
| 16 | + "requestItemId": "0o5Fs0EELR0fUjHjbCnEtdUwQe4", |
| 17 | + "requestItemPlanId": "0o5Fs0EELR0fUjHjbCnEtdUwQe5", |
| 18 | + "sha256Hash": "3a7bd3e2360a3d29eea436fcfb7e44c735d117c8f2f1d2d1e4f6e8f7e6e8f7e6", |
| 19 | + "status": "PREPARED", |
| 20 | + "templateId": "template_123", |
| 21 | + "url": "s3://nhs-820178564574-eu-west-2-pr280-supapi-test-letters/letter1.png" |
| 22 | + }, |
| 23 | + "datacontenttype": "application/json", |
| 24 | + "dataschema": "https://notify.nhs.uk/cloudevents/schemas/letter-rendering/letter-request.prepared.1.0.0.schema.json", |
| 25 | + "dataschemaversion": "1.0.0", |
| 26 | + "id": "23f1f09c-a555-4d9b-8405-0b33490bc920", |
| 27 | + "plane": "data", |
| 28 | + "recordedtime": "2025-08-28T08:45:00.000Z", |
| 29 | + "severitynumber": 2, |
| 30 | + "severitytext": "INFO", |
| 31 | + "source": "/data-plane/letter-rendering/prod/render-pdf", |
| 32 | + "specversion": "1.0", |
| 33 | + "subject": "client/00f3b388-bbe9-41c9-9e76-052d37ee8988/letter-request/0o5Fs0EELR0fUjHjbCnEtdUwQe4_0o5Fs0EELR0fUjHjbCnEtdUwQe5", |
| 34 | + "time": "2025-08-28T08:45:00.000Z", |
| 35 | + "traceparent": "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01", |
| 36 | + "type": "uk.nhs.notify.letter-rendering.letter-request.prepared.v1" |
| 37 | +}`; |
| 38 | +// supplier event |
| 39 | +const supplierEvent = JSON.stringify({ |
| 40 | + data: { |
| 41 | + domainId: "f47ac10b-58cc-4372-a567-0e02b2c3d479", |
| 42 | + groupId: "client_template", |
| 43 | + origin: { |
| 44 | + domain: "letter-rendering", |
| 45 | + event: "f47ac10b-58cc-4372-a567-0e02b2c3d479", |
| 46 | + source: "/data-plane/letter-rendering/prod/render-pdf", |
| 47 | + subject: |
| 48 | + "client/00f3b388-bbe9-41c9-9e76-052d37ee8988/letter-request/0o5Fs0EELR0fUjHjbCnEtdUwQe4_0o5Fs0EELR0fUjHjbCnEtdUwQe5", |
| 49 | + }, |
| 50 | + specificationId: "1y3q9v1zzzz", |
| 51 | + status: "ACCEPTED", |
| 52 | + supplierId: "supplier1", |
| 53 | + }, |
| 54 | + datacontenttype: "application/json", |
| 55 | + dataschema: |
| 56 | + "https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.ACCEPTED.1.0.0.schema.json", |
| 57 | + dataschemaversion: "1.0.0", |
| 58 | + id: "23f1f09c-a555-4d9b-8405-0b33490bc920", |
| 59 | + plane: "data", |
| 60 | + recordedtime: "2025-08-28T08:45:00.000Z", |
| 61 | + severitynumber: 2, |
| 62 | + severitytext: "INFO", |
| 63 | + source: "/data-plane/supplier-api/prod/update-status", |
| 64 | + specversion: "1.0", |
| 65 | + subject: |
| 66 | + "letter-origin/letter-rendering/letter/f47ac10b-58cc-4372-a567-0e02b2c3d479", |
| 67 | + time: "2025-08-28T08:45:00.000Z", |
| 68 | + traceparent: "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01", |
| 69 | + type: "uk.nhs.notify.supplier-api.letter.ACCEPTED.v1", |
| 70 | +}); |
| 71 | + |
| 72 | +test.describe("initial describe", () => { |
| 73 | + test("Listing Topics", async () => { |
| 74 | + const response = await snsClient.send(new ListTopicsCommand({})); |
| 75 | + console.log("Listing topics"); |
| 76 | + console.log(response); |
| 77 | + }); |
| 78 | + |
| 79 | + test("publish command", async () => { |
| 80 | + console.log("about to sent a message"); |
| 81 | + const letterResponse = await snsClient.send( |
| 82 | + new PublishCommand({ |
| 83 | + Message: preparedLetter, |
| 84 | + TopicArn: |
| 85 | + "arn:aws:sns:eu-west-2:820178564574:nhs-pr328-supapi-eventsub", |
| 86 | + }), |
| 87 | + ); |
| 88 | + console.log(letterResponse); |
| 89 | + const eventResponse = await snsClient.send( |
| 90 | + new PublishCommand({ |
| 91 | + Message: supplierEvent, |
| 92 | + TopicArn: |
| 93 | + "arn:aws:sns:eu-west-2:820178564574:nhs-pr328-supapi-eventsub", |
| 94 | + }), |
| 95 | + ); |
| 96 | + console.log(eventResponse); |
| 97 | + console.log("trigger another build"); |
| 98 | + }); |
| 99 | +}); |
0 commit comments