Baseline commit of the existing Maquina Comercial Pessoal project

Tracks the app that was already in place (capture, treatment, outreach,
WhatsApp integration, server, frontend, tests, docs) so future feature
work can branch and use isolated worktrees.
This commit is contained in:
Gustavo
2026-07-31 10:54:07 -03:00
parent 6cd336a41e
commit d330bb5ff0
132 changed files with 29969 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { collect } from '../src/sources/cnpj-base.mjs';
const header = 'cnpj;razao_social;nome_fantasia;municipio;uf;cnae\n';
const row = (cnpj, nome, uf) => `${cnpj};${nome};${nome};Salvador;${uf};5611201\n`;
test('cnpj-base le somente o CSV da UF solicitada e o legado apenas para Bahia', async (t) => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'cnpj-files-'));
t.after(() => fs.rm(dir, { recursive: true, force: true }));
await fs.writeFile(path.join(dir, 'estabelecimentos-BA.csv'), header + row('11111111000111', 'BA EXATA', 'BA'));
await fs.writeFile(path.join(dir, 'estabelecimentos-SP.csv'), header + row('22222222000122', 'SP ERRADA', 'SP'));
await fs.writeFile(path.join(dir, 'checkpoint-estabelecimentos-BA.csv'), header + row('33333333000133', 'CHECKPOINT', 'BA'));
await fs.writeFile(path.join(dir, 'qualquer.csv'), header + row('44444444000144', 'GENERICO', 'BA'));
await fs.writeFile(path.join(dir, 'estabelecimentos-bahia.csv'), header + row('55555555000155', 'LEGADO', 'BA'));
const names = [];
const params = {
uf: 'BA', cities: ['Salvador'],
segments: [{ name: 'restaurantes', cnaeCodes: ['5611201'], queries: [] }]
};
const ctx = { cnpjDir: dir, isCancelled: () => false, log() {}, emit() {}, endpoints: {} };
for await (const batch of collect(params, ctx)) names.push(...batch.leads.map((lead) => lead.company.name));
assert.deepEqual(names, ['BA EXATA']);
await fs.rm(path.join(dir, 'estabelecimentos-BA.csv'));
names.length = 0;
for await (const batch of collect(params, ctx)) names.push(...batch.leads.map((lead) => lead.company.name));
assert.deepEqual(names, ['LEGADO']);
});