Skip to content

test(auth-server): migrate subscription route unit tests from Mocha to Jest#20197

Open
vbudhram wants to merge 1 commit intomainfrom
fxa-12619
Open

test(auth-server): migrate subscription route unit tests from Mocha to Jest#20197
vbudhram wants to merge 1 commit intomainfrom
fxa-12619

Conversation

@vbudhram
Copy link
Contributor

@vbudhram vbudhram commented Mar 16, 2026

Because

  • The auth-server is migrating from Mocha/Chai to Jest for unit tests
  • 8 subscription route test files (~7,950 lines) remained on the legacy Mocha/Chai stack

This pull request

  • Migrates 8 subscription route test files from Mocha/Chai to co-located Jest specs under lib/routes/subscriptions/
  • Converts all Chai assertions to Jest expect() equivalents and retains sinon.assert.* for spy/stub verification
  • Replaces proxyquire module stubbing with jest.mock() + jest.requireActual()
  • Adds TypeScript type annotations throughout

Migration Parity Summary

File Tests Assertions Verdict
apple.spec.ts 11/11 All preserved PASS
google.spec.ts 6/6 All preserved PASS
play-pubsub.spec.ts 6/6 All preserved PASS
mozilla.spec.ts 18/18 All preserved PASS
paypal.spec.ts 30/30 All preserved PASS
paypal-notifications.spec.ts 22/22 All preserved PASS
stripe-webhook.spec.ts 86+18 dynamic 205 preserved PASS
stripe.spec.ts 72/72 236 preserved PASS
Total 269+ ~681 PASS

Key Translation Patterns

Mocha/Chai Jest Equivalent
assert.deepEqual(a, b) expect(a).toEqual(b)
assert.equal / assert.strictEqual expect(a).toBe(b)
assert.instanceOf(x, T) expect(x).toBeInstanceOf(T)
assert.deepInclude(a, b) expect(a).toEqual(expect.objectContaining(b))
assert.fail('msg') throw new Error('msg')
assert.calledOnce(spy) (merged sinon) sinon.assert.calledOnce(spy)
proxyquire jest.mock() + jest.requireActual()

Notable Improvements Over Original

  • Fixed async describe() anti-pattern in stripe-webhook tests
  • Avoided variable shadowing (errorfetchError, deleteAccountIfUnverifiedStublocalDeleteStub)
  • Made implicit undefined values explicit in test data and sinon fakes

Issue

Closes: https://mozilla-hub.atlassian.net/browse/FXA-12619

Checklist

  • My commit is GPG signed
  • Tests pass locally (if applicable)
  • Documentation updated (if applicable)
  • RTL rendering verified (if UI changed)

How to review

This is a large PR so it is probably better to use some AI tools to help verify the changes. I have run analysis on the assertions and test comparions so to the best of my knowledge this has partiy with original. It would be good for others to also do the check.

@vbudhram vbudhram requested a review from a team as a code owner March 16, 2026 18:18
@dschom dschom self-requested a review March 18, 2026 19:19
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