import { TRPCError } from "@trpc/server";
import { describe, expect, it } from "vitest";
import {
  assertTimelineDateRangeValid,
  validateTimelineAllocationDateRanges,
} from "../router/timeline-allocation-mutation-support.js";

describe("timeline allocation mutation support", () => {
  it("rejects inverted date ranges", () => {
    expect(() =>
      assertTimelineDateRangeValid(
        new Date("2026-04-10T00:00:00.000Z"),
        new Date("2026-04-09T00:00:00.000Z"),
      )).toThrowError(TRPCError);
  });

  it("validates date ranges in bulk", () => {
    expect(() =>
      validateTimelineAllocationDateRanges([
        {
          startDate: new Date("2026-04-10T00:00:00.000Z"),
          endDate: new Date("2026-04-11T00:00:00.000Z"),
        },
        {
          startDate: new Date("2026-04-12T00:00:00.000Z"),
          endDate: new Date("2026-04-09T00:00:00.000Z"),
        },
      ])).toThrowError(TRPCError);
  });
});
