Skip to content

test: consolidate worker/api db mock into shared test-fixtures#196

Open
bbornino wants to merge 1 commit into
playfulprogramming:mainfrom
bbornino:feature/193-consolidate-test-fixtures
Open

test: consolidate worker/api db mock into shared test-fixtures#196
bbornino wants to merge 1 commit into
playfulprogramming:mainfrom
bbornino:feature/193-consolidate-test-fixtures

Conversation

@bbornino

@bbornino bbornino commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #193.

The mocked drizzle db and its faked table/column definitions were duplicated between apps/worker/test-utils/setup.ts and apps/api/test-utils/setup.ts, with the two copies drifting from each other over time (different tables stubbed, different columns per shared table).

  • Added createDbMock() to packages/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 a db object 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.*).
  • Both apps now call vi.mock("@playfulprogramming/db", () => createDbMock()) from their own setup.ts instead of hand-rolling the mock. The vi.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 via node_modules — but the actual mock data/logic is now defined once and shared.
  • Preserved the Map-based dedup behavior from worker's original mock (repeated db.insert(table)/db.delete(table) calls for the same table return the same chainable mock instance) verbatim — getEmbedDataFromGist.test.ts exercises this directly and still passes.

Test plan

  • pnpm test:unit passes for all NX projects (93 tests across api/worker, plus lint/knip/publint/sherif)
  • pnpm run build:all passes (tsc --noEmit clean for both api and worker)
  • pnpm prettier --check clean on all changed files

Summary by CodeRabbit

  • Tests
    • Standardized database mocking across API and worker test suites.
    • Added reusable mock behavior for common database operations and queries.
    • Improved consistency and maintainability of test setup fixtures.

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.
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e24c8126-bd36-46a4-8648-2b8b5e9642be

📥 Commits

Reviewing files that changed from the base of the PR and between 8188426 and d28f6b6.

📒 Files selected for processing (4)
  • apps/api/test-utils/setup.ts
  • apps/worker/test-utils/setup.ts
  • packages/test-fixtures/src/db-mock.ts
  • packages/test-fixtures/src/index.ts

📝 Walkthrough

Walkthrough

A reusable createDbMock() factory is added to test-fixtures, exported publicly, and used by API and worker Vitest setup modules instead of inline database mock definitions.

Changes

Shared database mock

Layer / File(s) Summary
Database mock factory and export
packages/test-fixtures/src/db-mock.ts, packages/test-fixtures/src/index.ts
Adds createDbMock() with database operation stubs, query namespaces, and entity fixtures, then re-exports it from the package.
Application test setup integration
apps/api/test-utils/setup.ts, apps/worker/test-utils/setup.ts
API and worker test setups import createDbMock() and use it to mock @playfulprogramming/db.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: consolidating worker and API database mocks into shared test fixtures.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Consolidate drizzle/db test utilities in test-fixtures

1 participant