import { describe, expect, it } from "vitest";
import { isResultPending } from "@/lib/clean-logs/result-pending";
import { RESULT_WAIT_MINUTES } from "@/lib/config";
/**
* ★結果待ち(D-173。ユーザー判断 2026-10-07)の期待値表★ — 表1(予定 02:00〜03:00、W=120)。
* ★表は正。変えないこと★。
*/
const at = (hm: string) => new Date(`2026-10-07T${hm}:00+09:00`);
const START = at("02:00");
const END = at("03:00");
describe("isResultPending(表1。予定 02:00〜03:00、W=120)", () => {
it.each([
// [#, now, hasReport, endAt, 期待]
["P1", "04:00", true, END, false], // レポートあり
["P2", "01:59", false, END, false], // 未来の予定は対象外
["P3", "02:00", false, END, true], // 開始ちょうど(start > now ではない)
["P4", "02:30", false, END, true], // 清掃中
["P5", "04:59", false, END, true],
["P6", "05:00", false, END, false], // 終了+120分ちょうどで確定(now < end+W の境界)
["P7", "05:01", false, END, false],
["P8", "02:30", false, null, true], // endAt が null → start+120 で判定
["P9", "04:30", false, null, false], // 02:00+120=04:00 を過ぎた
] as const)("%s: now=%s report=%s", (_id, now, hasReport, endAt, expected) => {
expect(
isResultPending({ startAt: START, endAt, now: at(now), hasReport, waitMinutes: 120 }),
).toBe(expected);
});
it("waitMinutes 省略時は RESULT_WAIT_MINUTES(一旦120分)を使う", () => {
expect(RESULT_WAIT_MINUTES).toBe(120);
expect(isResultPending({ startAt: START, endAt: END, now: at("04:59"), hasReport: false })).toBe(true);
expect(isResultPending({ startAt: START, endAt: END, now: at("05:00"), hasReport: false })).toBe(false);
});
it("waitMinutes を変えると境界も動く(設定で変えられる)", () => {
expect(
isResultPending({ startAt: START, endAt: END, now: at("03:29"), hasReport: false, waitMinutes: 30 }),
).toBe(true);
expect(
isResultPending({ startAt: START, endAt: END, now: at("03:30"), hasReport: false, waitMinutes: 30 }),
).toBe(false);
});
});