- Added payment presentation logic to display payment status and due dates. - Introduced AttendeeNotesSection and AttendeePaymentsSection components for managing notes and payments. - Implemented forms for editing contact information and notes with validation. - Updated API to support attendee updates and added corresponding tests. - Improved attendance summary logic to reflect all visible sessions. - Enhanced UI with loading states and error handling for better user experience.
124 lines
3.4 KiB
TypeScript
124 lines
3.4 KiB
TypeScript
import { beforeEach, describe, expect, it, mock, vi } from 'bun:test';
|
|
import { Hono } from 'hono';
|
|
|
|
const db = {
|
|
group: {
|
|
findUnique: mock(),
|
|
},
|
|
attendee: {
|
|
findFirst: mock(),
|
|
},
|
|
};
|
|
|
|
mock.module('@/lib/prisma', () => ({
|
|
default: db,
|
|
getPrismaClient: mock(),
|
|
UnitOfWork: class {},
|
|
}));
|
|
|
|
import prisma from '@/lib/prisma';
|
|
import getAttendeeRoute from '@/modules/attendees/features/get-by-id/route';
|
|
|
|
const userId = 'user-1';
|
|
|
|
function makeApp(userValue: unknown) {
|
|
const app = new Hono();
|
|
app.use('*', async (c, next) => {
|
|
c.set('user', userValue as never);
|
|
await next();
|
|
});
|
|
app.route('/groups', getAttendeeRoute);
|
|
return app;
|
|
}
|
|
|
|
function makeGroup(overrides: Record<string, unknown> = {}) {
|
|
return { id: 'group-1', name: 'Funcional', createdById: userId, members: [], ...overrides };
|
|
}
|
|
|
|
const attendee = {
|
|
id: 'a-1',
|
|
groupId: 'group-1',
|
|
fullName: 'Ana Pérez',
|
|
email: 'ana@example.com',
|
|
phone: '5512345678',
|
|
guardianName: 'Luis Pérez',
|
|
guardianPhone: null,
|
|
notes: null,
|
|
notifyToken: 'token-1',
|
|
createdAt: new Date('2026-08-01T10:00:00.000Z'),
|
|
updatedAt: new Date('2026-08-01T10:00:00.000Z'),
|
|
payments: [
|
|
{ status: 'PENDING', dueDate: new Date('2026-10-10T00:00:00.000Z') },
|
|
],
|
|
};
|
|
|
|
describe('GET /groups/:groupId/attendees/:attendeeId', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('devuelve el participante del grupo', async () => {
|
|
prisma.group.findUnique.mockResolvedValue(makeGroup());
|
|
prisma.attendee.findFirst.mockResolvedValue(attendee);
|
|
|
|
const res = await makeApp({ id: userId }).request('/groups/group-1/attendees/a-1');
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(await res.json()).toEqual({
|
|
id: 'a-1',
|
|
groupId: 'group-1',
|
|
fullName: 'Ana Pérez',
|
|
email: 'ana@example.com',
|
|
phone: '5512345678',
|
|
guardianName: 'Luis Pérez',
|
|
guardianPhone: null,
|
|
notes: null,
|
|
notifyToken: 'token-1',
|
|
createdAt: '2026-08-01T10:00:00.000Z',
|
|
updatedAt: '2026-08-01T10:00:00.000Z',
|
|
payment: { status: 'PENDING', dueDate: '2026-10-10T00:00:00.000Z' },
|
|
});
|
|
expect(prisma.attendee.findFirst).toHaveBeenCalledWith({
|
|
where: { id: 'a-1', groupId: 'group-1' },
|
|
include: {
|
|
payments: {
|
|
where: {
|
|
status: { not: 'CANCELLED' },
|
|
dueDate: { gte: expect.any(Date), lt: expect.any(Date) },
|
|
},
|
|
orderBy: { dueDate: 'desc' },
|
|
take: 1,
|
|
select: { status: true, dueDate: true },
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
it('devuelve 404 si el participante no pertenece al grupo', async () => {
|
|
prisma.group.findUnique.mockResolvedValue(makeGroup());
|
|
prisma.attendee.findFirst.mockResolvedValue(null);
|
|
|
|
const res = await makeApp({ id: userId }).request('/groups/group-1/attendees/nope');
|
|
|
|
expect(res.status).toBe(404);
|
|
expect(await res.json()).toMatchObject({ code: 'not_found' });
|
|
});
|
|
|
|
it('devuelve 403 si el usuario no tiene acceso al grupo', async () => {
|
|
prisma.group.findUnique.mockResolvedValue(
|
|
makeGroup({ createdById: 'otro-user', members: [] }),
|
|
);
|
|
|
|
const res = await makeApp({ id: userId }).request('/groups/group-1/attendees/a-1');
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(await res.json()).toMatchObject({ code: 'group_access_denied' });
|
|
});
|
|
|
|
it('devuelve 401 si no hay sesión', async () => {
|
|
const res = await makeApp(undefined).request('/groups/group-1/attendees/a-1');
|
|
|
|
expect(res.status).toBe(401);
|
|
});
|
|
});
|