import { describe, expect, it } from "vitest";
import { normalizeMediaUrl } from "../src/lib/media";

describe("normalizeMediaUrl", () => {
  it("normalizes YouTube watch urls", () => {
    const media = normalizeMediaUrl("https://www.youtube.com/watch?v=abc123");
    expect(media.provider).toBe("YOUTUBE");
    expect(media.playbackUrl).toContain("/embed/abc123");
    expect(media.thumbnailUrl).toContain("img.youtube.com/vi/abc123");
  });

  it("normalizes YouTube shorts urls", () => {
    const media = normalizeMediaUrl("https://www.youtube.com/shorts/short123");
    expect(media.provider).toBe("YOUTUBE");
    expect(media.playbackUrl).toContain("/embed/short123");
  });

  it("normalizes Twitch channels", () => {
    const media = normalizeMediaUrl("https://www.twitch.tv/example");
    expect(media.provider).toBe("TWITCH");
    expect(media.playbackUrl).toContain("channel=example");
  });

  it("normalizes Twitch VODs", () => {
    const media = normalizeMediaUrl("https://www.twitch.tv/videos/12345");
    expect(media.provider).toBe("TWITCH");
    expect(media.playbackUrl).toContain("video=12345");
  });

  it("detects direct video sources", () => {
    const media = normalizeMediaUrl("https://cdn.example.com/video.mp4");
    expect(media.provider).toBe("DIRECT");
    expect(media.playbackUrl).toBe("https://cdn.example.com/video.mp4");
  });
});
