- 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
75 lines
2.0 KiB
TypeScript
75 lines
2.0 KiB
TypeScript
import { Hono } from 'hono';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
vi.mock('@/lib/prisma', () => ({
|
|
default: {
|
|
payment: {
|
|
findMany: vi.fn(),
|
|
count: vi.fn(),
|
|
},
|
|
},
|
|
getPrismaClient: vi.fn(),
|
|
UnitOfWork: class {},
|
|
}));
|
|
|
|
import prisma from '@/lib/prisma';
|
|
import { paymentsRoutes } from '@/modules/payments';
|
|
|
|
const app = new Hono();
|
|
app.route('/payments', paymentsRoutes);
|
|
|
|
const payment = {
|
|
id: 'payment-1',
|
|
groupId: 'group-1',
|
|
studentId: 'student-1',
|
|
amount: { toString: () => '150.50' } as { toString(): string },
|
|
currency: 'MXN',
|
|
status: 'pending',
|
|
dueDate: new Date('2026-09-01T10:00:00.000Z'),
|
|
paidAt: null,
|
|
createdAt: new Date('2026-08-01T10:00:00.000Z'),
|
|
updatedAt: new Date('2026-08-01T10:00:00.000Z'),
|
|
};
|
|
|
|
describe('payments routes', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('lists payments with pagination and converts Decimal amounts', async () => {
|
|
vi.mocked(prisma.payment.findMany).mockResolvedValue([payment]);
|
|
vi.mocked(prisma.payment.count).mockResolvedValue(1);
|
|
|
|
const res = await app.request('/payments');
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(await res.json()).toEqual({
|
|
data: [
|
|
{
|
|
id: 'payment-1',
|
|
groupId: 'group-1',
|
|
studentId: 'student-1',
|
|
amount: 150.5,
|
|
currency: 'MXN',
|
|
status: 'pending',
|
|
dueDate: payment.dueDate.toISOString(),
|
|
paidAt: null,
|
|
createdAt: payment.createdAt.toISOString(),
|
|
updatedAt: payment.updatedAt.toISOString(),
|
|
},
|
|
],
|
|
pagination: { page: 1, pageSize: 10, total: 1, totalPages: 1 },
|
|
});
|
|
expect(prisma.payment.findMany).toHaveBeenCalledWith({
|
|
skip: 0,
|
|
take: 10,
|
|
orderBy: { createdAt: 'desc' },
|
|
});
|
|
});
|
|
|
|
it('rejects invalid pagination query parameters', async () => {
|
|
const res = await app.request('/payments?pageSize=101');
|
|
|
|
expect(res.status).toBe(400);
|
|
});
|
|
}); |