Files
TradarrV2/backend/internal/generation/company_symbols_test.go
Blomios d65222169a feat(watchlist): add company identity catalog
Embed a pinned FinanceDatabase equity snapshot, add authenticated company search and identity-based follows, preserve legacy assets, and map selected Yahoo symbols for collection.

Refs #19

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

47 lines
2.2 KiB
Go

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, watcher := &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.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.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(watcher.symbols, bloomberg.symbols) {
t.Fatalf("Yahoo=%v Bloomberg=%v Watcher=%v", yahoo.symbols, bloomberg.symbols, watcher.symbols)
}
}