Skip to content

refactor(tests): standardize DB repository tests on createMockDb#1004

Merged
aaight merged 1 commit intodevfrom
feature/standardize-db-repo-tests-on-create-mock-db
Mar 23, 2026
Merged

refactor(tests): standardize DB repository tests on createMockDb#1004
aaight merged 1 commit intodevfrom
feature/standardize-db-repo-tests-on-create-mock-db

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Mar 23, 2026

Summary

  • Adds createMockDbWithGetDb() convenience helper to tests/helpers/mockDb.ts that creates a mock DB and wires it into mockGetDb in a single call
  • Standardizes all 13 DB repository test files to use mockDbClientModule/mockGetDb from sharedMocks.ts instead of inline vi.mock factories
  • Migrates partialsRepository.test.ts from its own inline createMockDb to the shared helper
  • Migrates prWorkItemsRepository.test.ts and configRepository.test.ts to use mockDbClientModule/mockGetDb from sharedMocks (keeping their specialized chain structures)

Card: https://trello.com/c/pBBLJoMZ/522-as-a-developer-i-want-db-repository-tests-standardized-on-createmockdb-so-that-mock-setup-is-consistent-and-minimal

Test plan

  • npx vitest run --project unit-core tests/unit/db/repositories/ — 241 tests pass
  • npm test — all 6367 unit tests pass across all 4 projects
  • npm run lint — no lint errors
  • npm run typecheck — no type errors

🤖 Generated with Claude Code

🕵️ claude-code · claude-sonnet-4-6 · run details

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

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

Summary

LGTM — Clean, mechanical refactoring that successfully standardizes DB mock setup across 12 repository test files. All CI checks pass.

The change introduces createMockDbWithGetDb() as a thin convenience wrapper in mockDb.ts that combines createMockDb() + mockGetDb.mockReturnValue() into a single call, then migrates all applicable test files to use it alongside the shared mockDbClientModule from sharedMocks.ts.

What I verified:

  • No circular dependency: mockDb.tssharedMocks.ts is one-directional; sharedMocks.ts does not import from mockDb.ts.
  • Correct coverage: 12 of 14 test files in tests/unit/db/repositories/ are migrated. The two excluded files are appropriate: configMapper.test.ts (pure mapper, no DB mock) and runsRepository.dashboard.test.ts (fundamentally different mock structure that returns a function instead of vi.fn()).
  • configRepository.test.ts and prWorkItemsRepository.test.ts correctly use mockGetDb directly (instead of createMockDbWithGetDb) because they have specialized mock chain structures — this is the right call.
  • partialsRepository.test.ts correctly removes its local createMockDb duplicate in favor of the shared helper.
  • The as never cast in createMockDbWithGetDb is consistent with the existing pattern used in every test file's beforeEach.
  • All 7 CI checks pass, including the full test suite (6367 tests).

🕵️ claude-code · claude-opus-4-6 · run details

@aaight aaight merged commit 9b2b057 into dev Mar 23, 2026
9 checks passed
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.

2 participants