|
| 1 | +import Fastify, { type FastifyInstance } from 'fastify'; |
1 | 2 | import { describe, it, expect, beforeEach, vi } from 'vitest'; |
2 | | -import Fastify from 'fastify'; |
| 3 | + |
3 | 4 | import { cardRoutes } from '../routes/cards.js'; |
4 | 5 |
|
| 6 | +import type { PrismaClient } from '@prisma/client'; |
| 7 | + |
5 | 8 | const USER_ID = 'user-123'; |
6 | 9 | const CARD_ID = 'card-abc'; |
7 | 10 | // Must be valid UUIDs — createCardSchema and updateCardSchema use z.string().uuid() |
@@ -43,15 +46,15 @@ const mockPrisma = { |
43 | 46 |
|
44 | 47 | // Re-wire $transaction before every test so that it executes the callback |
45 | 48 | // against the same mock client, preserving existing per-operation mocks. |
46 | | -function wireTransaction() { |
| 49 | +function wireTransaction(): void { |
47 | 50 | mockPrisma.$transaction.mockImplementation( |
48 | 51 | async (callback: (tx: typeof mockPrisma) => Promise<unknown>) => callback(mockPrisma), |
49 | 52 | ); |
50 | 53 | } |
51 | 54 |
|
52 | | -async function buildApp() { |
| 55 | +async function buildApp():Promise<FastifyInstance> { |
53 | 56 | const app = Fastify({ logger: false }); |
54 | | - app.decorate('prisma', mockPrisma); |
| 57 | + app.decorate('prisma', mockPrisma as unknown as PrismaClient); |
55 | 58 | app.decorate('authenticate', async (request: any) => { |
56 | 59 | request.user = { id: USER_ID }; |
57 | 60 | }); |
|
0 commit comments