Fix invalid prioridade filter silently matching P4 instead of nothing
buildLeadFilter used Number(filtro.prioridade) || 4, so an explicit prioridade=0 or any non-numeric value (both falsy after Number()) matched P4 leads instead of the requested (invalid) priority. Not reachable via the UI (its dropdown only offers 1-4) but reachable through a direct API call. Drops the fallback: an invalid value becomes NaN, which node:sqlite accepts as a bound parameter and never compares equal to anything, so it now correctly matches zero rows instead of silently redirecting to P4. Found via a full-project audit.
This commit is contained in:
@@ -98,6 +98,28 @@ test('opt-out bloqueia os dois lados de um par 12/13 digitos assimetrico', async
|
||||
db.close();
|
||||
});
|
||||
|
||||
// Number(...) || 4 tratava prioridade=0 (ou texto nao numerico) como P4,
|
||||
// ja que 0/NaN sao falsy em JS — um filtro invalido devolvia leads de P4 em
|
||||
// vez de nao bater com nada.
|
||||
test('filtro de prioridade invalido nao e silenciosamente tratado como P4', async () => {
|
||||
const { openDb } = await import('../src/db.mjs');
|
||||
const { listLeads } = await import('../src/treatment/queries.mjs');
|
||||
const db = openDb(':memory:');
|
||||
db.prepare(
|
||||
`INSERT INTO leads (dedup_key, empresa, whatsapp, prioridade, telefone_valido)
|
||||
VALUES ('p1', 'Empresa P1', '5511999990001', 1, 1)`
|
||||
).run();
|
||||
db.prepare(
|
||||
`INSERT INTO leads (dedup_key, empresa, whatsapp, prioridade, telefone_valido)
|
||||
VALUES ('p4', 'Empresa P4', '5511999990004', 4, 1)`
|
||||
).run();
|
||||
|
||||
assert.deepEqual(listLeads(db, { prioridade: '0' }).rows.map((r) => r.empresa), []);
|
||||
assert.deepEqual(listLeads(db, { prioridade: 'abc' }).rows.map((r) => r.empresa), []);
|
||||
assert.deepEqual(listLeads(db, { prioridade: '4' }).rows.map((r) => r.empresa), ['Empresa P4']);
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('listagem e detalhe derivam o estado da verificacao equivalente mais recente', async () => {
|
||||
const { openDb, saveWhatsAppVerification } = await import('../src/db.mjs');
|
||||
const { getLead, listLeads } = await import('../src/treatment/queries.mjs');
|
||||
|
||||
Reference in New Issue
Block a user