Skip to content

Revert test-mock refactor and stabilize tests #1012

@moshfeu

Description

@moshfeu

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):

  1. 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).
  2. 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.

  3. 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.
  4. 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.
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions