feat: un miembro puede pertenecer a más de un grupo
- Nuevo modelo `Person` (`people`): contacto y notas por profe, con teléfono único (índice parcial `people_owner_phone_key`). `Attendee` pasa a ser la membresía (`group_id` + `person_id`, único por grupo). - La cuenta de la app de alumnos se vincula a la persona (`student_account_people`): una sola cuenta ve todos sus grupos. - Migración unifica attendees del mismo profe y teléfono, y fusiona sus cuentas de alumno (conserva la usada más recientemente). - `POST /groups/:gid/attendees/:aid/add-to-group` y `GET /people/lookup` para detectar personas existentes al cargar; el alta responde `409 person_exists` y acepta `personId`. Bulk, lista de espera y preinscripciones vinculan solas. - El límite del plan cuenta personas con al menos un grupo activo. - Web: "Agregar a otro grupo", sección "También está en" en la ficha y aviso "Ya tenés a esta persona" en el alta individual. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,14 @@ describe.skipIf(!url)('student access (real database)', () => {
|
||||
// Same contract as UnitOfWork.executeResult, built on this file's own client
|
||||
// (other test files mock '@/lib/prisma').
|
||||
let unitOfWork: { executeResult: unknown };
|
||||
const ids = { user: `test-user-${suffix}`, group: `test-group-${suffix}`, attendee: `test-att-${suffix}` };
|
||||
const ids = {
|
||||
user: `test-user-${suffix}`,
|
||||
group: `test-group-${suffix}`,
|
||||
group2: `test-group2-${suffix}`,
|
||||
person: `test-person-${suffix}`,
|
||||
attendee: `test-att-${suffix}`,
|
||||
attendee2: `test-att2-${suffix}`,
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
db = new PrismaClient({ adapter: new PrismaPg({ connectionString: url as string }) });
|
||||
@@ -42,7 +49,11 @@ describe.skipIf(!url)('student access (real database)', () => {
|
||||
};
|
||||
await db.user.create({ data: { id: ids.user, name: 'Profe Test', email: `${ids.user}@test.local` } });
|
||||
await db.group.create({ data: { id: ids.group, name: 'Natación', createdById: ids.user } });
|
||||
await db.attendee.create({ data: { id: ids.attendee, groupId: ids.group, fullName: 'Ana Pérez' } });
|
||||
await db.group.create({ data: { id: ids.group2, name: 'Yoga', createdById: ids.user } });
|
||||
// One person in two groups of the teacher.
|
||||
await db.person.create({ data: { id: ids.person, createdById: ids.user, fullName: 'Ana Pérez' } });
|
||||
await db.attendee.create({ data: { id: ids.attendee, groupId: ids.group, personId: ids.person } });
|
||||
await db.attendee.create({ data: { id: ids.attendee2, groupId: ids.group2, personId: ids.person } });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -96,7 +107,7 @@ describe.skipIf(!url)('student access (real database)', () => {
|
||||
if (!loser.ok) expect(loser.error.status).toBe(410);
|
||||
}
|
||||
|
||||
const account = await db.studentAccountAttendee.findFirstOrThrow({ where: { attendeeId: ids.attendee } });
|
||||
const account = await db.studentAccountPerson.findFirstOrThrow({ where: { personId: ids.person } });
|
||||
const sessions = await db.studentSession.findMany({ where: { accountId: account.accountId, revokedAt: null } });
|
||||
expect(sessions).toHaveLength(1);
|
||||
expect(sessions[0]?.device).toBe('iPhone · Safari');
|
||||
@@ -122,7 +133,7 @@ describe.skipIf(!url)('student access (real database)', () => {
|
||||
if (!first.ok) throw new Error('invite failed');
|
||||
const consumed = await consume(tokenOf(first.value.url));
|
||||
expect(consumed.ok).toBe(true);
|
||||
const linked = await db.studentAccountAttendee.findFirstOrThrow({ where: { attendeeId: ids.attendee } });
|
||||
const linked = await db.studentAccountPerson.findFirstOrThrow({ where: { personId: ids.person } });
|
||||
await db.studentPasskey.create({
|
||||
data: { accountId: linked.accountId, credentialId: `cred-${suffix}`, publicKey: new Uint8Array([1]), device: 'iPhone · Safari' },
|
||||
});
|
||||
@@ -141,9 +152,25 @@ describe.skipIf(!url)('student access (real database)', () => {
|
||||
expect((await consume(tokenOf(pendingOld.value.url))).ok).toBe(false);
|
||||
expect((await consume(tokenOf(reinvite.value.url))).ok).toBe(true);
|
||||
|
||||
const account = await db.studentAccountAttendee.findFirstOrThrow({ where: { attendeeId: ids.attendee } });
|
||||
const account = await db.studentAccountPerson.findFirstOrThrow({ where: { personId: ids.person } });
|
||||
expect(await db.studentSession.count({ where: { accountId: account.accountId, revokedAt: null } })).toBe(1);
|
||||
const after = await new GetStudentAccess({ db }).execute(ids.group, ids.attendee, ids.user);
|
||||
expect(after).toMatchObject({ ok: true, value: { status: 'active' } });
|
||||
});
|
||||
|
||||
it('una sola cuenta por persona: invitar desde otro grupo la reutiliza', async () => {
|
||||
const fromFirst = await invite();
|
||||
if (!fromFirst.ok) throw new Error('invite failed');
|
||||
const fromSecond = await new InviteStudent({ db, unitOfWork: unitOfWork as never }).execute(
|
||||
ids.group2,
|
||||
ids.attendee2,
|
||||
ids.user,
|
||||
);
|
||||
if (!fromSecond.ok) throw new Error('invite failed');
|
||||
|
||||
expect(await db.studentAccountPerson.count({ where: { personId: ids.person } })).toBe(1);
|
||||
// Same state from both groups: it is the person's access.
|
||||
const fromGroup2 = await new GetStudentAccess({ db }).execute(ids.group2, ids.attendee2, ids.user);
|
||||
expect(fromGroup2).toMatchObject({ ok: true, value: { status: 'invited' } });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user