'use strict'; const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { formatCourseTime, formatClassDays, formatClassStartDate, formatClassDaysFromIndexes, normalizeWeekdays, normalizeClockTime, 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'); }); it('prefers stored class days and times over inferred sessions', () => { const atNoon = (year, month, day) => new Date(year, month - 1, day, 12, 0, 0); const context = buildClassScheduleContext( { startDate: atNoon(2026, 8, 15), days: [6, 1], startTime: '18:00', endTime: '20:00' }, [ { day: atNoon(2026, 8, 16), startTime: '19:00', endTime: '21:00' } ] ); assert.equal(context.classDays, 'شنبه و دوشنبه'); assert.equal(context.courseTime, 'از 18 تا 20'); }); }); describe('class weekday and time normalization', () => { it('deduplicates weekdays and sorts them in Iran week order', () => { assert.deepEqual(normalizeWeekdays([1, 6, 1, 3, 9, '2']), [6, 1, 2, 3]); }); it('normalizes clock times to HH:mm', () => { assert.equal(normalizeClockTime('19'), '19:00'); assert.equal(normalizeClockTime('9:5'), '09:05'); assert.equal(normalizeClockTime('19:00'), '19:00'); assert.equal(normalizeClockTime('25:00'), ''); assert.equal(normalizeClockTime(''), ''); }); it('formats stored weekday indexes as Persian day names', () => { assert.equal(formatClassDaysFromIndexes([1, 6]), 'شنبه و دوشنبه'); }); });