// Session 59 (work-order 2.3) — honest waiting states derive from the REAL
// cron schedule (UTC 14,19,22,1,3). A wrong time is a lie; keep HOURS_UTC in
// sync with snapshotScheduler's default.

const { HOURS_UTC, nextRunAt, nextRunLabelET } = require('../../web/src/lib/pipelineSchedule');
const { HOURS_UTC: BACKEND_HOURS } = require('../../src/snapshotScheduler');

describe('pipelineSchedule', () => {
  test('mirrors the backend default cron hours EXACTLY', () => {
    expect([...HOURS_UTC].sort((a, b) => a - b)).toEqual([...BACKEND_HOURS].sort((a, b) => a - b));
  });

  test('next run after 15:30 UTC is 19:00 UTC same day', () => {
    const now = new Date('2026-07-10T15:30:00Z');
    expect(nextRunAt(now).toISOString()).toBe('2026-07-10T19:00:00.000Z');
  });

  test('next run after 23:30 UTC rolls to 01:00 UTC next day', () => {
    const now = new Date('2026-07-10T23:30:00Z');
    expect(nextRunAt(now).toISOString()).toBe('2026-07-11T01:00:00.000Z');
  });

  test('label renders an ET clock time', () => {
    // 19:00 UTC = 3:00 PM ET in July (EDT).
    const label = nextRunLabelET(new Date('2026-07-10T15:30:00Z'));
    expect(label).toBe('~3:00 PM ET');
  });
});
