64 lines
2.4 KiB
JavaScript
64 lines
2.4 KiB
JavaScript
// /components/settings/smsTemplateRender.test.js
|
|
'use strict';
|
|
|
|
const { describe, it } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { renderSmsText, SMS_TEMPLATE_DEFS } = require('./smsTemplates');
|
|
const { formatJalaliDate } = require('../../utils/jalaliDate');
|
|
|
|
describe('SMS Template Text Rendering', () => {
|
|
it('renders class plan to professor template correctly with variables', () => {
|
|
const def = SMS_TEMPLATE_DEFS.find((d) => d.key === 'classPlanProfessor');
|
|
assert.ok(def);
|
|
|
|
const slotValues = {
|
|
professorName: 'علی رضایی',
|
|
className: 'برنامهنویسی وب',
|
|
classDays: 'شنبه و دوشنبه',
|
|
classTimes: '۱۶:۰۰ الی ۱۸:۰۰',
|
|
classStartDate: '1405/06/01',
|
|
classEndDate: '1405/08/15'
|
|
};
|
|
|
|
const rendered = renderSmsText(def.defaultText, def.slots.map(s => ({ slot: s.key, name: s.defaultName })), slotValues);
|
|
assert.match(rendered, /استاد علی رضایی/);
|
|
assert.match(rendered, /برنامهنویسی وب/);
|
|
assert.match(rendered, /شنبه و دوشنبه/);
|
|
assert.match(rendered, /۱۶:۰۰ الی ۱۸:۰۰/);
|
|
assert.match(rendered, /1405\/06\/01/);
|
|
assert.match(rendered, /1405\/08\/15/);
|
|
});
|
|
|
|
it('renders sessionHolding template correctly', () => {
|
|
const def = SMS_TEMPLATE_DEFS.find((d) => d.key === 'sessionHolding');
|
|
assert.ok(def);
|
|
|
|
const slotValues = {
|
|
fullName: 'سارا محمدی',
|
|
topic: 'مقدمهای بر پایگاه داده',
|
|
className: 'کلاس بکاند',
|
|
sessionDate: '1405/06/10',
|
|
classTime: '17:00'
|
|
};
|
|
|
|
const rendered = renderSmsText(def.defaultText, [
|
|
{ slot: 'fullName', name: 'FULLNAME' },
|
|
{ slot: 'topic', name: 'TOPIC' },
|
|
{ slot: 'className', name: 'CLASSNAME' },
|
|
{ slot: 'sessionDate', name: 'SESSIONDATE' },
|
|
{ slot: 'classTime', name: 'CLASSTIME' }
|
|
], slotValues);
|
|
|
|
assert.match(rendered, /سارا محمدی عزیز/);
|
|
assert.match(rendered, /مقدمهای بر پایگاه داده/);
|
|
assert.match(rendered, /کلاس بکاند/);
|
|
assert.match(rendered, /1405\/06\/10/);
|
|
assert.match(rendered, /17:00/);
|
|
});
|
|
|
|
it('formats dates into Jalali correctly', () => {
|
|
const formatted = formatJalaliDate('2026-08-24T00:00:00.000Z');
|
|
assert.equal(formatted, '1405/06/02');
|
|
});
|
|
});
|