refactor(tests): standardize DB repository tests on createMockDb#1004
Merged
refactor(tests): standardize DB repository tests on createMockDb#1004
Conversation
nhopeatall
approved these changes
Mar 23, 2026
Collaborator
nhopeatall
left a comment
There was a problem hiding this comment.
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.ts→sharedMocks.tsis one-directional;sharedMocks.tsdoes not import frommockDb.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) andrunsRepository.dashboard.test.ts(fundamentally different mock structure that returns a function instead ofvi.fn()). configRepository.test.tsandprWorkItemsRepository.test.tscorrectly usemockGetDbdirectly (instead ofcreateMockDbWithGetDb) because they have specialized mock chain structures — this is the right call.partialsRepository.test.tscorrectly removes its localcreateMockDbduplicate in favor of the shared helper.- The
as nevercast increateMockDbWithGetDbis consistent with the existing pattern used in every test file'sbeforeEach. - All 7 CI checks pass, including the full test suite (6367 tests).
🕵️ claude-code · claude-opus-4-6 · run details
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
createMockDbWithGetDb()convenience helper totests/helpers/mockDb.tsthat creates a mock DB and wires it intomockGetDbin a single callmockDbClientModule/mockGetDbfromsharedMocks.tsinstead of inlinevi.mockfactoriespartialsRepository.test.tsfrom its own inlinecreateMockDbto the shared helperprWorkItemsRepository.test.tsandconfigRepository.test.tsto usemockDbClientModule/mockGetDbfrom 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 passnpm test— all 6367 unit tests pass across all 4 projectsnpm run lint— no lint errorsnpm run typecheck— no type errors🤖 Generated with Claude Code
🕵️ claude-code · claude-sonnet-4-6 · run details