- Grupos: subtítulo con resumen (grupos · alumnos · lugares libres), sección "Requiere atención" con los 4 alumnos más urgentes y tarjetas con avatares (punteados por lugar libre en grupos chicos, superpuestos con "+N" en grandes; con alerta primero y anillo de gravedad). - Pantalla nueva /groups/attention: filtros Todos/Asistencia/Pagos, secciones Urgente y A vigilar, Contactar / Enviar recordatorio por wa.me y "Resuelto" persistente con update optimista. - FAB "Nuevo grupo" que se pliega al scrollear (respeta reduced motion); los toasts en mobile suben para no quedar debajo. - Alertas centralizadas en computeStudentAlerts (shared). La regla de asistencia pasa a: urgente = 3 seguidas o 4 de las últimas 6; a vigilar = 2 de las últimas 4 (sin inactividad por días ni tendencia). Cuotas: 1 vencida vigilar, 2+ urgente. - Backend: GET /attention y POST /attention/:attendeeId/resolve; tabla attendee_alert_resolutions (la alerta vuelve si cambia la firma). - Tokens de gravedad para claro y oscuro; se quita el indicador de pills. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
131 lines
5.2 KiB
TypeScript
131 lines
5.2 KiB
TypeScript
import { beforeEach, describe, expect, it, mock } from 'bun:test';
|
|
import { Prisma } from '@generated/prisma/client';
|
|
import { GetAttentionOverview } from '@/modules/attention/features/get-overview/use-case';
|
|
import { ResolveStudentAlert } from '@/modules/attention/features/resolve/use-case';
|
|
|
|
const NOW = new Date('2026-10-27T20:00:00.000Z');
|
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
const at = (days: number) => new Date(NOW.getTime() - days * DAY_MS);
|
|
|
|
const db = {
|
|
group: { findMany: mock() },
|
|
attendee: { findMany: mock(), findFirst: mock() },
|
|
classSession: { findMany: mock() },
|
|
attendance: { findMany: mock() },
|
|
payment: { findMany: mock() },
|
|
attendeeAlertResolution: { findMany: mock(), upsert: mock() },
|
|
user: { findUnique: mock() },
|
|
};
|
|
|
|
function overview() {
|
|
return new GetAttentionOverview({ db: db as never, now: NOW });
|
|
}
|
|
|
|
beforeEach(() => {
|
|
for (const delegate of Object.values(db)) {
|
|
for (const fn of Object.values(delegate)) fn.mockReset();
|
|
}
|
|
});
|
|
|
|
describe('GetAttentionOverview', () => {
|
|
it('sin grupos no consulta nada más', async () => {
|
|
db.group.findMany.mockResolvedValue([]);
|
|
const result = await overview().execute('user-1');
|
|
expect(result).toEqual({ ok: true, value: { groups: [] } });
|
|
expect(db.attendee.findMany).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('devuelve todos los miembros con sus alertas, sin las resueltas', async () => {
|
|
db.user.findUnique.mockResolvedValue({ country: 'AR' });
|
|
db.group.findMany.mockResolvedValue([{ id: 'g1', name: 'Natación', capacity: 30 }]);
|
|
db.attendee.findMany.mockResolvedValue([
|
|
{ id: 'a1', groupId: 'g1', fullName: 'Agustina', phone: '1155550000', guardianPhone: null, createdAt: at(90) },
|
|
{ id: 'a2', groupId: 'g1', fullName: 'Valentina', phone: null, guardianPhone: '1166660000', createdAt: at(90) },
|
|
{ id: 'a3', groupId: 'g1', fullName: 'Felipe', phone: null, guardianPhone: null, createdAt: at(90) },
|
|
]);
|
|
db.classSession.findMany.mockResolvedValue([
|
|
{ id: 's1', groupId: 'g1', startsAt: at(1) },
|
|
{ id: 's2', groupId: 'g1', startsAt: at(3) },
|
|
{ id: 's3', groupId: 'g1', startsAt: at(5) },
|
|
]);
|
|
const row = (attendeeId: string, sessionId: string, status: string, days: number) => ({
|
|
attendeeId,
|
|
classSessionId: sessionId,
|
|
status,
|
|
classSession: { startsAt: at(days) },
|
|
});
|
|
db.attendance.findMany.mockResolvedValue([
|
|
row('a1', 's1', 'ABSENT', 1),
|
|
row('a1', 's2', 'ABSENT', 3),
|
|
row('a1', 's3', 'ABSENT', 5),
|
|
// Valentina missed two classes, but the professor already resolved it.
|
|
row('a2', 's1', 'ABSENT', 1),
|
|
row('a2', 's2', 'ABSENT', 3),
|
|
row('a3', 's1', 'PRESENT', 1),
|
|
]);
|
|
db.payment.findMany.mockResolvedValue([
|
|
{
|
|
id: 'p1',
|
|
attendeeId: 'a2',
|
|
amount: new Prisma.Decimal('15000.00'),
|
|
currency: 'ARS',
|
|
dueDate: new Date('2026-10-10T12:00:00.000Z'),
|
|
checkoutUrl: 'https://mp.test/p1',
|
|
},
|
|
]);
|
|
db.attendeeAlertResolution.findMany.mockResolvedValue([
|
|
{ attendeeId: 'a2', kind: 'ATTENDANCE', signature: 's1' },
|
|
]);
|
|
|
|
const result = await overview().execute('user-1');
|
|
if (!result.ok) throw new Error('expected ok');
|
|
|
|
const [group] = result.value.groups;
|
|
expect(group).toMatchObject({ groupId: 'g1', groupName: 'Natación', capacity: 30 });
|
|
expect(group.members.map((member) => member.attendeeId)).toEqual(['a1', 'a2', 'a3']);
|
|
|
|
const [agustina, valentina, felipe] = group.members;
|
|
expect(agustina.phone).toBe('1155550000');
|
|
expect(agustina.whatsappPhone).toBe('+5491155550000');
|
|
expect(agustina.alerts).toMatchObject([{ tipo: 'asistencia', gravedad: 'urgente', etiqueta: '3 seguidas' }]);
|
|
|
|
expect(valentina.phone).toBe('1166660000');
|
|
expect(valentina.alerts).toMatchObject([{ tipo: 'pago', gravedad: 'vigilar', etiqueta: 'Cuota vencida' }]);
|
|
expect(valentina.overduePayments).toEqual([
|
|
{ id: 'p1', amount: 15000, currency: 'ARS', dueDate: '2026-10-10T12:00:00.000Z', checkoutUrl: 'https://mp.test/p1' },
|
|
]);
|
|
|
|
expect(felipe.alerts).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('ResolveStudentAlert', () => {
|
|
it('guarda la firma con upsert por alumno y tipo', async () => {
|
|
db.attendee.findFirst.mockResolvedValue({ id: 'a1' });
|
|
const result = await new ResolveStudentAlert({ db: db as never }).execute('a1', 'user-1', {
|
|
tipo: 'pago',
|
|
firma: 'p1,p2',
|
|
});
|
|
|
|
expect(result).toEqual({ ok: true, value: { attendeeId: 'a1', tipo: 'pago', firma: 'p1,p2' } });
|
|
expect(db.attendeeAlertResolution.upsert).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
where: { attendeeId_kind: { attendeeId: 'a1', kind: 'PAYMENT' } },
|
|
create: expect.objectContaining({ signature: 'p1,p2', resolvedById: 'user-1' }),
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('un alumno de un grupo ajeno es 404 y no escribe nada', async () => {
|
|
db.attendee.findFirst.mockResolvedValue(null);
|
|
const result = await new ResolveStudentAlert({ db: db as never }).execute('a9', 'user-1', {
|
|
tipo: 'asistencia',
|
|
firma: 's1',
|
|
});
|
|
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) expect(result.error.status).toBe(404);
|
|
expect(db.attendeeAlertResolution.upsert).not.toHaveBeenCalled();
|
|
});
|
|
});
|