import { describe, expect, it } from "vitest";
import { orphanUploadFolderName } from "@/lib/orphan-upload-path";

describe("orphan upload folder names", () => {
  it("uses the Arabic orphan name and case number instead of the UUID", () => {
    const folder = orphanUploadFolderName({
      orphanId: "1112824f-0357-46be-8ab3-f724c59f4c82",
      orphanName: "زينب محمد عبدالفراج عمران",
      caseNumber: "ORP-000001"
    });

    expect(folder).toBe("زينب محمد عبدالفراج عمران - ORP-000001");
    expect(folder).not.toContain("1112824f");
  });

  it("removes characters that could escape or invalidate the folder", () => {
    const folder = orphanUploadFolderName({
      orphanId: "e11cd76f-3a4c-47d8-9c01-db388bf81838",
      orphanName: "ريان / علي: الطاهر.",
      caseNumber: "ORP-000002"
    });

    expect(folder).toBe("ريان - علي- الطاهر - ORP-000002");
    expect(folder).not.toMatch(/[<>:"/\\|?*]/);
  });

  it("rejects an invalid case number", () => {
    expect(() =>
      orphanUploadFolderName({
        orphanId: "1112824f-0357-46be-8ab3-f724c59f4c82",
        orphanName: "زينب محمد",
        caseNumber: "../ORP-1"
      })
    ).toThrow("Invalid orphan case number");
  });
});
