Skip to content

Skip replayed letter event#495

Merged
stevebux merged 5 commits into
mainfrom
feature/CCM-13587-Skip-Duplicate-Letter
Mar 27, 2026
Merged

Skip replayed letter event#495
stevebux merged 5 commits into
mainfrom
feature/CCM-13587-Skip-Duplicate-Letter

Conversation

@stevebux

Copy link
Copy Markdown
Contributor

Description

Context

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I am familiar with the contributing guidelines
  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming

Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

@stevebux stevebux requested a review from a team as a code owner March 26, 2026 10:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make the upsert-letter flow idempotent by treating replayed “insert” events (where the letter already exists) as non-failures, and updating tests/utilities accordingly.

Changes:

  • Introduce and propagate a LetterAlreadyExistsError from the datastore, and handle it in the upsert-letter Lambda by logging a warning instead of failing the batch item.
  • Refactor CloudWatch polling test helpers and update component tests to look for a warning (rather than an error) for duplicate/replayed events.
  • Update event schema dependency version in package-lock.json.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/helpers/aws-cloudwatch-helper.ts Refactors log polling into a generic helper and adds warning polling for upsert-letter logs.
tests/constants/api-constants.ts Alters how the test environment name is determined for AWS resource naming.
tests/component-tests/letterQueue-tests/queue-operations.spec.ts Updates duplicate insert assertion to poll for a warning log.
tests/component-tests/events-tests/event-subscription.spec.ts Updates duplicate event assertion to poll for a warning log.
package-lock.json Bumps @nhsdigital/nhs-notify-event-schemas-supplier-api version.
lambdas/upsert-letter/src/handler/upsert-handler.ts Catches LetterAlreadyExistsError and logs a warning instead of failing.
lambdas/upsert-letter/src/handler/tests/upsert-handler.test.ts Adds unit test ensuring replayed insert does not create batch failures; updates logger mock to include warn.
lambdas/upsert-letter/jest.config.ts Adds transformIgnorePatterns exception for event schema package(s).
internal/datastore/src/letter-repository.ts Throws LetterAlreadyExistsError on conditional put conflict.
internal/datastore/src/test/letter-repository.test.ts Updates expectation to assert LetterAlreadyExistsError is thrown.

Comment thread tests/helpers/aws-cloudwatch-helper.ts
Comment thread tests/component-tests/letterQueue-tests/queue-operations.spec.ts Outdated
Comment thread tests/component-tests/events-tests/event-subscription.spec.ts Outdated
@stevebux stevebux merged commit eb8f0f2 into main Mar 27, 2026
37 checks passed
@stevebux stevebux deleted the feature/CCM-13587-Skip-Duplicate-Letter branch March 27, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants