Expose shared-number state on lead list and detail queries
This commit is contained in:
@@ -140,3 +140,38 @@ test('lead sem verificacao equivalente permanece nao consultado', async () => {
|
||||
}
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('listagem e detalhe marcam numero compartilhado por mais de um lead', async () => {
|
||||
const { openDb, addSharedNumberOverride } = await import('../src/db.mjs');
|
||||
const { getLead, listLeads } = await import('../src/treatment/queries.mjs');
|
||||
const db = openDb(':memory:');
|
||||
const sharedA = db.prepare(
|
||||
`INSERT INTO leads (dedup_key, empresa, whatsapp, telefone_valido)
|
||||
VALUES ('shared-a', 'Contabilidade Cliente A', '5575999091780', 1)`
|
||||
).run();
|
||||
db.prepare(
|
||||
`INSERT INTO leads (dedup_key, empresa, whatsapp, telefone_valido)
|
||||
VALUES ('shared-b', 'Contabilidade Cliente B', '557599091780', 1)`
|
||||
).run();
|
||||
const solo = db.prepare(
|
||||
`INSERT INTO leads (dedup_key, empresa, whatsapp, telefone_valido)
|
||||
VALUES ('solo', 'Empresa Unica', '5511999990001', 1)`
|
||||
).run();
|
||||
|
||||
const rows = listLeads(db).rows;
|
||||
const shared = rows.find((row) => row.id === Number(sharedA.lastInsertRowid));
|
||||
const unique = rows.find((row) => row.id === Number(solo.lastInsertRowid));
|
||||
assert.equal(shared.numero_compartilhado, true);
|
||||
assert.equal(shared.numero_compartilhado_total, 2);
|
||||
assert.equal(shared.numero_compartilhado_liberado, false);
|
||||
assert.equal(unique.numero_compartilhado, false);
|
||||
assert.equal(unique.numero_compartilhado_total, 0);
|
||||
|
||||
const detail = getLead(db, Number(sharedA.lastInsertRowid));
|
||||
assert.equal(detail.numero_compartilhado, true);
|
||||
|
||||
addSharedNumberOverride(db, '5575999091780', 'revisado');
|
||||
const refreshed = getLead(db, Number(sharedA.lastInsertRowid));
|
||||
assert.equal(refreshed.numero_compartilhado_liberado, true);
|
||||
db.close();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user