Summary:
Revert recent local refactor that unified test mocks (api/auth) and tightened typings in test helpers. The refactor caused widespread test changes and failing legacy tests.
What remains done locally (working):
- New typed test helpers created under src/tests/utils/: apiMock.ts, authMock.ts, userMock.ts, renderWithProviders.tsx, factories/ (user/face-detection).
- Deprecated src/tests/utils/mocks.ts now re-exports the new mocks to act as an adapter shim for current code that imports from ./tests/utils/mocks.
Goal for the bigger refactor (follow-up PR): migrate test-suite to typed helpers safely and incrementally.
Recommended migration plan (separate PRs):
-
Add adapter shims (DONE)
- Ensure src/tests/utils/mocks.ts re-exports apiMockFactory, authMockFactory, userMockFactory, and any helper names consumers expect.
- Ensure renderWithProviders remains available at src/tests/utils/renderWithProviders.tsx and preserves backward-compatible behavior (accepts partial ApiService or factory).
-
Create a new branch: test/typed-mocks and open a WIP PR. Include only non-breaking changes (factories + mocks) and adapter shims (no behavior changes). Run CI until green.
-
Migrate suites in priority order (one suite per PR):
- High-impact suites: Me/MentorshipRequests, App tests, Navigation (they interact with Api/Auth providers).
- Component suites: Avatar, RichList, Select, etc.
For each suite migration PR:
a. Replace local test-setup wiring to use renderWithProviders and apiMockFactory()/authMockFactory() where appropriate.
b. Update any test data shapes (e.g., ensure objects have _id when production code accesses it).
c. Run tsc and tests; update snapshots only when rendering changes are intended and documented.
-
CI and linting:
- Add a CI job that runs tsc --noEmit and full test-suite before merging each migration PR.
- Add tests for the new mock factories to ensure their public API (useApi, return types) stays stable.
-
Cleanup and deprecation:
- After all suites migrated, remove the adapter shims and deprecated exports from src/tests/utils/mocks.ts and enforce importing the new mock files directly.
- Update contributor docs (src/CONTRIBUTING.md or tests/README.md) with examples: how to create Api/Auth overrides using apiMockFactory(overrides).useApi() and renderWithProviders.
Notes & Risks:
- Some legacy tests relied on static ApiService method overrides; those need to be migrated to instance-level mocks or the adapters must delegate static overrides to instance methods during migration (see MentorshipRequests test-setup).
- Snapshot updates must be intentional; recommend enabling --updateSnapshot only in the migration PR if visual/markup changes are expected.
If you want, I can:
- Finish converting src/tests/utils/mocks.ts into a full compatibility shim (expose the exact same API as the old module) and commit it.
- Create the feature branch and open the initial WIP PR with adapters and tests for the mock factories.
Please advise which next step you prefer.
Summary:
Revert recent local refactor that unified test mocks (api/auth) and tightened typings in test helpers. The refactor caused widespread test changes and failing legacy tests.
What remains done locally (working):
Goal for the bigger refactor (follow-up PR): migrate test-suite to typed helpers safely and incrementally.
Recommended migration plan (separate PRs):
Add adapter shims (DONE)
Create a new branch: test/typed-mocks and open a WIP PR. Include only non-breaking changes (factories + mocks) and adapter shims (no behavior changes). Run CI until green.
Migrate suites in priority order (one suite per PR):
For each suite migration PR:
a. Replace local test-setup wiring to use renderWithProviders and apiMockFactory()/authMockFactory() where appropriate.
b. Update any test data shapes (e.g., ensure objects have _id when production code accesses it).
c. Run tsc and tests; update snapshots only when rendering changes are intended and documented.
CI and linting:
Cleanup and deprecation:
Notes & Risks:
If you want, I can:
Please advise which next step you prefer.