Skip to content

Commit f8088ed

Browse files
authored
Revert "fix(event): remove all any casts — typed authenticate, user.id, and…" (#648)
This reverts commit 01873b8.
1 parent 01873b8 commit f8088ed

2 files changed

Lines changed: 211 additions & 214 deletions

File tree

apps/backend/src/__tests__/event.test.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { type PrismaClient, Prisma } from '@prisma/client';
2-
import Fastify, { type FastifyInstance } from 'fastify';
1+
import Fastify from 'fastify';
32
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
43

54
import { eventRoutes } from '../routes/event';
65

6+
import type { PrismaClient } from '@prisma/client';
7+
import type { FastifyInstance,LightMyRequestResponse } from 'fastify';
78

89
// ─── Shared mock data ────────────────────────────────────────────────────────
910

@@ -106,7 +107,7 @@ async function createEvent(
106107
app: FastifyInstance,
107108
body: Record<string, unknown>,
108109
authenticated = true,
109-
): Promise<Awaited<ReturnType<FastifyInstance['inject']>>> {
110+
): Promise<LightMyRequestResponse> {
110111
return app.inject({
111112
method: 'POST',
112113
url: '/api/events',
@@ -366,10 +367,9 @@ describe('Events API', () => {
366367
it('409 — returns 409 when user already joined the event', async () => {
367368
prismaMock.event.findUnique.mockResolvedValue(MOCK_EVENT);
368369
// 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+
});
373373
prismaMock.eventAttendee.create.mockRejectedValue(uniqueError);
374374

375375
const res = await app.inject({
@@ -452,10 +452,9 @@ describe('Events API', () => {
452452
it('404 — returns 404 when user was never an attendee (P2025)', async () => {
453453
prismaMock.event.findUnique.mockResolvedValue(MOCK_EVENT);
454454
// 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+
});
459458
prismaMock.eventAttendee.delete.mockRejectedValue(notFoundError);
460459

461460
const res = await app.inject({
@@ -489,13 +488,13 @@ describe('Events API', () => {
489488
/** Builds a raw EventAttendee row as Prisma returns it (with nested user) */
490489
function makeAttendeeRow(
491490
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+
} {
499498
return {
500499
id: `attendee-${profile.id}`,
501500
userId: profile.id,

0 commit comments

Comments
 (0)