feat: pasar de la lista de espera a otro grupo del profesor
- `POST /groups/:gid/waitlist/:entryId/promote` acepta `targetGroupId` opcional (por defecto, el grupo en el que se anotó). El destino tiene que ser del mismo profesor; cupo y teléfono duplicado se validan ahí. - Detalle de la lista de espera: selector "Asignar a" con los grupos llenos deshabilitados. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -204,6 +204,71 @@ describe('group waitlist management', () => {
|
||||
expect(res.status).toBe(403);
|
||||
expect(prisma.attendee.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
const promoteTo = (targetGroupId: string) =>
|
||||
makeApp({ id: teacherId }).request('/groups/group-1/waitlist/wl-1/promote', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ targetGroupId }),
|
||||
});
|
||||
|
||||
it('places the entry in another group of the teacher and removes it from the origin waitlist', async () => {
|
||||
prisma.group.findUnique
|
||||
.mockResolvedValueOnce(mockGroup as never)
|
||||
.mockResolvedValueOnce({ ...mockGroup, id: 'group-2', name: 'Taller de Cerámica' } as never);
|
||||
prisma.groupWaitlistEntry.findFirst.mockResolvedValue(waitlistEntry() as never);
|
||||
prisma.attendee.count.mockResolvedValue(5);
|
||||
prisma.attendee.findFirst.mockResolvedValue(null);
|
||||
prisma.attendee.create.mockResolvedValue(attendee({ groupId: 'group-2' }) as never);
|
||||
|
||||
const res = await promoteTo('group-2');
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(prisma.group.findUnique).toHaveBeenLastCalledWith({ where: { id: 'group-2' } });
|
||||
expect(prisma.attendee.count).toHaveBeenCalledWith({ where: { groupId: 'group-2', status: 'ACTIVE' } });
|
||||
expect(prisma.attendee.create).toHaveBeenCalledWith({
|
||||
data: expect.objectContaining({ groupId: 'group-2', fullName: 'Martín Gómez' }),
|
||||
});
|
||||
expect(prisma.groupWaitlistEntry.delete).toHaveBeenCalledWith({ where: { id: 'wl-1' } });
|
||||
});
|
||||
|
||||
it('rejects a target group owned by another teacher', async () => {
|
||||
prisma.group.findUnique
|
||||
.mockResolvedValueOnce(mockGroup as never)
|
||||
.mockResolvedValueOnce({ ...mockGroup, id: 'group-2', createdById: 'other-user' } as never);
|
||||
prisma.groupWaitlistEntry.findFirst.mockResolvedValue(waitlistEntry() as never);
|
||||
|
||||
const res = await promoteTo('group-2');
|
||||
|
||||
expect(res.status).toBe(403);
|
||||
expect(prisma.attendee.create).not.toHaveBeenCalled();
|
||||
expect(prisma.groupWaitlistEntry.delete).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('returns 404 when the target group does not exist', async () => {
|
||||
prisma.group.findUnique.mockResolvedValueOnce(mockGroup as never).mockResolvedValueOnce(null);
|
||||
prisma.groupWaitlistEntry.findFirst.mockResolvedValue(waitlistEntry() as never);
|
||||
|
||||
const res = await promoteTo('group-missing');
|
||||
|
||||
expect(res.status).toBe(404);
|
||||
expect(prisma.attendee.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects with 409 when the target group reached its capacity', async () => {
|
||||
prisma.group.findUnique
|
||||
.mockResolvedValueOnce(mockGroup as never)
|
||||
.mockResolvedValueOnce({ ...mockGroup, id: 'group-2', capacity: 5 } as never);
|
||||
prisma.groupWaitlistEntry.findFirst.mockResolvedValue(waitlistEntry() as never);
|
||||
prisma.attendee.count.mockResolvedValue(5);
|
||||
|
||||
const res = await promoteTo('group-2');
|
||||
|
||||
expect(res.status).toBe(409);
|
||||
const body = await res.json();
|
||||
expect(body.code).toBe('group_capacity_reached');
|
||||
expect(prisma.groupWaitlistEntry.delete).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /groups/:groupId/waitlist/:entryId', () => {
|
||||
|
||||
Reference in New Issue
Block a user