Files
TradarrV2/backend/internal/generation/source_allowlist_ticket13_test.go
Blomios 64a7124889 feat(sources): replace WatcherGuru with CNBC Business
Add the CNBC Business RSS source, switch supported-source wiring and reporting, and migrate existing WatcherGuru rows to disabled historical status without rewriting references.

Refs #23

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-22 17:17:15 +01:00

51 lines
2.4 KiB
Go

package generation
import (
"context"
"encoding/json"
"testing"
"github.com/tradarr/backend/internal/models"
"github.com/tradarr/backend/internal/scraper"
)
func TestGenerationRoutesOnlyAllowlistedSourceKeysEvenWhenLegacyRowsAreEnabled(t *testing.T) {
var sources []models.Source
if err := json.Unmarshal([]byte(`[
{"id":"y","name":"Yahoo Finance","type":"stocktwits","source_key":"yahoo_finance","enabled":true,"article_limit":20},
{"id":"b","name":"Bloomberg","type":"bloomberg","source_key":"bloomberg","enabled":true,"article_limit":20},
{"id":"c","name":"CNBC Business","type":"cnbc_business","source_key":"cnbc_business","enabled":true,"article_limit":20},
{"id":"w","name":"Watcher.Guru","type":"watcherguru","source_key":"watcher_guru","enabled":true,"article_limit":20},
{"id":"s","name":"StockTwits","type":"stocktwits","source_key":null,"enabled":true,"article_limit":20},
{"id":"r","name":"Reuters","type":"reuters","source_key":null,"enabled":true,"article_limit":20}
]`), &sources); err != nil {
t.Fatal(err)
}
repo := &contractRepository{inputs: map[string]UserInput{"user": {Language: "fr", RankingMode: "title", GlobalLimit: 10, Assets: []models.UserAsset{{Symbol: "SPX"}}, Sources: sources}}, saved: map[string][]GenerationRecord{}}
feeds := map[string]*contractScraper{}
for _, key := range []string{"yahoo_finance", "bloomberg", "cnbc_business", "watcher_guru", "stocktwits", "reuters"} {
feeds[key] = &contractScraper{name: key, articles: []scraper.Article{{Title: key}}}
}
scrapers := map[string]scraper.Scraper{}
for key, feed := range feeds {
scrapers[key] = feed
}
result, err := NewUseCase(Dependencies{Repository: repo, Scrapers: scrapers, Ranker: &contractRanker{}, Summarizer: &contractSummarizer{}}).Generate(context.Background(), "user")
if err != nil || result.Summary == nil {
t.Fatalf("generation result=%+v err=%v", result, err)
}
for _, key := range []string{"yahoo_finance", "bloomberg", "cnbc_business"} {
if len(feeds[key].calls) != 1 {
t.Errorf("target %s calls=%d, want one", key, len(feeds[key].calls))
}
}
for _, key := range []string{"watcher_guru", "stocktwits", "reuters"} {
if len(feeds[key].calls) != 0 {
t.Errorf("unsupported enabled source %s was invoked %d times", key, len(feeds[key].calls))
}
}
if result.Outcome.TotalCandidates != 3 {
t.Errorf("target candidate count=%d, want 3", result.Outcome.TotalCandidates)
}
}