Files
CRM_Montzar/apps/api/test/birthdays.test.ts
T
MahdiandCursor 13ee70764b feat: show this month's birthdays and send a greeting SMS
Each owner sees their customers born this Jalali month and can text a custom greeting.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-13 19:55:11 +03:30

53 lines
2.0 KiB
TypeScript

import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { toGregorian } from '../src/common/jalali';
import {
BIRTHDAY_SMS_DEFAULT,
fillBirthdaySmsText,
selectMonthBirthdays,
} from '../src/contacts/birthday-month';
function birth(jy: number, jm: number, jd: number) {
const g = toGregorian(jy, jm, jd);
return new Date(Date.UTC(g.gy, g.gm - 1, g.gd, 12, 0, 0));
}
const now = new Date('2026-10-08T08:00:00Z');
describe('تولدهای ماه شمسی', () => {
it('فقط متولدین همین ماه را می‌آورد و روزهای مانده را جلوتر می‌گذارد', () => {
const result = selectMonthBirthdays(
[
{ id: 'soon', firstName: 'آیدا', lastName: 'کریمی', mobile: '09120000000', birthDate: birth(1370, 7, 20) },
{ id: 'past', firstName: 'رضا', lastName: 'بهرامی', mobile: null, birthDate: birth(1360, 7, 2) },
{ id: 'other', firstName: 'پریسا', lastName: 'قاسمی', mobile: '09121111111', birthDate: birth(1369, 6, 30) },
{ id: 'today', firstName: 'سارا', lastName: 'محمدی', mobile: '09123333333', birthDate: birth(1375, 7, 16) },
],
now,
2,
);
assert.equal(result.month, 7);
assert.equal(result.monthName, 'مهر');
assert.equal(result.today, 16);
assert.equal(result.total, 3);
assert.deepEqual(
result.preview.map((row) => row.id),
['today', 'soon'],
);
assert.deepEqual(
result.items.map((row) => row.id),
['today', 'soon', 'past'],
);
assert.equal(result.items.find((row) => row.id === 'past')?.mobile, null);
});
it('نام را در متن پیامک می‌گذارد', () => {
assert.equal(
fillBirthdaySmsText(BIRTHDAY_SMS_DEFAULT, 'آیدا', 'کریمی'),
'آیدا کریمی عزیز، تولدتان مبارک.',
);
assert.equal(fillBirthdaySmsText(' سلام {نام} ', 'آیدا', ''), 'سلام آیدا');
});
});