|
1 | | -import { type PrismaClient, Prisma } from '@prisma/client'; |
2 | | -import Fastify, { type FastifyInstance } from 'fastify'; |
| 1 | +import Fastify from 'fastify'; |
3 | 2 | import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; |
4 | 3 |
|
5 | 4 | import { eventRoutes } from '../routes/event'; |
6 | 5 |
|
| 6 | +import type { PrismaClient } from '@prisma/client'; |
| 7 | +import type { FastifyInstance,LightMyRequestResponse } from 'fastify'; |
7 | 8 |
|
8 | 9 | // ─── Shared mock data ──────────────────────────────────────────────────────── |
9 | 10 |
|
@@ -106,7 +107,7 @@ async function createEvent( |
106 | 107 | app: FastifyInstance, |
107 | 108 | body: Record<string, unknown>, |
108 | 109 | authenticated = true, |
109 | | -): Promise<Awaited<ReturnType<FastifyInstance['inject']>>> { |
| 110 | +): Promise<LightMyRequestResponse> { |
110 | 111 | return app.inject({ |
111 | 112 | method: 'POST', |
112 | 113 | url: '/api/events', |
@@ -366,10 +367,9 @@ describe('Events API', () => { |
366 | 367 | it('409 — returns 409 when user already joined the event', async () => { |
367 | 368 | prismaMock.event.findUnique.mockResolvedValue(MOCK_EVENT); |
368 | 369 | // Prisma unique constraint error |
369 | | - const uniqueError = new Prisma.PrismaClientKnownRequestError( |
370 | | - 'Unique constraint failed', |
371 | | - { code: 'P2002', clientVersion: '6.0.0' }, |
372 | | - ); |
| 370 | + const uniqueError = Object.assign(new Error('Unique constraint'), { |
| 371 | + code: 'P2002', |
| 372 | + }); |
373 | 373 | prismaMock.eventAttendee.create.mockRejectedValue(uniqueError); |
374 | 374 |
|
375 | 375 | const res = await app.inject({ |
@@ -452,10 +452,9 @@ describe('Events API', () => { |
452 | 452 | it('404 — returns 404 when user was never an attendee (P2025)', async () => { |
453 | 453 | prismaMock.event.findUnique.mockResolvedValue(MOCK_EVENT); |
454 | 454 | // Prisma record-not-found error |
455 | | - const notFoundError = new Prisma.PrismaClientKnownRequestError( |
456 | | - 'Record not found', |
457 | | - { code: 'P2025', clientVersion: '6.0.0' }, |
458 | | - ); |
| 455 | + const notFoundError = Object.assign(new Error('Record not found'), { |
| 456 | + code: 'P2025', |
| 457 | + }); |
459 | 458 | prismaMock.eventAttendee.delete.mockRejectedValue(notFoundError); |
460 | 459 |
|
461 | 460 | const res = await app.inject({ |
@@ -489,13 +488,13 @@ describe('Events API', () => { |
489 | 488 | /** Builds a raw EventAttendee row as Prisma returns it (with nested user) */ |
490 | 489 | function makeAttendeeRow( |
491 | 490 | profile: typeof MOCK_USER_PROFILE | typeof MOCK_OTHER_USER_PROFILE, |
492 | | - ): { |
493 | | - id: string; |
494 | | - userId: string; |
495 | | - eventId: string; |
496 | | - joinedAt: Date; |
497 | | - user: typeof profile; |
498 | | - } { |
| 491 | + ) : { |
| 492 | + id: string; |
| 493 | + userId: string; |
| 494 | + eventId: string; |
| 495 | + joinedAt: Date; |
| 496 | + user: typeof MOCK_USER_PROFILE | typeof MOCK_OTHER_USER_PROFILE; |
| 497 | + } { |
499 | 498 | return { |
500 | 499 | id: `attendee-${profile.id}`, |
501 | 500 | userId: profile.id, |
|
0 commit comments