feat(attendee-detail): enhance attendee detail view with payment and notes sections
- 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.
This commit is contained in:
@@ -202,7 +202,11 @@ describe('analytics routes', () => {
|
||||
describe('GET /groups/:groupId/attendees/:attendeeId/history', () => {
|
||||
it('devuelve el historial de presentismo con su porcentaje', async () => {
|
||||
prisma.group.findUnique.mockResolvedValue(makeGroup());
|
||||
prisma.attendee.findFirst.mockResolvedValue({ id: 'a-1', fullName: 'Ana Pérez' });
|
||||
prisma.attendee.findFirst.mockResolvedValue({
|
||||
id: 'a-1',
|
||||
fullName: 'Ana Pérez',
|
||||
createdAt: new Date('2026-09-29T00:00:00.000Z'),
|
||||
});
|
||||
prisma.classSession.findMany.mockResolvedValue([
|
||||
{ id: 's-2', startsAt: new Date(at(7)) },
|
||||
{ id: 's-1', startsAt: new Date(at(0)) },
|
||||
@@ -228,6 +232,15 @@ describe('analytics routes', () => {
|
||||
{ classSessionId: 's-2', startsAt: at(7), status: 'ABSENT' },
|
||||
],
|
||||
});
|
||||
expect(prisma.classSession.findMany).toHaveBeenCalledWith({
|
||||
where: {
|
||||
groupId: 'group-1',
|
||||
startsAt: { gte: new Date('2026-09-29T00:00:00.000Z') },
|
||||
},
|
||||
orderBy: { startsAt: 'desc' },
|
||||
take: 20,
|
||||
select: { id: true, startsAt: true },
|
||||
});
|
||||
});
|
||||
|
||||
it('devuelve 404 si el alumno no pertenece al grupo', async () => {
|
||||
@@ -322,4 +335,4 @@ describe('analytics routes', () => {
|
||||
expect(res.status).toBe(401);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,6 +47,9 @@ const attendee = {
|
||||
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', () => {
|
||||
@@ -73,6 +76,21 @@ describe('GET /groups/:groupId/attendees/:attendeeId', () => {
|
||||
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 },
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
99
apps/backend/test/attendee-update.test.ts
Normal file
99
apps/backend/test/attendee-update.test.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
import { beforeEach, describe, expect, it, mock, vi } from 'bun:test'
|
||||
import { Hono } from 'hono'
|
||||
|
||||
const db = {
|
||||
group: { findUnique: mock() },
|
||||
attendee: { findFirst: mock(), update: mock() },
|
||||
}
|
||||
|
||||
mock.module('@/lib/prisma', () => ({
|
||||
default: db,
|
||||
getPrismaClient: mock(),
|
||||
UnitOfWork: class {},
|
||||
}))
|
||||
|
||||
import updateAttendeeRoute from '@/modules/attendees/features/update/route'
|
||||
|
||||
const userId = 'user-1'
|
||||
const attendee = {
|
||||
id: 'a-1',
|
||||
groupId: 'group-1',
|
||||
fullName: 'Ana Pérez',
|
||||
email: null,
|
||||
phone: null,
|
||||
guardianName: null,
|
||||
guardianPhone: null,
|
||||
notes: 'Llega temprano',
|
||||
notifyToken: 'token-1',
|
||||
createdAt: new Date('2026-08-01T10:00:00.000Z'),
|
||||
updatedAt: new Date('2026-10-01T12:00:00.000Z'),
|
||||
}
|
||||
|
||||
function makeApp() {
|
||||
const app = new Hono()
|
||||
app.use('*', async (context, next) => {
|
||||
context.set('user', { id: userId } as never)
|
||||
await next()
|
||||
})
|
||||
app.route('/groups', updateAttendeeRoute)
|
||||
return app
|
||||
}
|
||||
|
||||
describe('PATCH /groups/:groupId/attendees/:attendeeId', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
db.group.findUnique.mockResolvedValue({
|
||||
id: 'group-1',
|
||||
name: 'Funcional',
|
||||
createdById: userId,
|
||||
members: [],
|
||||
})
|
||||
db.attendee.findFirst.mockResolvedValue(attendee)
|
||||
})
|
||||
|
||||
it('actualiza contacto y conserva los campos vacíos como null', async () => {
|
||||
db.attendee.update.mockResolvedValue({
|
||||
...attendee,
|
||||
email: 'ana@example.com',
|
||||
phone: null,
|
||||
})
|
||||
|
||||
const response = await makeApp().request('/groups/group-1/attendees/a-1', {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email: 'ana@example.com', phone: '' }),
|
||||
})
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
expect(db.attendee.update).toHaveBeenCalledWith({
|
||||
where: { id: 'a-1' },
|
||||
data: { email: 'ana@example.com', phone: null },
|
||||
})
|
||||
})
|
||||
|
||||
it('actualiza una única nota', async () => {
|
||||
db.attendee.update.mockResolvedValue({ ...attendee, notes: 'Traer colchoneta' })
|
||||
|
||||
await makeApp().request('/groups/group-1/attendees/a-1', {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ notes: 'Traer colchoneta' }),
|
||||
})
|
||||
|
||||
expect(db.attendee.update).toHaveBeenCalledWith({
|
||||
where: { id: 'a-1' },
|
||||
data: { notes: 'Traer colchoneta' },
|
||||
})
|
||||
})
|
||||
|
||||
it('rechaza un email inválido', async () => {
|
||||
const response = await makeApp().request('/groups/group-1/attendees/a-1', {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email: 'sin-arroba' }),
|
||||
})
|
||||
|
||||
expect(response.status).toBe(400)
|
||||
expect(db.attendee.update).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user