Skip to content

test: integrate prisma-mock for unit tests#2857

Closed
tobiasdiez with Copilot wants to merge 3 commits into
mainfrom
copilot/setup-database-for-tests
Closed

test: integrate prisma-mock for unit tests#2857
tobiasdiez with Copilot wants to merge 3 commits into
mainfrom
copilot/setup-database-for-tests

Conversation

Copilot AI commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves setup-database-for-tests

📚 Description

Replaced vitest-mock-extended with prisma-mock for unit tests to eliminate PostgreSQL dependency and improve test execution speed.

Changes:

  • Prisma schema: Added DMMF generator to export database metadata required by prisma-mock
  • Unit tests: Migrated to prisma-mock with per-test fresh instances and in-test data seeding
    • server/journals/journal.service.spec.ts
    • server/documents/user.document.service.spec.ts
  • Documentation: Added docs/testing-with-prisma-mock.md with implementation guide

Usage pattern:

import createPrismaMock from 'prisma-mock/client'
import { Prisma, type PrismaClient } from '../database'
import * as dmmf from '../database/generated/dmmf'

beforeEach(() => {
  const mockClient = mockDeep<PrismaClient>()
  prisma = createPrismaMock(Prisma, {
    mockClient,
    datamodel: { enums: dmmf.enums, models: dmmf.models }
  })
  // Seed test data
  await prisma.journal.create({ data: testJournal })
})

Integration tests remain on PostgreSQL - they exercise complex nested queries and full-stack behavior that prisma-mock doesn't fully support.

Original prompt

Use https://github.com/demonsters/prisma-mock for setting up the database for unit and integration tests.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 13, 2025 13:40
Co-authored-by: tobiasdiez <5037600+tobiasdiez@users.noreply.github.com>
Co-authored-by: tobiasdiez <5037600+tobiasdiez@users.noreply.github.com>
Copilot AI changed the title [WIP] Set up database with prisma-mock for tests test: integrate prisma-mock for unit tests Nov 13, 2025
Copilot AI requested a review from tobiasdiez November 13, 2025 13:59
@tobiasdiez

Copy link
Copy Markdown
Member

#2486 makes more sense

@tobiasdiez tobiasdiez closed this Mar 10, 2026
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