- Replace Bun with pnpm 9 + Turborepo + tsx; apps/api renamed to apps/backend - Split backend into http/, modules/, lib/ layers mirroring tai-specguard - Add use-case + Result pattern, Problem Details RFC 7807, basePath /api/v1 - Mount Better Auth at /api/v1/auth, keep session-auth whitelist - Split Prisma schema into prisma/models/*, generate into generated/ - Rework packages/shared into lib/ + schemas/ with pagination DTOs - Implement health, groups, students, payments, waitlist modules - Add vitest suite with prisma mocks (21 tests), biome lint - Point web client to /api/v1/auth and /api/v1/groups/from-organization
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { Hono } from 'hono';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
vi.mock('@/lib/prisma', () => ({
|
|
default: {
|
|
waitlistEntry: {
|
|
findMany: vi.fn(),
|
|
count: vi.fn(),
|
|
},
|
|
},
|
|
getPrismaClient: vi.fn(),
|
|
UnitOfWork: class {},
|
|
}));
|
|
|
|
import prisma from '@/lib/prisma';
|
|
import { waitlistRoutes } from '@/modules/waitlist';
|
|
|
|
const app = new Hono();
|
|
app.route('/waitlist', waitlistRoutes);
|
|
|
|
const entry = {
|
|
id: 'waitlist-1',
|
|
email: 'caro@example.com',
|
|
name: 'Caro',
|
|
status: 'pending',
|
|
createdAt: new Date('2026-08-01T10:00:00.000Z'),
|
|
updatedAt: new Date('2026-08-01T10:00:00.000Z'),
|
|
};
|
|
|
|
describe('waitlist routes', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('lists waitlist entries with pagination', async () => {
|
|
vi.mocked(prisma.waitlistEntry.findMany).mockResolvedValue([entry]);
|
|
vi.mocked(prisma.waitlistEntry.count).mockResolvedValue(1);
|
|
|
|
const res = await app.request('/waitlist');
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(await res.json()).toEqual({
|
|
data: [
|
|
{
|
|
...entry,
|
|
createdAt: entry.createdAt.toISOString(),
|
|
updatedAt: entry.updatedAt.toISOString(),
|
|
},
|
|
],
|
|
pagination: { page: 1, pageSize: 10, total: 1, totalPages: 1 },
|
|
});
|
|
});
|
|
|
|
it('rejects invalid pagination query parameters', async () => {
|
|
const res = await app.request('/waitlist?page=0');
|
|
|
|
expect(res.status).toBe(400);
|
|
expect(await res.json()).toMatchObject({ status: 400, title: 'Bad Request' });
|
|
});
|
|
}); |