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
+26
View File
@@ -0,0 +1,26 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { openDb } from '../src/db.mjs';
import { createJobLease } from '../src/jobs/lease.mjs';
test('lease marca running e atualiza heartbeat ate cleanup', () => {
const db = openDb(':memory:');
const id = Number(db.prepare("INSERT INTO exports (tipo, status) VALUES ('excel', 'pending')").run().lastInsertRowid);
let tick;
let cleared = false;
const lease = createJobLease({
db, table: 'exports', id, ownerToken: 'owner-1', pid: 123,
setInterval: (fn) => { tick = fn; return 7; },
clearInterval: (timer) => { assert.equal(timer, 7); cleared = true; }
});
const first = db.prepare('SELECT status, pid, owner_token, heartbeat_at FROM exports WHERE id = ?').get(id);
assert.equal(first.status, 'running');
assert.equal(first.pid, 123);
assert.equal(first.owner_token, 'owner-1');
db.prepare("UPDATE exports SET heartbeat_at = '2000-01-01 00:00:00' WHERE id = ?").run(id);
tick();
assert.notEqual(db.prepare('SELECT heartbeat_at FROM exports WHERE id = ?').get(id).heartbeat_at, '2000-01-01 00:00:00');
lease.close();
assert.equal(cleared, true);
db.close();
});