Files
COMERCIAL-GTI/tests/waba-template-library.test.mjs
T
Gustavo 4f736562f3 Carry over pre-existing WABA outreach automation WIP
This work already existed uncommitted in the main working tree (not
authored by this branch) and is required as a runtime dependency for the
campaign outreach port (zpro-client, templates, outreach routes/UI). Copied
in as-is, untouched, so this feature branch has a working baseline; the
original uncommitted state in the main checkout is left exactly as it was.
2026-08-01 10:12:25 -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();
});