// tests/callReport.businessWindow.test.js import test from 'node:test'; import assert from 'node:assert/strict'; import { DateTime } from 'luxon'; import { computeBusinessWindow, parseReportDateArg, } from '../services/callReport/businessWindow.js'; test('parseReportDateArg defaults to yesterday', () => { const now = DateTime.fromISO('2026-07-24T15:00:00', { zone: 'America/New_York' }).toJSDate(); const p = parseReportDateArg(null, 'America/New_York', now); assert.equal(p.label, '2026-07-23'); assert.equal(p.mode, 'fullDay'); }); test('computeBusinessWindow full day yesterday 9-9', () => { const now = DateTime.fromISO('2026-07-24T12:00:00', { zone: 'America/New_York' }).toJSDate(); const w = computeBusinessWindow({ timeZone: 'America/New_York', dateArg: 'yesterday', now, }); assert.equal(w.ready, true); assert.equal(w.label, '2026-07-23'); const start = DateTime.fromISO(w.startTime, { zone: 'utc' }); const end = DateTime.fromISO(w.endTime, { zone: 'utc' }); const startLocal = start.setZone('America/New_York'); const endLocal = end.setZone('America/New_York'); assert.equal(startLocal.hour, 9); assert.equal(endLocal.hour, 21); }); test('computeBusinessWindow today ends at now minus lag', () => { const now = DateTime.fromISO('2026-07-24T14:00:00', { zone: 'America/New_York' }).toJSDate(); const w = computeBusinessWindow({ timeZone: 'America/New_York', dateArg: 'today', now, }); assert.equal(w.ready, true); assert.equal(w.mode, 'today'); const endMs = new Date(w.endTime).getTime(); assert.ok(endMs <= now.getTime() - 5 * 60 * 1000 + 2000); const startLocal = DateTime.fromISO(w.startTime).setZone('America/New_York'); assert.equal(startLocal.hour, 9); }); test('computeBusinessWindow today before 9am not ready', () => { const now = DateTime.fromISO('2026-07-24T08:00:00', { zone: 'America/New_York' }).toJSDate(); const w = computeBusinessWindow({ timeZone: 'America/New_York', dateArg: 'today', now, }); assert.equal(w.ready, false); });