import { describe, expect, it } from "vitest"; import { calculateFreshness, freshnessStatus } from "@/domain/freshness"; describe("freshness scoring", () => { const asOf = new Date("2026-07-25T12:00:00Z"); it("returns a fresh score for recently received stock", () => { expect(calculateFreshness("2026-07-23T12:00:00Z", 10, asOf)).toMatchObject({ ageDays: 2, remainingDays: 8, score: 80, status: "fresh", }); }); it("marks the threshold states consistently", () => { expect(freshnessStatus(45)).toBe("watch"); expect(freshnessStatus(20)).toBe("at_risk"); expect(freshnessStatus(0)).toBe("expired"); }); it("never emits a negative freshness score", () => { expect(calculateFreshness("2026-07-01T12:00:00Z", 7, asOf).score).toBe(0); }); });