import { describe, expect, it } from "vitest"; import { instructionImportObjectKey, instructionImportShipmentsHash, } from "@/services/import/instruction-import-log"; describe("instruction-import-log", () => { it("builds unique object keys with kind prefix (no raw ISO collide)", () => { expect( instructionImportObjectKey({ kind: "work_order", instructionId: "wo-1", display: "YT2604021091", }), ).toBe("WO/YT2604021091"); expect( instructionImportObjectKey({ kind: "do_upload", instructionId: "do-1", display: "TCNU4412465", }), ).toBe("DO/TCNU4412465"); expect( instructionImportObjectKey({ kind: "transfer", instructionId: "xf-1", display: "ABCD1234567", }), ).toBe("XF/ABCD1234567"); }); it("same instruction id shares shipments hash; different ids differ", () => { const a = instructionImportShipmentsHash("unit-a"); const b = instructionImportShipmentsHash("unit-b"); expect(a).toHaveLength(64); expect(a).not.toBe(b); expect(instructionImportShipmentsHash("unit-a")).toBe(a); }); it("falls back to instruction id when display empty", () => { expect( instructionImportObjectKey({ kind: "work_order", instructionId: "seg-body-2", display: "", }), ).toBe("WO/seg-body-2"); }); it("stable object key length within 50", () => { const key = instructionImportObjectKey({ kind: "work_order", instructionId: "x".repeat(80), display: "Y".repeat(80), }); expect(key.length).toBeLessThanOrEqual(50); expect(key.startsWith("WO/")).toBe(true); }); });