import { describe, expect, it } from "vitest";
import { computeModule3Summary, getViabilityLevel } from "@/lib/licitations/module3";

describe("module3 helpers", () => {
  it("classifies viability levels by score threshold", () => {
    expect(getViabilityLevel(80)).toBe("alta");
    expect(getViabilityLevel(55)).toBe("media");
    expect(getViabilityLevel(10)).toBe("baja");
  });

  it("computes summary KPIs including recent opportunities", () => {
    const now = new Date("2026-03-21T12:00:00.000Z");
    const summary = computeModule3Summary(
      9,
      [
        { id: "a", score: 80, publishDate: "2026-03-20T09:00:00.000Z" },
        { id: "b", score: 55, publishDate: "2026-03-10T09:00:00.000Z" },
        { id: "c", score: 20, publishDate: "2026-03-21T09:00:00.000Z" },
      ],
      now,
    );

    expect(summary.opportunities).toBe(9);
    expect(summary.highViability).toBe(1);
    expect(summary.mediumViability).toBe(1);
    expect(summary.averageCompatibility).toBe(52);
    expect(summary.newToReview).toBe(2);
  });
});
