- root: bun workspaces via package.json, packageManager bun@1.4.0, scripts use bun --filter - backend: Bun.serve, bun test (vitest removed), bun --watch dev script, tsconfig types bun - tests: migrate 6 test files from vitest to bun:test (mock.module) - validate: replace @hono/zod-validator with hono validator + zod safeParse (fixes TS2589) - lockfile: bunfig.toml saveTextLockfile, regenerated bun.lock (text) for turbo - docs: AGENTS.md, README.md, stack.md updated to Bun stack
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { beforeEach, describe, expect, it, mock, vi } from 'bun:test';
|
|
import { Hono } from 'hono';
|
|
|
|
mock.module('@/lib/prisma', () => ({
|
|
default: {
|
|
waitlistEntry: {
|
|
findMany: mock(),
|
|
count: mock(),
|
|
},
|
|
},
|
|
getPrismaClient: mock(),
|
|
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 () => {
|
|
prisma.waitlistEntry.findMany.mockResolvedValue([entry]);
|
|
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' });
|
|
});
|
|
}); |