Files
TradarrV2/backend/internal/scraper/bloomberg/full_content_ticket39_test.go

42 lines
1.4 KiB
Go

package bloomberg
import (
"context"
"encoding/json"
"github.com/tradarr/backend/internal/scraper"
"io"
"net/http"
"os"
"strings"
"testing"
)
func TestTicket39BloombergFixtureCompleteStateAndLongBody(t *testing.T) {
raw, err := os.ReadFile("testdata/enriched_complete.json")
if err != nil {
t.Fatal(err)
}
for _, long := range []bool{false, true} {
var response struct {
Articles []map[string]any `json:"articles"`
}
if json.Unmarshal(raw, &response) != nil {
t.Fatal("bad fixture")
}
want := "Synthetic first editorial paragraph.\n\nFinal editorial paragraph."
if long {
want = strings.Repeat(want, 600)
response.Articles[0]["content"] = want
}
payload, _ := json.Marshal(response)
b := New("http://fixture.invalid")
b.client = &http.Client{Transport: dateTransport(func(*http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(string(payload))), Header: make(http.Header)}, nil
})}
got, err := b.EnrichWithCredentials(context.Background(), "fixture", "fixture", []scraper.Article{{Title: "Original", URL: "https://www.bloomberg.com/news/articles/fixture"}})
if err != nil || len(got) != 1 || got[0].Content != want || scraper.ContentStatus(got[0]) != scraper.ContentComplete || got[0].PublishedAt == nil || got[0].ContentTruncated {
t.Fatal("complete full-body DTO lost")
}
}
}