Files
gruperly/apps/backend/test/payments.test.ts
Jose Selesan 6246bf2341 refactor: migrate monorepo from pnpm to Bun runtime and workspaces
- 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
2026-09-14 10:58:56 -03:00

75 lines
1.9 KiB
TypeScript

import { beforeEach, describe, expect, it, mock, vi } from 'bun:test';
import { Hono } from 'hono';
mock.module('@/lib/prisma', () => ({
default: {
payment: {
findMany: mock(),
count: mock(),
},
},
getPrismaClient: mock(),
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 () => {
prisma.payment.findMany.mockResolvedValue([payment]);
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);
});
});