fix(scraper): verify complete article evidence (#40)
This commit is contained in:
@ -20,11 +20,11 @@ func TestTicket39SourceFixtures(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a := ExtractHTML(source, "https://fixture.invalid/article", raw)
|
||||
a := ExtractHTML(source, fixtureArticleURL(source), raw)
|
||||
if a.ContentState != scraper.ContentComplete || !strings.Contains(a.Content, "Final editorial paragraph.") || strings.Contains(a.Content, "excluded") || a.PublishedAt == nil {
|
||||
t.Fatalf("bad full content: state=%s date=%v", a.ContentState, a.PublishedAt)
|
||||
}
|
||||
a = ExtractHTML(source, "https://fixture.invalid/article", append(raw, []byte(`<div class="paywall">subscribe</div>`)...))
|
||||
a = ExtractHTML(source, fixtureArticleURL(source), append(raw, []byte(`<div class="paywall">subscribe</div>`)...))
|
||||
if a.ContentState != scraper.ContentIncomplete {
|
||||
t.Fatal("paywall claimed complete")
|
||||
}
|
||||
@ -33,7 +33,7 @@ func TestTicket39SourceFixtures(t *testing.T) {
|
||||
}
|
||||
func TestTicket39FetchRestrictionsAndFullBody(t *testing.T) {
|
||||
calls := 0
|
||||
body := "<div class=caas-body><p>" + strings.Repeat("Full editorial paragraph. ", 2000) + "</p></div>"
|
||||
body := `<link rel="canonical" href="https://finance.yahoo.com/news/fixture.html">` + "<div class=caas-body><p>" + strings.Repeat("Full editorial paragraph. ", 2000) + "</p></div>"
|
||||
client := &http.Client{Transport: roundTrip(func(r *http.Request) (*http.Response, error) {
|
||||
calls++
|
||||
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(body)), Header: make(http.Header)}, nil
|
||||
@ -73,3 +73,10 @@ func TestTicket39EditorialHeadingsListsAndQuotesAreNotDropped(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fixtureArticleURL(source string) string {
|
||||
if source == "yahoo_finance" {
|
||||
return "https://finance.yahoo.com/news/fixture.html"
|
||||
}
|
||||
return "https://www.cnbc.com/2026/01/02/fixture.html"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user