test: consolidate worker/api db mock into shared test-fixtures#196
Open
bbornino wants to merge 1 commit into
Open
test: consolidate worker/api db mock into shared test-fixtures#196bbornino wants to merge 1 commit into
bbornino wants to merge 1 commit into
Conversation
The mocked drizzle db and its faked table/column definitions were
duplicated (and drifting) between apps/worker and apps/api test setup.
Move it into a shared createDbMock() factory in test-fixtures as the
superset of both, so both apps' vi.mock("@playfulprogramming/db", ...)
calls source the same mock instead of hand-rolling their own.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughA reusable ChangesShared database mock
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
Closes #193.
The mocked drizzle
dband its faked table/column definitions were duplicated betweenapps/worker/test-utils/setup.tsandapps/api/test-utils/setup.ts, with the two copies drifting from each other over time (different tables stubbed, different columns per shared table).createDbMock()topackages/test-fixtures/src/db-mock.ts— a single factory that's the superset merge of both apps' previous mocks (union of all stubbed tables/columns, and adbobject exposing both the core query-builder shape worker's tests use —insert/delete/select/transaction— and the relational-query shape api's tests use —query.*).vi.mock("@playfulprogramming/db", () => createDbMock())from their ownsetup.tsinstead of hand-rolling the mock. Thevi.mock()call itself has to stay local to each app — Vitest's mock-hoisting only intercepts calls made from a file inside that app's own transformed source tree, not one made from inside a workspace package resolved vianode_modules— but the actual mock data/logic is now defined once and shared.Map-based dedup behavior from worker's original mock (repeateddb.insert(table)/db.delete(table)calls for the same table return the same chainable mock instance) verbatim —getEmbedDataFromGist.test.tsexercises this directly and still passes.Test plan
pnpm test:unitpasses for all NX projects (93 tests acrossapi/worker, plus lint/knip/publint/sherif)pnpm run build:allpasses (tsc --noEmitclean for bothapiandworker)pnpm prettier --checkclean on all changed filesSummary by CodeRabbit