|
|
|
|
@ -227,4 +227,111 @@ describe('Web API - GET /api/me/tasks', () => {
|
|
|
|
|
const ids = recent.items.map((it: any) => it.id);
|
|
|
|
|
expect(ids.includes(taskId)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('oculta tareas de grupo archivado aunque esté asignada y allowed', async () => {
|
|
|
|
|
// Abrir la misma DB del servidor para sembrar datos adicionales
|
|
|
|
|
const db2 = new Database(dbPath);
|
|
|
|
|
const nowIso = toIsoSql(new Date());
|
|
|
|
|
|
|
|
|
|
// Grupo activo inicialmente
|
|
|
|
|
db2.prepare(`
|
|
|
|
|
INSERT INTO groups (id, community_id, name, active, last_verified, archived)
|
|
|
|
|
VALUES (?, 'comm-1', 'Group ARCH', 1, ?, 0)
|
|
|
|
|
`).run('arch@g.us', nowIso);
|
|
|
|
|
db2.prepare(`INSERT OR REPLACE INTO allowed_groups (group_id, status, updated_at) VALUES ('arch@g.us','allowed',?)`).run(nowIso);
|
|
|
|
|
db2.prepare(`
|
|
|
|
|
INSERT INTO group_members (group_id, user_id, is_admin, is_active, first_seen_at, last_seen_at)
|
|
|
|
|
VALUES ('arch@g.us', ?, 0, 1, ?, ?)
|
|
|
|
|
`).run(USER, nowIso, nowIso);
|
|
|
|
|
|
|
|
|
|
// Tarea asignada al usuario en ese grupo
|
|
|
|
|
const r = db2.prepare(`
|
|
|
|
|
INSERT INTO tasks (description, due_date, group_id, created_by, display_code)
|
|
|
|
|
VALUES ('delta archivada', '2025-03-01', 'arch@g.us', ?, 150)
|
|
|
|
|
`).run(USER) as any;
|
|
|
|
|
const tid = Number(r.lastInsertRowid);
|
|
|
|
|
db2.prepare(`INSERT INTO task_assignments (task_id, user_id, assigned_by) VALUES (?, ?, ?)`).run(tid, USER, USER);
|
|
|
|
|
|
|
|
|
|
// Archivar el grupo
|
|
|
|
|
db2.prepare(`UPDATE groups SET archived = 1 WHERE id = 'arch@g.us'`).run();
|
|
|
|
|
|
|
|
|
|
db2.close();
|
|
|
|
|
|
|
|
|
|
const q = encodeURIComponent('delta');
|
|
|
|
|
const res = await fetch(`${server!.baseUrl}/api/me/tasks?limit=50&search=${q}`, {
|
|
|
|
|
headers: { Cookie: `sid=${sid}` }
|
|
|
|
|
});
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
const json = await res.json();
|
|
|
|
|
const descs = json.items.map((it: any) => String(it.description));
|
|
|
|
|
expect(descs.some((d: string) => d.includes('delta archivada'))).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('oculta tareas de grupo inactivo (active=0) aunque esté asignada y allowed', async () => {
|
|
|
|
|
const db2 = new Database(dbPath);
|
|
|
|
|
const nowIso = toIsoSql(new Date());
|
|
|
|
|
|
|
|
|
|
db2.prepare(`
|
|
|
|
|
INSERT INTO groups (id, community_id, name, active, last_verified, archived)
|
|
|
|
|
VALUES ('inact@g.us', 'comm-1', 'Group INACT', 1, ?, 0)
|
|
|
|
|
`).run(nowIso);
|
|
|
|
|
db2.prepare(`INSERT OR REPLACE INTO allowed_groups (group_id, status, updated_at) VALUES ('inact@g.us','allowed',?)`).run(nowIso);
|
|
|
|
|
db2.prepare(`
|
|
|
|
|
INSERT INTO group_members (group_id, user_id, is_admin, is_active, first_seen_at, last_seen_at)
|
|
|
|
|
VALUES ('inact@g.us', ?, 0, 1, ?, ?)
|
|
|
|
|
`).run(USER, nowIso, nowIso);
|
|
|
|
|
|
|
|
|
|
const r = db2.prepare(`
|
|
|
|
|
INSERT INTO tasks (description, due_date, group_id, created_by, display_code)
|
|
|
|
|
VALUES ('omega inactiva', '2025-04-01', 'inact@g.us', ?, 151)
|
|
|
|
|
`).run(USER) as any;
|
|
|
|
|
const tid = Number(r.lastInsertRowid);
|
|
|
|
|
db2.prepare(`INSERT INTO task_assignments (task_id, user_id, assigned_by) VALUES (?, ?, ?)`).run(tid, USER, USER);
|
|
|
|
|
|
|
|
|
|
// Desactivar el grupo
|
|
|
|
|
db2.prepare(`UPDATE groups SET active = 0 WHERE id = 'inact@g.us'`).run();
|
|
|
|
|
db2.close();
|
|
|
|
|
|
|
|
|
|
const q = encodeURIComponent('omega inactiva');
|
|
|
|
|
const res = await fetch(`${server!.baseUrl}/api/me/tasks?limit=50&search=${q}`, {
|
|
|
|
|
headers: { Cookie: `sid=${sid}` }
|
|
|
|
|
});
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
const json = await res.json();
|
|
|
|
|
expect(json.items.length).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('recent no muestra tareas completadas de grupos archivados', async () => {
|
|
|
|
|
const db2 = new Database(dbPath);
|
|
|
|
|
const nowIso = toIsoSql(new Date());
|
|
|
|
|
|
|
|
|
|
db2.prepare(`
|
|
|
|
|
INSERT INTO groups (id, community_id, name, active, last_verified, archived)
|
|
|
|
|
VALUES ('rec@g.us', 'comm-1', 'Group REC', 1, ?, 0)
|
|
|
|
|
`).run(nowIso);
|
|
|
|
|
db2.prepare(`INSERT OR REPLACE INTO allowed_groups (group_id, status, updated_at) VALUES ('rec@g.us','allowed',?)`).run(nowIso);
|
|
|
|
|
db2.prepare(`
|
|
|
|
|
INSERT INTO group_members (group_id, user_id, is_admin, is_active, first_seen_at, last_seen_at)
|
|
|
|
|
VALUES ('rec@g.us', ?, 0, 1, ?, ?)
|
|
|
|
|
`).run(USER, nowIso, nowIso);
|
|
|
|
|
|
|
|
|
|
const r = db2.prepare(`
|
|
|
|
|
INSERT INTO tasks (description, due_date, group_id, created_by, completed, completed_at, display_code)
|
|
|
|
|
VALUES ('epsilon reciente', '2025-05-01', 'rec@g.us', ?, 1, ?, 152)
|
|
|
|
|
`).run(USER, nowIso) as any;
|
|
|
|
|
const tid = Number(r.lastInsertRowid);
|
|
|
|
|
db2.prepare(`INSERT INTO task_assignments (task_id, user_id, assigned_by) VALUES (?, ?, ?)`).run(tid, USER, USER);
|
|
|
|
|
|
|
|
|
|
// Archivar el grupo
|
|
|
|
|
db2.prepare(`UPDATE groups SET archived = 1 WHERE id = 'rec@g.us'`).run();
|
|
|
|
|
db2.close();
|
|
|
|
|
|
|
|
|
|
const q = encodeURIComponent('epsilon reciente');
|
|
|
|
|
const res = await fetch(`${server!.baseUrl}/api/me/tasks?status=recent&limit=50&search=${q}`, {
|
|
|
|
|
headers: { Cookie: `sid=${sid}` }
|
|
|
|
|
});
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
const json = await res.json();
|
|
|
|
|
expect(json.items.length).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|