Files
COMERCIAL-GTI/tests/waba-template-library.test.mjs
T
Gustavo eaaf7af659 Add WABA outreach automation (Z-PRO integration)
Per-product message templates, official/não-oficial channel selection,
manual per-number sending, and a 20-minute internal scheduler for the
existing automatic outreach batch — all pre-existing local work being
committed as-is.
2026-08-03 13:14:09 -03:00

41 lines
1.3 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { openDb, getSetting, setSetting } from '../src/db.mjs';
import { listWabaTemplateLibrary, syncWabaTemplateLibrary } from '../src/outreach/waba-template-library.mjs';
test('listWabaTemplateLibrary retorna modelos padrao', () => {
const db = openDb(':memory:');
const templates = listWabaTemplateLibrary(db);
assert.ok(templates.some((template) => template.name === 'gti_inicio_atendimento_solicitado'));
db.close();
});
test('syncWabaTemplateLibrary importa templates de resposta do GChat', async () => {
const db = openDb(':memory:');
setSetting(db, 'gchat.templatesUrl', 'https://gchat.example/templates');
const originalFetch = global.fetch;
global.fetch = async () => ({
ok: true,
status: 200,
text: async () => JSON.stringify({
data: [{
name: 'novo_template',
language: 'pt_BR',
category: 'UTILITY',
components: [{ type: 'BODY', text: 'Ola {{1}}, assunto {{2}}' }]
}]
})
});
try {
const result = await syncWabaTemplateLibrary(db);
assert.equal(result.ok, true);
assert.equal(result.total, 1);
} finally {
global.fetch = originalFetch;
}
const saved = JSON.parse(getSetting(db, 'gchat.wabaTemplatesJson'));
assert.deepEqual(saved[0].variables, ['{empresa}', '{produto}']);
db.close();
});