Expose schedule fields on class and invoice templates so SMS can include Jalali start date, weekdays, and hour range.
60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
const { describe, it } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const {
|
|
formatCourseTime,
|
|
formatClassDays,
|
|
formatClassStartDate,
|
|
buildClassScheduleContext
|
|
} = require('./classSchedule');
|
|
|
|
describe('class schedule SMS helpers', () => {
|
|
it('formats course time as an hour range', () => {
|
|
assert.equal(formatCourseTime('19:00', '21:00'), 'از 19 تا 21');
|
|
assert.equal(formatCourseTime('19:30', '21:00'), 'از 19:30 تا 21');
|
|
});
|
|
|
|
it('joins class weekdays in Persian week order', () => {
|
|
const atNoon = (year, month, day) => new Date(year, month - 1, day, 12, 0, 0);
|
|
const monday = atNoon(2026, 8, 17);
|
|
const saturday = atNoon(2026, 8, 15);
|
|
const wednesday = atNoon(2026, 8, 19);
|
|
|
|
assert.equal(
|
|
formatClassDays([
|
|
{ day: monday },
|
|
{ day: saturday },
|
|
{ day: wednesday },
|
|
{ day: saturday }
|
|
]),
|
|
'شنبه، دوشنبه و چهارشنبه'
|
|
);
|
|
});
|
|
|
|
it('builds start date, days, and course time from class and sessions', () => {
|
|
const atNoon = (year, month, day) => new Date(year, month - 1, day, 12, 0, 0);
|
|
const context = buildClassScheduleContext(
|
|
{ startDate: atNoon(2026, 8, 15) },
|
|
[
|
|
{ day: atNoon(2026, 8, 15), startTime: '19:00', endTime: '21:00' },
|
|
{ day: atNoon(2026, 8, 17), startTime: '19:00', endTime: '21:00' }
|
|
]
|
|
);
|
|
|
|
assert.ok(context.classStartDate);
|
|
assert.equal(context.classDays, 'شنبه و دوشنبه');
|
|
assert.equal(context.courseTime, 'از 19 تا 21');
|
|
});
|
|
|
|
it('uses the current session for course time when provided', () => {
|
|
const context = buildClassScheduleContext(
|
|
{ startDate: new Date('2026-08-15T00:00:00Z') },
|
|
[{ day: new Date('2026-08-15T00:00:00Z'), startTime: '19:00', endTime: '21:00' }],
|
|
{ startTime: '10:00', endTime: '12:00' }
|
|
);
|
|
|
|
assert.equal(context.courseTime, 'از 10 تا 12');
|
|
});
|
|
});
|