import { describe, expect, it } from "vitest"; import { DELIVERY_CONFIG_DEFAULT, applyTokens, nextPackageName, tidyPath } from "./deliveries"; const BASE = "260901_Delivery"; describe("nextPackageName", () => { it("uses the bare base for the first package of the day", () => { expect(nextPackageName(BASE, [])).toBe(BASE); }); it("suffixes later packages sharing the base", () => { expect(nextPackageName(BASE, [BASE])).toBe(`${BASE}_02`); expect(nextPackageName(BASE, [BASE, `${BASE}_02`])).toBe(`${BASE}_03`); }); it("never reuses a number after a gap", () => { expect(nextPackageName(BASE, [BASE, `${BASE}_02`, `${BASE}_04`])).toBe(`${BASE}_05`); }); it("ignores names that only share a prefix", () => { expect(nextPackageName(BASE, [`${BASE}_final`, "260902_Delivery"])).toBe(BASE); }); }); describe("delivery layout", () => { const tokens = { deliveryRoot: "//SAN/DELIVERY", showId: "ACME", episode: "101", packageName: BASE, }; it("separates shows so two shows' episode 101 cannot collide", () => { const acme = applyTokens(DELIVERY_CONFIG_DEFAULT.layout.packageDir, tokens); const other = applyTokens(DELIVERY_CONFIG_DEFAULT.layout.packageDir, { ...tokens, showId: "BRAVO" }); expect(acme).toBe("//SAN/DELIVERY/ACME/101/260901_Delivery"); expect(other).not.toBe(acme); }); it("puts producer reviews under the show too", () => { expect(applyTokens(DELIVERY_CONFIG_DEFAULT.layout.reviewDir, tokens)).toBe( "//SAN/DELIVERY/ACME/PRODUCER_REVIEWS/260901_Delivery" ); }); }); describe("tidyPath", () => { it("drops the empty segment a non-episodic show leaves behind", () => { const raw = applyTokens(DELIVERY_CONFIG_DEFAULT.layout.packageDir, { deliveryRoot: "//SAN/DELIVERY", showId: "ACME", episode: "", packageName: BASE, }); expect(tidyPath(raw)).toBe("//SAN/DELIVERY/ACME/260901_Delivery"); }); it("keeps the UNC root intact", () => { expect(tidyPath("//SAN/DELIVERY/ACME")).toBe("//SAN/DELIVERY/ACME"); }); it("leaves a well-formed path alone", () => { expect(tidyPath("V:/DELIVERY/ACME/101/x")).toBe("V:/DELIVERY/ACME/101/x"); }); });