Files
gameno-api/components/settings/smsTemplates.test.js
T
kavehhn 72be01fee3 feat: add messaging toggles, password reset SMS, and payment discounts
Allow SuperAdmin to disable SMS, email, and bot from dashboard settings on top of env flags. Add admin password reset with credentials SMS, plus payment discounts, notes, and payable amount handling.
2026-08-16 06:58:08 +03:30

80 lines
3.0 KiB
JavaScript

'use strict';
const { describe, it } = require('node:test');
const assert = require('node:assert/strict');
const {
SMS_TEMPLATE_DEFS,
normalizeStoredEntry,
resolveVariablesList,
parseIncomingVariables,
mergeTemplateEntry
} = require('./smsTemplates');
const invoiceDef = SMS_TEMPLATE_DEFS.find((def) => def.key === 'invoiceCreated');
const threeInvoiceVars = [
{ slot: 'amount', name: 'PAYMENT_PRICE' },
{ slot: 'fullName', name: 'FULLNAME' },
{ slot: 'course', name: 'COURSE' }
];
describe('SMS template variables', () => {
it('keeps all invoiceCreated variables when stored as an array', () => {
const stored = normalizeStoredEntry({
templateId: '111',
variables: threeInvoiceVars
}, invoiceDef);
const resolved = resolveVariablesList(invoiceDef, stored.variables);
assert.equal(resolved.length, 3);
assert.deepEqual(resolved.map((item) => item.slot), ['amount', 'fullName', 'course']);
assert.deepEqual(resolved.map((item) => item.name), ['PAYMENT_PRICE', 'FULLNAME', 'COURSE']);
});
it('keeps all invoiceCreated variables when an array was stored as a numeric object', () => {
const stored = normalizeStoredEntry({
templateId: '111',
variables: {
0: { slot: 'amount', name: 'PAYMENT_PRICE' },
1: { slot: 'fullName', name: 'FULLNAME' },
2: { slot: 'course', name: 'COURSE' }
}
}, invoiceDef);
const resolved = resolveVariablesList(invoiceDef, stored.variables);
assert.equal(resolved.length, 3);
assert.deepEqual(resolved.map((item) => item.slot), ['amount', 'fullName', 'course']);
});
it('replaces a legacy single-slot map with every incoming invoiceCreated variable', () => {
const incoming = parseIncomingVariables(threeInvoiceVars, invoiceDef);
const merged = mergeTemplateEntry(
invoiceDef,
{ templateId: '111', variables: { amount: 'PAYMENT_PRICE' } },
{ templateId: '111', variables: incoming }
);
assert.equal(merged.variables.length, 3);
assert.deepEqual(merged.variables.map((item) => item.slot), ['amount', 'fullName', 'course']);
assert.deepEqual(merged.variables.map((item) => item.name), ['PAYMENT_PRICE', 'FULLNAME', 'COURSE']);
});
it('exposes class start date, class days, and course time slots', () => {
const expected = ['classStartDate', 'classDays', 'courseTime'];
for (const key of ['classRegistered', 'classReminder', 'invoiceCreated']) {
const def = SMS_TEMPLATE_DEFS.find((item) => item.key === key);
const slots = (def?.slots || []).map((slot) => slot.key);
for (const slot of expected) {
assert.ok(slots.includes(slot), `${key} is missing slot ${slot}`);
}
}
});
it('keeps username and password slots on the accountCreated template', () => {
const def = SMS_TEMPLATE_DEFS.find((item) => item.key === 'accountCreated');
const slots = (def?.slots || []).map((slot) => slot.key);
assert.ok(slots.includes('username'));
assert.ok(slots.includes('password'));
});
});