package generation import ( "context" "github.com/tradarr/backend/internal/models" "github.com/tradarr/backend/internal/scraper" "reflect" "testing" ) func pointer(s string) *string { return &s } func TestYahooSymbolsUseResolvedPrimaryWithoutBloombergOrFIGI(t *testing.T) { assets := []models.UserAsset{ {CompanyID: pointer("isin:KYG070341048"), Name: "Baidu, Inc.", Symbol: "OLD_BLOOMBERG", YahooSymbol: pointer("9888.HK")}, {Symbol: "SSAAPL INDEX"}, {Symbol: "BBG000BBJQV0"}, {Symbol: "NVDA"}, {Symbol: "NVDA"}, {CompanyID: pointer("isin:unknown"), Symbol: "CLIENT-SPOOF"}, } if got := yahooSymbols(assets); !reflect.DeepEqual(got, []string{"9888.HK", "NVDA"}) { t.Fatalf("Yahoo input=%v", got) } } type symbolFeed struct{ symbols []string } func (f *symbolFeed) Name() string { return "fake" } func (f *symbolFeed) Scrape(_ context.Context, s []string) ([]scraper.Article, error) { f.symbols = s return nil, nil } func TestPerSourceCompanyHintsDoNotChangeOtherFeeds(t *testing.T) { yahoo, bloomberg, cnbc, watcher := &symbolFeed{}, &symbolFeed{}, &symbolFeed{}, &symbolFeed{} input := UserInput{Language: "fr", RankingMode: "title", GlobalLimit: 20, Assets: []models.UserAsset{{CompanyID: pointer("isin:company"), Name: "Company", Symbol: "HISTORIC INDEX", YahooSymbol: pointer("9888.HK")}}} for _, key := range []string{models.SourceYahooFinance, models.SourceBloomberg, models.SourceCNBCBusiness, models.SourceWatcherGuru} { key := key input.Sources = append(input.Sources, models.Source{ID: key, SourceKey: &key, Enabled: true, ArticleLimit: 20}) } repo := &contractRepository{inputs: map[string]UserInput{"owner": input}, saved: map[string][]GenerationRecord{}} uc := NewUseCase(Dependencies{Repository: repo, LayaRanker: &contractRanker{}, Summarizer: &contractSummarizer{}, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: yahoo, models.SourceBloomberg: bloomberg, models.SourceCNBCBusiness: cnbc, models.SourceWatcherGuru: watcher}}) if _, err := uc.Generate(context.Background(), "owner"); err != nil { t.Fatal(err) } if !reflect.DeepEqual(yahoo.symbols, []string{"9888.HK"}) || !reflect.DeepEqual(bloomberg.symbols, []string{"HISTORIC INDEX"}) || !reflect.DeepEqual(cnbc.symbols, bloomberg.symbols) || watcher.symbols != nil { t.Fatalf("Yahoo=%v Bloomberg=%v Watcher=%v", yahoo.symbols, bloomberg.symbols, watcher.symbols) } }