- 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.
100 lines
2.7 KiB
TypeScript
100 lines
2.7 KiB
TypeScript
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()
|
|
})
|
|
})
|