Conversation
84ce3c0 to
72f8373
Compare
| // ./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'); |
There was a problem hiding this comment.
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.
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).
There was a problem hiding this comment.
Pull request overview
Refactors fxa-auth-server tests away from the legacy test/mocks.js factories toward typed Jest mocks (@golevelup/ts-jest), adds a small fixture for DI-installed FxaMailer, and fixes a circular dependency in route validators.
Changes:
- Added
@golevelup/ts-jestand migrated many specs tocreateMock<T>()forAuthLogger/StatsDand related collaborators. - Introduced
test/fixtures/(README +fxa-mailer.ts) to install/uninstall a typedFxaMailermock in the TypeDIContainer, and removed the oldmockStatsd/mockFxaMailerslices fromtest/mocks.js. - Updated
AuthLogger’s TypeScript interface and adjustedvalidators.jsto importReasonForDeletionfrom@fxa/shared/cloud-tasksto avoid a circular dependency.
Reviewed changes
Copilot reviewed 72 out of 73 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Adds lock entry for @golevelup/ts-jest. |
| packages/fxa-auth-server/package.json | Adds @golevelup/ts-jest as a devDependency. |
| packages/fxa-auth-server/test/mocks.js | Removes mockStatsd + mockFxaMailer exports/implementation. |
| packages/fxa-auth-server/test/fixtures/README.md | Documents new typed test-fixture conventions and when to add fixtures. |
| packages/fxa-auth-server/test/fixtures/fxa-mailer.ts | Adds install/uninstall helpers for a Container-registered FxaMailer mock. |
| packages/fxa-auth-server/lib/types.ts | Expands AuthLogger interface to include missing methods used in production. |
| packages/fxa-auth-server/lib/routes/validators.js | Avoids circular dependency by importing ReasonForDeletion from the shared package. |
| packages/fxa-auth-server/lib/tokens/token.spec.ts | Migrates mockLog() usage to createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/subscription-account-reminders.in.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/server.in.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/senders/index.spec.ts | Migrates nullLog to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/utils/signup.spec.ts | Uses typed AuthLogger mock and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/routes/utils/signin.spec.ts | Uses typed AuthLogger mock and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/routes/utils/oauth.spec.ts | Installs typed FxaMailer fixture (Container) for tests. |
| packages/fxa-auth-server/lib/routes/utils/clients.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/unblock-codes.spec.ts | Installs typed FxaMailer fixture and migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/totp.spec.ts | Migrates logger/statsd mocks to typed createMock<AuthLogger/StatsD>() and installs typed FxaMailer. |
| packages/fxa-auth-server/lib/routes/subscriptions/support.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/subscriptions/stripe.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/subscriptions/stripe-webhooks.spec.ts | Migrates logger mock to typed createMock<AuthLogger>() and tidies some spy formatting. |
| packages/fxa-auth-server/lib/routes/subscriptions/play-pubsub.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/subscriptions/paypal-notifications.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/subscriptions/mozilla.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/subscriptions/google.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/subscriptions/apple.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/session.spec.ts | Migrates logger/statsd mocks to typed mocks and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/routes/security-events.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/recovery-phone.spec.ts | Migrates logger/statsd mocks to typed mocks and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/routes/recovery-key.spec.ts | Migrates logger mock to typed createMock<AuthLogger>() and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/routes/recovery-codes.spec.ts | Migrates logger mock to typed createMock<AuthLogger>() and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/routes/passwordless.spec.ts | Migrates logger/statsd mocks to typed mocks and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/routes/password.spec.ts | Migrates logger/statsd mocks to typed mocks and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/routes/oauth/index.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/newsletters.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/mfa.spec.ts | Migrates logger/statsd mocks to typed mocks and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/routes/linked-accounts.spec.ts | Installs typed FxaMailer fixture and migrates logger/statsd mocks to typed mocks. |
| packages/fxa-auth-server/lib/routes/ip-profiling.spec.ts | Migrates logger/statsd mocks to typed mocks and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/routes/geo-location.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/emails.spec.ts | Migrates logger/statsd mocks to typed mocks and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/routes/devices-and-sessions.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/cms.spec.ts | Migrates logger/statsd mocks to typed mocks. |
| packages/fxa-auth-server/lib/routes/cloud-tasks.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/attached-clients.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/routes/account.spec.ts | Migrates logger/statsd mocks to typed mocks and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/redis.in.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/pushbox/index.spec.ts | Migrates logger/statsd mocks to typed mocks. |
| packages/fxa-auth-server/lib/push.spec.ts | Migrates logger/statsd mocks to typed mocks. |
| packages/fxa-auth-server/lib/profile/updates.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/payments/subscription-reminders.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/payments/stripe.spec.ts | Migrates logger/statsd mocks to typed mocks. |
| packages/fxa-auth-server/lib/payments/paypal/processor.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/payments/paypal/helper.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/payments/iap/iap-config.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/payments/iap/google-play/user-manager.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/payments/iap/google-play/purchase-manager.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/payments/iap/google-play/play-billing.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/payments/iap/apple-app-store/purchase-manager.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/payments/iap/apple-app-store/apple-iap.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/payments/iap/apple-app-store/app-store-helper.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/payments/capability.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/metrics/context.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/metrics/amplitude.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/inactive-accounts/index.spec.ts | Migrates logger/statsd mocks to typed mocks and installs typed FxaMailer fixture. |
| packages/fxa-auth-server/lib/google-maps-services.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/email/utils/helpers.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/email/notifications.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/email/delivery.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/email/delivery-delay.spec.ts | Migrates logger/statsd mocks to typed mocks. |
| packages/fxa-auth-server/lib/email/bounces.spec.ts | Migrates logger/statsd mocks to typed mocks. |
| packages/fxa-auth-server/lib/devices.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/db.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/cad-reminders.in.spec.ts | Migrates logger mock to typed createMock<AuthLogger>(). |
| packages/fxa-auth-server/lib/account-delete.spec.ts | Migrates logger/statsd mocks to typed mocks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const mailer = createMock<FxaMailer>({ | ||
| canSend: () => true, | ||
| ...overrides, | ||
| }); | ||
| Container.set(FxaMailer, mailer); |
There was a problem hiding this comment.
canSend will hopefully go away soon, and we should always be testing the fxaMailer route over falling back to the 'old' mailer style, so there's really no need to override this on the mock
Because:
This commit:
Issue that this pull request solves
Closes: (issue number)
Checklist
Put an
xin the boxes that applyHow to review (Optional)
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.