import { describe, expect, it } from "vitest"; import { parseYouTubeUrl } from "@/lib/guides/youtube"; describe("YouTube URLs", () => { const videoId = "dQw4w9WgXcQ"; it.each([ `https://www.youtube.com/watch?v=${videoId}`, `https://m.youtube.com/watch?v=${videoId}&t=12`, `https://youtu.be/${videoId}?si=share`, `https://youtube.com/shorts/${videoId}`, `https://youtube.com/live/${videoId}`, `https://youtube.com/embed/${videoId}`, ])("normalizes %s", (url) => { expect(parseYouTubeUrl(url)).toEqual({ videoId, watchUrl: `https://www.youtube.com/watch?v=${videoId}`, embedUrl: `https://www.youtube-nocookie.com/embed/${videoId}`, }); }); it.each([ "", "not a url", "https://example.com/watch?v=dQw4w9WgXcQ", "https://youtube.example.com/watch?v=dQw4w9WgXcQ", "javascript:alert(1)", "https://youtube.com/watch?v=too-short", ])("rejects %s", (url) => { expect(parseYouTubeUrl(url)).toBeNull(); }); });