Add shared-number review routes and block manual send for unreleased numbers
This commit is contained in:
@@ -130,6 +130,79 @@ test('rotas opt-out listam e restringem mutacoes a admin', async () => {
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('envio manual bloqueia numero compartilhado por leads distintos ate liberacao', async () => {
|
||||
const { db, router } = setup();
|
||||
const insert = createLeadInserter(db);
|
||||
insert({
|
||||
dedup_key: 'shared-a', empresa: 'Empresa A', whatsapp: '5511999990009', cidade: 'Salvador',
|
||||
produtos_json: '[]', pains_json: '[]', origem: 'teste',
|
||||
telefone_valido: 1, cnpj_valido: 0, empresa_valida: 1, score: 0, classificacao: 'ruim'
|
||||
});
|
||||
insert({
|
||||
dedup_key: 'shared-b', empresa: 'Empresa B', whatsapp: '5511999990009', cidade: 'Salvador',
|
||||
produtos_json: '[]', pains_json: '[]', origem: 'teste',
|
||||
telefone_valido: 1, cnpj_valido: 0, empresa_valida: 1, score: 0, classificacao: 'ruim'
|
||||
});
|
||||
|
||||
const blocked = await invoke(router, 'POST', '/api/outreach/enviar-manual', {
|
||||
body: { numero: '5511999990009', mensagem: 'Oi' }
|
||||
});
|
||||
assert.equal(blocked.status, 409);
|
||||
|
||||
await invoke(router, 'POST', '/api/outreach/shared-numbers/5511999990009/liberar', {
|
||||
body: { motivo: 'confirmado contato direto' }, user: { role: 'admin' }
|
||||
});
|
||||
const allowed = await invoke(router, 'POST', '/api/outreach/enviar-manual', {
|
||||
body: { numero: '5511999990009', mensagem: 'Oi' }
|
||||
});
|
||||
assert.equal(allowed.status, 202);
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('rotas de numeros compartilhados listam e restringem liberacao a admin', async () => {
|
||||
const { db, router } = setup();
|
||||
const insert = createLeadInserter(db);
|
||||
insert({
|
||||
dedup_key: 'shared-a', empresa: 'Empresa A', whatsapp: '5511999990009', cidade: 'Salvador',
|
||||
produtos_json: '[]', pains_json: '[]', origem: 'teste',
|
||||
telefone_valido: 1, cnpj_valido: 0, empresa_valida: 1, score: 0, classificacao: 'ruim'
|
||||
});
|
||||
insert({
|
||||
dedup_key: 'shared-b', empresa: 'Empresa B', whatsapp: '5511999990009', cidade: 'Salvador',
|
||||
produtos_json: '[]', pains_json: '[]', origem: 'teste',
|
||||
telefone_valido: 1, cnpj_valido: 0, empresa_valida: 1, score: 0, classificacao: 'ruim'
|
||||
});
|
||||
|
||||
const listed = await invoke(router, 'GET', '/api/outreach/shared-numbers');
|
||||
assert.equal(listed.data.groups.length, 1);
|
||||
assert.equal(listed.data.groups[0].leads.length, 2);
|
||||
|
||||
const denied = await invoke(router, 'POST', '/api/outreach/shared-numbers/5511999990009/liberar', {
|
||||
body: { motivo: 'teste' }, user: { role: 'comercial' }
|
||||
});
|
||||
assert.equal(denied.status, 403);
|
||||
|
||||
const missingMotivo = await invoke(router, 'POST', '/api/outreach/shared-numbers/5511999990009/liberar', {
|
||||
body: {}, user: { role: 'admin' }
|
||||
});
|
||||
assert.equal(missingMotivo.status, 400);
|
||||
|
||||
const created = await invoke(router, 'POST', '/api/outreach/shared-numbers/5511999990009/liberar', {
|
||||
body: { motivo: 'confirmado' }, user: { role: 'admin' }
|
||||
});
|
||||
assert.equal(created.status, 201);
|
||||
|
||||
const removeDenied = await invoke(router, 'DELETE', '/api/outreach/shared-numbers/5511999990009/liberar', { user: { role: 'comercial' } });
|
||||
assert.equal(removeDenied.status, 403);
|
||||
|
||||
const removed = await invoke(router, 'DELETE', '/api/outreach/shared-numbers/5511999990009/liberar', { user: { role: 'admin' } });
|
||||
assert.equal(removed.status, 200);
|
||||
|
||||
const removedAgain = await invoke(router, 'DELETE', '/api/outreach/shared-numbers/5511999990009/liberar', { user: { role: 'admin' } });
|
||||
assert.equal(removedAgain.status, 404);
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('envio com leadId honra destino visivel e usa contexto completo do banco', async () => {
|
||||
const { db, router, sent } = setup();
|
||||
createLeadInserter(db)({
|
||||
|
||||
Reference in New Issue
Block a user