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:93ca82979egit-subtree-split:b77484946f
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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();
|
||||
});
|
||||
Reference in New Issue
Block a user