package services import ( "strings" "testing" ) func TestExtractVideoPreviewURLFindsEnvatoPreview(t *testing.T) { html := `` got := firstNonEmpty(extractJSONLDValue(html, "contentUrl"), extractVideoPreviewURL(html)) want := "https://video-previews.elements.envatousercontent.com/ad0a3abc-7eb0-4075-8f68-8198f9a08777/watermarked_preview/watermarked_preview.mp4" if got != want { t.Fatalf("expected %q, got %q", want, got) } } func TestDeriveEnvatoPreviewFromThumbnail(t *testing.T) { thumb := "https://elements-resized.envatousercontent.com/elements-video-cover-images/ad0a3abc-7eb0-4075-8f68-8198f9a08777/video_preview/video_preview_0000.jpg?w=1200&h=630" got := deriveEnvatoPreviewFromThumbnail(thumb) want := "https://elements-resized.envatousercontent.com/elements-video-cover-images/ad0a3abc-7eb0-4075-8f68-8198f9a08777/watermarked_preview/watermarked_preview.mp4" if got != want { t.Fatalf("expected %q, got %q", want, got) } } func TestIsUsefulGoogleVideoResultRejectsMusicResults(t *testing.T) { result := SearchResult{ Title: "Couple Friendly Sad Bgm Movie Best Bgm", Link: "https://www.youtube.com/watch?v=LGP4wiXSw8c", Snippet: "romantic bgm soundtrack", } if isUsefulGoogleVideoResult(result) { t.Fatal("expected bgm/music result to be rejected") } } func TestExtractVideoObjectJSONLD(t *testing.T) { html := `` meta := extractVideoObjectJSONLD(html) if meta.Name != "Smiling Man and Woman Waving at Camera" { t.Fatalf("unexpected name: %#v", meta) } if meta.ContentURL == "" || meta.ThumbnailURL == "" || meta.Description == "" { t.Fatalf("expected full video object metadata, got %#v", meta) } } func TestCleanArtgridTitle(t *testing.T) { got := cleanArtgridTitle("movie film moving slowly from a reel by Arthur Cauty | Royalty Free Stock Footage – Artgrid.io") want := "movie film moving slowly from a reel" if got != want { t.Fatalf("expected %q, got %q", want, got) } } func TestCanonicalizeArtgridLinkFromArtlist(t *testing.T) { got := canonicalizeArtgridLink("https://artlist.io/stock-footage/clip/movie-film-moving-slowly-from-a-reel/114756") want := "https://artgrid.io/clip/114756/movie-film-moving-slowly-from-a-reel" if got != want { t.Fatalf("expected %q, got %q", want, got) } } func TestIsRenderableArtgridResultAcceptsArtlistCanonical(t *testing.T) { if !isRenderableArtgridResult(SearchResult{Link: "https://artlist.io/stock-footage/clip/movie-film-moving-slowly-from-a-reel/114756"}) { t.Fatal("expected artlist canonical clip URL to be accepted for Artgrid collector") } } func TestBuildArtgridQueriesIncludesArtlistCanonicalDomain(t *testing.T) { queries := buildArtgridQueries("friendly couple") found := false for _, query := range queries { if strings.Contains(query, "site:artlist.io/stock-footage/clip/") { found = true break } } if !found { t.Fatal("expected Artgrid queries to include artlist canonical domain") } } func TestIsMatchingArtgridClipPageRejectsHomepage(t *testing.T) { html := `
` if isMatchingArtgridClipPage(html, "114756") { t.Fatal("expected generic Artgrid homepage HTML to be rejected as a clip page") } } func TestGeminiCandidateLimitNeverExceedsCandidates(t *testing.T) { if got := GeminiCandidateLimit(9); got != 9 { t.Fatalf("expected Gemini limit to stay within candidate count, got %d", got) } }