Files
COMERCIAL-GTI/gti-maquina-comercial/tests/waba-template-library.test.mjs
T
GustavoandClaude Sonnet 5 f5af038e19 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: 93ca82979e
git-subtree-split: b77484946f
2026-09-28 15:50:08 -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();
});