|
1 | 1 | import { SQSEvent, SQSRecord } from "aws-lambda"; |
2 | 2 | import pino from "pino"; |
3 | | -import { LetterRepository } from "internal/datastore/src"; |
| 3 | +import { |
| 4 | + LetterAlreadyExistsError, |
| 5 | + LetterRepository, |
| 6 | +} from "@internal/datastore"; |
4 | 7 | import { LetterRequestPreparedEventV2 } from "@nhsdigital/nhs-notify-event-schemas-letter-rendering"; |
5 | 8 | import { LetterRequestPreparedEvent } from "@nhsdigital/nhs-notify-event-schemas-letter-rendering-v1"; |
6 | 9 | import { |
@@ -199,7 +202,11 @@ describe("createUpsertLetterHandler", () => { |
199 | 202 | putLetter: jest.fn(), |
200 | 203 | updateLetterStatus: jest.fn(), |
201 | 204 | } as unknown as LetterRepository, |
202 | | - logger: { error: jest.fn(), info: jest.fn() } as unknown as pino.Logger, |
| 205 | + logger: { |
| 206 | + error: jest.fn(), |
| 207 | + warn: jest.fn(), |
| 208 | + info: jest.fn(), |
| 209 | + } as unknown as pino.Logger, |
203 | 210 | env: { |
204 | 211 | LETTERS_TABLE_NAME: "LETTERS_TABLE_NAME", |
205 | 212 | LETTER_TTL_HOURS: 12_960, |
@@ -301,6 +308,31 @@ describe("createUpsertLetterHandler", () => { |
301 | 308 | ); |
302 | 309 | }); |
303 | 310 |
|
| 311 | + it("does not treat a replayed insert as a failure", async () => { |
| 312 | + const v1message = { |
| 313 | + letterEvent: createPreparedV1Event(), |
| 314 | + supplierSpec: { |
| 315 | + supplierId: "supplier1", |
| 316 | + specId: "spec1", |
| 317 | + priority: 10, |
| 318 | + billingId: "billing1", |
| 319 | + }, |
| 320 | + }; |
| 321 | + const evt: SQSEvent = createSQSEvent([ |
| 322 | + createSqsRecord("msg2", JSON.stringify(v1message)), |
| 323 | + ]); |
| 324 | + (mockedDeps.letterRepo.putLetter as jest.Mock).mockRejectedValue( |
| 325 | + new LetterAlreadyExistsError("supplier1", "letter1"), |
| 326 | + ); |
| 327 | + |
| 328 | + const result = await createUpsertLetterHandler(mockedDeps)( |
| 329 | + evt, |
| 330 | + {} as any, |
| 331 | + {} as any, |
| 332 | + ); |
| 333 | + expect(result!.batchItemFailures).toEqual([]); |
| 334 | + }); |
| 335 | + |
304 | 336 | test("unknown supplier has metric emitted with 'unknown' supplier dimension", async () => { |
305 | 337 | const letterEvent = createSupplierStatusChangeEventWithoutSupplier(); |
306 | 338 |
|
|
0 commit comments