import { describe, expect, it } from "vitest"; import { nextSaturdayStart, wallTimeToInstant, zonedDateKey, zonedParts, } from "@/lib/intelligence/fridayTime"; // 2026-10-10 is a Saturday, so: Oct 6 = Tuesday, Oct 9 = Friday, Oct 11 = Sunday. const et = (y: number, m: number, d: number, h: number, min = 0): Date => wallTimeToInstant(y, m, d, h, min); describe("nextSaturdayStart", () => { it("returns the coming Saturday for every day of the week before 20:00", () => { const cases: Array<[Date, string]> = [ [et(2026, 10, 6, 10), "2026-10-10"], // Tuesday -> the same coming Saturday [et(2026, 10, 9, 23), "2026-10-10"], // Friday night [et(2026, 10, 11, 0, 30), "2026-10-17"], // Sunday just after midnight ]; for (const [now, expectedKey] of cases) { const result = nextSaturdayStart(now); expect(zonedDateKey(result)).toBe(expectedKey); expect(zonedParts(result).hour).toBe(20); expect(result.getTime()).toBeGreaterThan(now.getTime()); } }); it("uses today when it is Saturday but 20:00 has not passed yet", () => { const result = nextSaturdayStart(et(2026, 10, 10, 15)); expect(zonedDateKey(result)).toBe("2026-10-10"); expect(zonedParts(result).hour).toBe(20); }); it("rolls to the following Saturday once today's 20:00 has passed", () => { const result = nextSaturdayStart(et(2026, 10, 10, 21)); expect(zonedDateKey(result)).toBe("2026-10-17"); expect(zonedParts(result).hour).toBe(20); }); it("never skips a week when today is midweek", () => { // Regression: the old "+7" always landed on the Saturday AFTER the coming // one, so a Tuesday generation jumped 11 days out instead of 4. const now = et(2026, 10, 6, 12); const daysOut = (nextSaturdayStart(now).getTime() - now.getTime()) / (24 * 60 * 60 * 1000); expect(daysOut).toBeLessThan(7); }); });