chore: import gti-maquina-comercial history via subtree
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> git-subtree-dir: gti-maquina-comercial git-subtree-mainline:93ca82979egit-subtree-split:b77484946f
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { openDb } from '../src/db.mjs';
|
||||
import { runCapture, createCaptureRun } from '../src/capture/runner.mjs';
|
||||
|
||||
const SEGMENTS = [
|
||||
{ name: 'mercados_de_bairro', label: 'Mercados De Bairro', interest: 'ERP / sistema de gestao', queries: ['mercado'], cnaeCodes: ['4711302'], overpassTags: [], pains: ['estoque'] },
|
||||
{ name: 'clinicas_medicas', label: 'Clinicas Medicas', interest: 'gestao de TI', queries: ['clinica'], cnaeCodes: ['8630501'], overpassTags: [], pains: ['agenda'] },
|
||||
{ name: 'restaurantes', label: 'Restaurantes', interest: 'autoatendimento WhatsApp', queries: ['restaurante'], cnaeCodes: ['5611201'], overpassTags: [], pains: ['pedidos'] }
|
||||
];
|
||||
|
||||
function captureParams() {
|
||||
return {
|
||||
sources: ['mock'],
|
||||
uf: 'BA',
|
||||
cities: ['Santo Antonio de Jesus'],
|
||||
segments: SEGMENTS,
|
||||
limits: { maxPerQuery: 10, queryLimit: 0 }
|
||||
};
|
||||
}
|
||||
|
||||
test('runCapture insere leads do mock e deduplica no rerun', async () => {
|
||||
const db = openDb(':memory:');
|
||||
|
||||
const runId = createCaptureRun(db, {});
|
||||
const first = await runCapture({ db, runId, params: captureParams() });
|
||||
assert.equal(first.raw, 3);
|
||||
assert.equal(first.new, 3);
|
||||
assert.equal(first.dup, 0);
|
||||
assert.equal(first.status, 'done');
|
||||
|
||||
const run = db.prepare('SELECT * FROM capture_runs WHERE id = ?').get(runId);
|
||||
assert.equal(run.status, 'done');
|
||||
assert.equal(run.new_count, 3);
|
||||
assert.ok(run.finished_at);
|
||||
|
||||
const lead = db.prepare("SELECT * FROM leads WHERE segmento = 'restaurantes'").get();
|
||||
assert.equal(lead.uf, 'BA');
|
||||
assert.equal(lead.cidade, 'Santo Antonio de Jesus');
|
||||
assert.equal(lead.origem, 'mock');
|
||||
assert.equal(lead.telefone_valido, 1);
|
||||
assert.ok(lead.dedup_key.startsWith('phone:'));
|
||||
assert.equal(lead.capture_run_id, runId);
|
||||
|
||||
// rerun: tudo duplicado
|
||||
const runId2 = createCaptureRun(db, {});
|
||||
const second = await runCapture({ db, runId: runId2, params: captureParams() });
|
||||
assert.equal(second.new, 0);
|
||||
assert.equal(second.dup, 3);
|
||||
assert.equal(db.prepare('SELECT COUNT(*) AS t FROM leads').get().t, 3);
|
||||
|
||||
db.close();
|
||||
});
|
||||
|
||||
test('runCapture respeita cancelamento', async () => {
|
||||
const db = openDb(':memory:');
|
||||
const runId = createCaptureRun(db, {});
|
||||
|
||||
const result = await runCapture({
|
||||
db,
|
||||
runId,
|
||||
params: captureParams(),
|
||||
isCancelled: () => true
|
||||
});
|
||||
|
||||
assert.equal(result.status, 'cancelled');
|
||||
assert.equal(db.prepare('SELECT status FROM capture_runs WHERE id = ?').get(runId).status, 'cancelled');
|
||||
db.close();
|
||||
});
|
||||
Reference in New Issue
Block a user