import { describe, expect, it } from "vitest";
import { cloudinaryPublicIdFromUrl } from "../cloudinary.server";

describe("cloudinaryPublicIdFromUrl", () => {
  it("extracts avatar public IDs", () => {
    expect(
      cloudinaryPublicIdFromUrl("https://res.cloudinary.com/demo/image/upload/v123/avatars/team-1.jpg")
    ).toBe("avatars/team-1");
  });

  it("extracts sport icon public IDs", () => {
    expect(
      cloudinaryPublicIdFromUrl("https://res.cloudinary.com/demo/image/upload/v123/sports-icons/nfl.svg")
    ).toBe("sports-icons/nfl");
  });

  it("ignores non-managed URLs", () => {
    expect(cloudinaryPublicIdFromUrl("/sports-icons/nfl.svg")).toBeNull();
    expect(cloudinaryPublicIdFromUrl(null)).toBeNull();
  });
});
