Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions apps/backend/src/__tests__/event.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { type PrismaClient, Prisma } from '@prisma/client';
import Fastify, { type FastifyInstance } from 'fastify';
import Fastify from 'fastify';
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';

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

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

// ─── Shared mock data ────────────────────────────────────────────────────────

Expand Down Expand Up @@ -106,7 +107,7 @@ async function createEvent(
app: FastifyInstance,
body: Record<string, unknown>,
authenticated = true,
): Promise<Awaited<ReturnType<FastifyInstance['inject']>>> {
): Promise<LightMyRequestResponse> {
return app.inject({
method: 'POST',
url: '/api/events',
Expand Down Expand Up @@ -366,10 +367,9 @@ describe('Events API', () => {
it('409 — returns 409 when user already joined the event', async () => {
prismaMock.event.findUnique.mockResolvedValue(MOCK_EVENT);
// Prisma unique constraint error
const uniqueError = new Prisma.PrismaClientKnownRequestError(
'Unique constraint failed',
{ code: 'P2002', clientVersion: '6.0.0' },
);
const uniqueError = Object.assign(new Error('Unique constraint'), {
code: 'P2002',
});
prismaMock.eventAttendee.create.mockRejectedValue(uniqueError);

const res = await app.inject({
Expand Down Expand Up @@ -452,10 +452,9 @@ describe('Events API', () => {
it('404 — returns 404 when user was never an attendee (P2025)', async () => {
prismaMock.event.findUnique.mockResolvedValue(MOCK_EVENT);
// Prisma record-not-found error
const notFoundError = new Prisma.PrismaClientKnownRequestError(
'Record not found',
{ code: 'P2025', clientVersion: '6.0.0' },
);
const notFoundError = Object.assign(new Error('Record not found'), {
code: 'P2025',
});
prismaMock.eventAttendee.delete.mockRejectedValue(notFoundError);

const res = await app.inject({
Expand Down Expand Up @@ -489,13 +488,13 @@ describe('Events API', () => {
/** Builds a raw EventAttendee row as Prisma returns it (with nested user) */
function makeAttendeeRow(
profile: typeof MOCK_USER_PROFILE | typeof MOCK_OTHER_USER_PROFILE,
): {
id: string;
userId: string;
eventId: string;
joinedAt: Date;
user: typeof profile;
} {
) : {
id: string;
userId: string;
eventId: string;
joinedAt: Date;
user: typeof MOCK_USER_PROFILE | typeof MOCK_OTHER_USER_PROFILE;
} {
return {
id: `attendee-${profile.id}`,
userId: profile.id,
Expand Down
Loading