import { describe, expect, it } from "vitest"; import { colonyIdsOfBulkInput, withoutColonies } from "./bulk-input"; const TREATMENT = { date: "2026-10-14", product: "Oxuvar", colonyIds: ["a", "b", "c"] }; const VARROA = { date: "2026-10-14", method: "NATURAL_MITE_FALL", entries: [ { colonyId: "a", miteCount: 4 }, { colonyId: "b", miteCount: 9 }, ], }; describe("colonyIdsOfBulkInput", () => { it("lists the colonies of every kind", () => { expect(colonyIdsOfBulkInput("treatments", TREATMENT)).toEqual(["a", "b", "c"]); expect(colonyIdsOfBulkInput("feedings", TREATMENT)).toEqual(["a", "b", "c"]); expect(colonyIdsOfBulkInput("varroa", VARROA)).toEqual(["a", "b"]); }); it("is empty for input of an unknown shape", () => { expect(colonyIdsOfBulkInput("treatments", null)).toEqual([]); expect(colonyIdsOfBulkInput("varroa", { entries: "x" })).toEqual([]); }); }); describe("withoutColonies", () => { it("drops the colonies and keeps every shared field", () => { expect(withoutColonies("treatments", TREATMENT, ["b"])).toEqual({ ...TREATMENT, colonyIds: ["a", "c"], }); }); it("drops a varroa colony together with its own count", () => { expect(withoutColonies("varroa", VARROA, ["a"])).toEqual({ ...VARROA, entries: [{ colonyId: "b", miteCount: 9 }], }); }); it("does not change the input", () => { const before = structuredClone(TREATMENT); withoutColonies("treatments", TREATMENT, ["a"]); expect(TREATMENT).toEqual(before); }); });