Skip to content

[wip] test(auth): migrate log/statsd/fxaMailer mocks to typed Jest fixtures#20705

Draft
nshirley wants to merge 1 commit into
mainfrom
FXA-13708
Draft

[wip] test(auth): migrate log/statsd/fxaMailer mocks to typed Jest fixtures#20705
nshirley wants to merge 1 commit into
mainfrom
FXA-13708

Conversation

@nshirley

@nshirley nshirley commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Because:

  • test/mocks.js is an untyped ~1.2k-line monolith whose shared factories obscure test intent and cannot track production-type drift (FXA-13708).

This commit:

  • Replaces mocks.mockLog()/mockStatsd() with inline createMock() and createMock() (@golevelup/ts-jest) across ~60 specs, plus any hand-rolled statsd stubs.
  • Adds test/fixtures/ (README + fxa-mailer.ts with installMockFxaMailer/ uninstallMockFxaMailer) and migrates the 16 route specs off mocks.mockFxaMailer(), with Container teardown.
  • Completes the AuthLogger interface (flowEvent, activityEvent, amplitudeEvent, summary) so the typed log mock matches the real logger.
  • Removes the now-dead mockStatsd and mockFxaMailer slices from test/mocks.js (mockLog stays; mockRequest still consumes it internally).
  • Adds @golevelup/ts-jest as a devDependency. Legacy mocks.mockMailer() and its negative "not called" guards are left intact; no file tests the legacy mailer sending path.

Issue that this pull request solves

Closes: (issue number)

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).
  • I have manually reviewed all AI generated code.

How to review (Optional)

  • Key files/areas to focus on:
  • Suggested review order:
  • Risky or complex parts:

Screenshots (Optional)

Please attach the screenshots of the changes made in case of change in user interface.

Other information (Optional)

Any other information that is important to this pull request.

@nshirley nshirley force-pushed the FXA-13708 branch 2 times, most recently from 4b77dbf to 84ce3c0 Compare June 8, 2026 14:57
Because:
- test/mocks.js's untyped shared factories obscure intent and miss type
  drift (FXA-13708).

This commit:
- Swaps mocks.mockLog()/mockStatsd() for inline createMock<T>() and adds
  test/fixtures/fxa-mailer.ts (installMockFxaMailer) across ~60 specs.
- Completes the AuthLogger interface and removes the now-dead mockStatsd and
  mockFxaMailer slices from test/mocks.js.
- Breaks a validators <-> cloud-tasks circular dependency the migration
  exposed (validators now imports ReasonForDeletion from @fxa/shared/cloud-tasks).
// ./cloud-tasks route module, which re-exports it: ./cloud-tasks imports this
// validators module, so requiring it here created a circular dependency that
// left ReasonForDeletion undefined depending on module load order.
const { ReasonForDeletion } = require('@fxa/shared/cloud-tasks');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll remove the comment here, but left it for the time being to remind myself.

I suspect, as more things are ripped out of the shared mocks.ts, we'll see this more. There was a hidden circular dependency. The import here was a re-export from the source, but the mocks.ts also imported all of the relevant modules in order, thus loading them into the dependency cache and hiding this problem.

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.

1 participant