33 lines
1.7 KiB
JavaScript
33 lines
1.7 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const { DEFAULT_ACCOUNT_EMAIL_TEMPLATES, formatAccountEmailExpiry, normalizeOtpEmailBody, renderAccountEmailTemplate } = require('../src/data/account-email-templates');
|
|
|
|
test('account email expiry values render with singular and plural units', () => {
|
|
assert.equal(formatAccountEmailExpiry(1, 'minutes'), '1 minute');
|
|
assert.equal(formatAccountEmailExpiry(30, 'minutes'), '30 minutes');
|
|
assert.equal(formatAccountEmailExpiry(24, 'hours'), '24 hours');
|
|
assert.equal(renderAccountEmailTemplate('Subject [[expiry_time]]', 'Expires in [[expiry_time]].', { expiry_time: '45 minutes' }).text, 'Expires in 45 minutes.');
|
|
});
|
|
|
|
test('default account email templates render one-time verification codes', () => {
|
|
const rendered = renderAccountEmailTemplate('Subject', DEFAULT_ACCOUNT_EMAIL_TEMPLATES.verificationBody, {
|
|
display_name: 'Alex',
|
|
otp: '123456',
|
|
expiry_time: '30 minutes',
|
|
});
|
|
|
|
assert.match(rendered.html, /<strong>Alex<\/strong>/);
|
|
assert.match(rendered.html, /verification code[\s\S]*<strong>123456<\/strong>/);
|
|
assert.match(rendered.html, /This code expires in <em>30 minutes<\/em>\./);
|
|
assert.doesNotMatch(rendered.html, /\[\[(?:action_button|url|otp)\]\]/);
|
|
});
|
|
|
|
test('legacy link email templates normalize to OTP wording and placeholders', () => {
|
|
const normalized = normalizeOtpEmailBody('Click [[action_button]]. This link expires in [[expiry_time]]. Verify: [[url]]');
|
|
const rendered = renderAccountEmailTemplate('Subject', normalized, { otp: '321654', expiry_time: '5 minutes' });
|
|
|
|
assert.match(rendered.text, /verification code/);
|
|
assert.match(rendered.text, /321654/);
|
|
assert.doesNotMatch(rendered.text, /\[\[(?:action_button|url|otp)\]\]/);
|
|
}); |