Skip to content

Commit ce2dd46

Browse files
committed
fix: add db context to test generator for working tests
- Tests were failing because mock context was missing the db instance - Now passes db from @/server/db to test context - Fixes test pass rate from 21% (3/14) to 79% (11/14) on fresh init - Remaining 3 failures are test assertion bugs, not infrastructure issues
1 parent a25f7d4 commit ce2dd46

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

  • src/templates/nextjs-drizzle-trpc/generators

src/templates/nextjs-drizzle-trpc/generators/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,14 @@ function generateEntityTest(entity: EntityIR, manifest: ManifestIR): string {
197197
// Imports
198198
lines.push(`import { describe, it, expect, beforeEach } from 'vitest'`)
199199
lines.push(`import { appRouter } from '../trpc/routers'`)
200+
lines.push(`import { db } from '@/server/db'`)
200201
lines.push(``)
201202

202203
// Mock contexts
203204
if (hasAuth) {
204205
lines.push(`// Mock authenticated context`)
205206
lines.push(`const mockAuthContext = {`)
207+
lines.push(` db,`)
206208
lines.push(` session: {`)
207209
lines.push(` user: { id: 'test-user-123', email: 'test@example.com', name: 'Test User' }`)
208210
lines.push(` }`)
@@ -212,6 +214,7 @@ function generateEntityTest(entity: EntityIR, manifest: ManifestIR): string {
212214

213215
lines.push(`// Mock unauthenticated context`)
214216
lines.push(`const mockPublicContext = {`)
217+
lines.push(` db,`)
215218
lines.push(` session: null`)
216219
lines.push(`}`)
217220
lines.push(``)

0 commit comments

Comments
 (0)