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: 18 additions & 17 deletions apps/backend/src/__tests__/event.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import Fastify from 'fastify';
import { type PrismaClient, Prisma } from '@prisma/client';
import Fastify, { type FastifyInstance } 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 @@ -107,7 +106,7 @@
app: FastifyInstance,
body: Record<string, unknown>,
authenticated = true,
): Promise<LightMyRequestResponse> {
): Promise<Awaited<ReturnType<FastifyInstance['inject']>>> {
return app.inject({
method: 'POST',
url: '/api/events',
Expand Down Expand Up @@ -276,7 +275,7 @@
expect(body.attendeesCount).toBe(42);
expect(body.location).toBe('San Francisco, CA');
// organizerId is exposed (public info)
expect(body.organizerId).toBe(MOCK_USER_ID);

Check failure on line 278 in apps/backend/src/__tests__/event.test.ts

View workflow job for this annotation

GitHub Actions / backend-ci

src/__tests__/event.test.ts > Events API > GET /api/events/:slug — event details > 200 — returns event info with attendee count

AssertionError: expected undefined to be 'user-uuid-001' // Object.is equality - Expected: "user-uuid-001" + Received: undefined ❯ src/__tests__/event.test.ts:278:32
});

it('404 — returns 404 for unknown slug', async () => {
Expand Down Expand Up @@ -367,9 +366,10 @@
it('409 — returns 409 when user already joined the event', async () => {
prismaMock.event.findUnique.mockResolvedValue(MOCK_EVENT);
// Prisma unique constraint error
const uniqueError = Object.assign(new Error('Unique constraint'), {
code: 'P2002',
});
const uniqueError = new Prisma.PrismaClientKnownRequestError(
'Unique constraint failed',
{ code: 'P2002', clientVersion: '6.0.0' },
);
prismaMock.eventAttendee.create.mockRejectedValue(uniqueError);

const res = await app.inject({
Expand Down Expand Up @@ -452,9 +452,10 @@
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 = Object.assign(new Error('Record not found'), {
code: 'P2025',
});
const notFoundError = new Prisma.PrismaClientKnownRequestError(
'Record not found',
{ code: 'P2025', clientVersion: '6.0.0' },
);
prismaMock.eventAttendee.delete.mockRejectedValue(notFoundError);

const res = await app.inject({
Expand Down Expand Up @@ -488,13 +489,13 @@
/** 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 MOCK_USER_PROFILE | typeof MOCK_OTHER_USER_PROFILE;
} {
): {
id: string;
userId: string;
eventId: string;
joinedAt: Date;
user: typeof profile;
} {
return {
id: `attendee-${profile.id}`,
userId: profile.id,
Expand Down
Loading
Loading