package generation import ( "context" "encoding/json" "io" "net/http" "net/http/httptest" "strings" "testing" "github.com/tradarr/backend/internal/models" "github.com/tradarr/backend/internal/scraper" "github.com/tradarr/backend/internal/scraper/articlecontent" "github.com/tradarr/backend/internal/scraper/bloomberg" ) type ticket40Transport func(*http.Request) (*http.Response, error) func (f ticket40Transport) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) } type ticket40EvidenceFeed struct { calls *int source string articles []scraper.Article client *http.Client bb *bloomberg.Bloomberg } func (f ticket40EvidenceFeed) Name() string { return f.source } func (f ticket40EvidenceFeed) Scrape(context.Context, []string) ([]scraper.Article, error) { if f.calls != nil { *f.calls++ } return append([]scraper.Article(nil), f.articles...), nil } func (f ticket40EvidenceFeed) Enrich(ctx context.Context, a []scraper.Article) ([]scraper.Article, error) { if f.bb != nil { return f.bb.EnrichWithCredentials(ctx, "fixture", "fixture", a) } return articlecontent.Enrich(ctx, f.client, f.source, a) } func TestTicket40LegacyEnrichmentPreservedAndRetiredSourcesCannotGenerate(t *testing.T) { for _, key := range []string{models.SourceYahooFinance, models.SourceBloomberg, models.SourceCNBCBusiness} { t.Run(key, func(t *testing.T) { const full = "Synthetic full editorial body." base, root := "https://finance.yahoo.com/news/", "caas-body" if key == models.SourceCNBCBusiness { base = "https://www.cnbc.com/2026/01/02/" root = "ArticleBody-articleBody" } if key == models.SourceBloomberg { base = "https://www.bloomberg.com/news/articles/" } calls := 0 feed := ticket40EvidenceFeed{source: key, calls: &calls} for _, kind := range []string{"complete", "partial", "absent"} { feed.articles = append(feed.articles, scraper.Article{Title: "Followed fixture " + kind, URL: base + kind + ".html", Content: "RSS teaser", ContentState: scraper.ContentIncomplete}) } if key == models.SourceBloomberg { server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var req struct { URLs []string `json:"urls"` } if r.URL.Path != "/bloomberg/enrich" || json.NewDecoder(r.Body).Decode(&req) != nil { t.Error("unexpected fixture RPC") w.WriteHeader(400) return } result := []map[string]any{} for _, url := range req.URLs { body, state := full, scraper.ContentComplete if strings.Contains(url, "partial") { body = "Available introduction." state = scraper.ContentIncomplete } if strings.Contains(url, "absent") { body = "" state = scraper.ContentUnavailable } result = append(result, map[string]any{"url": url, "content": body, "content_state": state}) } json.NewEncoder(w).Encode(map[string]any{"articles": result}) })) defer server.Close() feed.bb = bloomberg.New(server.URL) } else { feed.client = &http.Client{Transport: ticket40Transport(func(r *http.Request) (*http.Response, error) { body := `
` + full + `