diff --git a/internal/services/url_metadata_service_test.go b/internal/services/url_metadata_service_test.go index e1a86c2..b92305d 100644 --- a/internal/services/url_metadata_service_test.go +++ b/internal/services/url_metadata_service_test.go @@ -539,239 +539,6 @@ func TestExtractFromTitleTag(t *testing.T) { } } -func TestExtractFromOpenGraph(t *testing.T) { - svc := NewURLMetadataService() - - tests := []struct { - name string - html string - expected string - }{ - { - name: "simple og:title", - html: ``, - expected: "Open Graph Title", - }, - { - name: "og:title with whitespace", - html: ``, - expected: "Open Graph Title", - }, - - { - name: "empty og:title", - html: ``, - expected: "", - }, - { - name: "whitespace only og:title", - html: ``, - expected: "", - }, - { - name: "no og:title", - html: ``, - expected: "", - }, - { - name: "case insensitive property", - html: ``, - expected: "Case Insensitive Title", - }, - { - name: "multiple og:title (first one)", - html: ``, - expected: "First Title", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := svc.ExtractFromOpenGraph(tt.html) - if result != tt.expected { - t.Fatalf("expected %q, got %q", tt.expected, result) - } - }) - } -} - -func TestExtractFromJSONLD(t *testing.T) { - svc := NewURLMetadataService() - - tests := []struct { - name string - html string - expected string - }{ - { - name: "VideoObject with name", - html: `{"@type":"VideoObject","name":"Video Title"}`, - expected: "Video Title", - }, - { - name: "WebPage with name", - html: `{"@type":"WebPage","name":"Page Title"}`, - expected: "Page Title", - }, - { - name: "VideoObject with whitespace in name", - html: `{"@type":"VideoObject","name":" Video Title "}`, - expected: "Video Title", - }, - { - name: "empty name", - html: `{"@type":"VideoObject","name":""}`, - expected: "", - }, - { - name: "whitespace only name", - html: `{"@type":"VideoObject","name":" "}`, - expected: "", - }, - { - name: "no name field", - html: `{"@type":"VideoObject","description":"Description"}`, - expected: "", - }, - { - name: "wrong type", - html: `{"@type":"Article","name":"Article Title"}`, - expected: "", - }, - { - name: "no @type", - html: `{"name":"Some Title"}`, - expected: "", - }, - { - name: "multiple objects (first VideoObject)", - html: `{"@type":"VideoObject","name":"Video Title"} {"@type":"WebPage","name":"Page Title"}`, - expected: "Video Title", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := svc.ExtractFromJSONLD(tt.html) - if result != tt.expected { - t.Fatalf("expected %q, got %q", tt.expected, result) - } - }) - } -} - -func TestExtractFromTwitterCard(t *testing.T) { - svc := NewURLMetadataService() - - tests := []struct { - name string - html string - expected string - }{ - { - name: "simple twitter:title", - html: ``, - expected: "Twitter Title", - }, - { - name: "twitter:title with whitespace", - html: ``, - expected: "Twitter Title", - }, - - { - name: "empty twitter:title", - html: ``, - expected: "", - }, - { - name: "whitespace only twitter:title", - html: ``, - expected: "", - }, - { - name: "no twitter:title", - html: ``, - expected: "", - }, - { - name: "case insensitive name", - html: ``, - expected: "Case Insensitive Title", - }, - { - name: "multiple twitter:title (first one)", - html: ``, - expected: "First Title", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := svc.ExtractFromTwitterCard(tt.html) - if result != tt.expected { - t.Fatalf("expected %q, got %q", tt.expected, result) - } - }) - } -} - -func TestExtractFromMetaTags(t *testing.T) { - svc := NewURLMetadataService() - - tests := []struct { - name string - html string - expected string - }{ - { - name: "simple meta title", - html: ``, - expected: "Meta Title", - }, - { - name: "meta title with whitespace", - html: ``, - expected: "Meta Title", - }, - - { - name: "empty meta title", - html: ``, - expected: "", - }, - { - name: "whitespace only meta title", - html: ``, - expected: "", - }, - { - name: "no meta title", - html: ``, - expected: "", - }, - { - name: "case insensitive name", - html: ``, - expected: "Case Insensitive Title", - }, - { - name: "multiple meta title (first one)", - html: ``, - expected: "First Title", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := svc.extractFromMetaTags(tt.html) - if result != tt.expected { - t.Fatalf("expected %q, got %q", tt.expected, result) - } - }) - } -} - func TestExtractTitleFromHTML(t *testing.T) { svc := NewURLMetadataService() @@ -781,39 +548,24 @@ func TestExtractTitleFromHTML(t *testing.T) { expected string }{ { - name: "title tag takes precedence", + name: "title tag extracted", html: `Title Tag`, expected: "Title Tag", }, { - name: "og:title fallback when no title tag", + name: "no title tag returns empty", html: ``, - expected: "OG Title", + expected: "", }, { - name: "JSON-LD fallback when no title or og", - html: ``, - expected: "JSON Title", - }, - { - name: "twitter fallback when no title, og, or json", - html: ``, - expected: "Twitter Title", - }, - { - name: "meta title fallback when no other methods work", - html: ``, - expected: "Meta Title", - }, - { - name: "empty title tag falls back to og:title", + name: "empty title tag returns empty", html: ``, - expected: "OG Title", + expected: "", }, { - name: "whitespace title tag falls back to og:title", + name: "whitespace title tag returns empty", html: ` `, - expected: "OG Title", + expected: "", }, { name: "no title found",