import { describe, expect, it } from "vitest";
import { cleanLogAdviceUrl } from "@/lib/clean-logs/advice-url";

/** 表U — `cleanLogAdviceUrl()`（指示書BI §4） */
describe("cleanLogAdviceUrl", () => {
  it("U-1: 予定ありで id が数値 → /api/clean-logs/{id}/advice", () => {
    expect(
      cleanLogAdviceUrl({ id: 54, unscheduled: false, report_id: null })
    ).toBe("/api/clean-logs/54/advice");
  });

  it("U-2: 予定なしで report_id あり → unscheduled 入口", () => {
    expect(
      cleanLogAdviceUrl({
        id: null,
        unscheduled: true,
        report_id: "9200000000000000002",
      })
    ).toBe("/api/clean-logs/unscheduled/9200000000000000002/advice");
  });

  it("U-3: report_id に特殊文字 → encodeURIComponent", () => {
    expect(
      cleanLogAdviceUrl({
        id: null,
        unscheduled: true,
        report_id: "a/b c",
      })
    ).toBe("/api/clean-logs/unscheduled/a%2Fb%20c/advice");
  });

  it("U-4: 予定ありなのに id が null → null", () => {
    expect(
      cleanLogAdviceUrl({ id: null, unscheduled: false, report_id: null })
    ).toBeNull();
  });

  it("U-5: 予定なしなのに report_id が null → null", () => {
    expect(
      cleanLogAdviceUrl({ id: null, unscheduled: true, report_id: null })
    ).toBeNull();
  });
});
