package articlecontent
import (
"github.com/tradarr/backend/internal/scraper"
"os"
"strings"
"testing"
)
func TestTicket40AssociationAndIncompleteBodies(t *testing.T) {
for _, tc := range []struct{ source, url, root string }{{"yahoo_finance", "https://finance.yahoo.com/news/fixture.html", "caas-body"}, {"cnbc_business", "https://www.cnbc.com/2026/01/02/fixture.html", "ArticleBody-articleBody"}} {
t.Run(tc.source, func(t *testing.T) {
full := `
Synthetic editorial introduction.
Synthetic final editorial paragraph.
`
for _, marker := range []string{``, ``, ``, ``} {
a := ExtractHTML(tc.source, tc.url, []byte(strings.Replace(full, "", marker+"", 1)))
if a.ContentState == scraper.ContentComplete {
t.Fatal("blocked or partial page marked complete")
}
}
wrong := ExtractHTML(tc.source, tc.url, []byte(strings.Replace(full, tc.url, tc.url+"-other", 1)))
if wrong.ContentState != scraper.ContentUnavailable || wrong.Content != "" || wrong.PublishedAt != nil {
t.Fatal("wrong article accepted")
}
missing := ExtractHTML(tc.source, tc.url, []byte(``))
if missing.ContentState == scraper.ContentComplete {
t.Fatal("unassociated body marked complete")
}
})
}
}
func TestTicket40SourceSpecificLayoutsPreserveFullEditorialText(t *testing.T) {
for _, tc := range []struct{ source, url, fixture string }{{"yahoo_finance", "https://finance.yahoo.com/news/fixture.html", "yahoo_modern.html"}, {"cnbc_business", "https://www.cnbc.com/2026/01/02/fixture.html", "cnbc_module.html"}} {
t.Run(tc.source, func(t *testing.T) {
raw, err := os.ReadFile("testdata/" + tc.fixture)
if err != nil {
t.Fatal(err)
}
a := ExtractHTML(tc.source, tc.url, raw)
if a.ContentState != scraper.ContentComplete || a.PublishedAt == nil || !strings.Contains(a.Content, "Final editorial paragraph.") || !strings.Contains(a.Content, "Synthetic heading.") || strings.Contains(a.Content, "excluded") {
t.Fatalf("unrecognized or incomplete fixture extraction: state=%s", a.ContentState)
}
})
}
}