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>
73 lines
2.8 KiB
Go
73 lines
2.8 KiB
Go
package companycatalog
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// This checks the internal catalog result only; it intentionally does not fix
|
|
// an HTTP/public DTO shape. The snapshot is local and pinned, with no network.
|
|
func TestSearchReturnsOneCompanyNameAndPrimaryYahooSymbol(t *testing.T) {
|
|
catalog, err := NewFinanceDatabaseCatalogFromSnapshot(filepath.Join("testdata", "finance_database_equities_primary_2026-11-22.csv"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, tc := range []struct{ query, name, companyID, yahoo string }{
|
|
{"NVIDIA", "NVIDIA Corporation", "isin:US67066G1040", "NVDA"},
|
|
{"Apple", "Apple Inc.", "isin:US0378331005", "AAPL"},
|
|
{"Baidu", "Baidu, Inc.", "isin:KYG070341048", "9888.HK"},
|
|
{"BYD Company", "BYD Company Limited", "isin:CNE100001526", "002594.SZ"},
|
|
{"BYD Electronic", "BYD Electronic (International) Company Limited", "isin:HK0285041858", "0285.HK"},
|
|
} {
|
|
t.Run(tc.query, func(t *testing.T) {
|
|
got, err := catalog.SearchCompanies(tc.query, 10)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(got) != 1 {
|
|
t.Fatalf("results=%+v; want one company for %q", got, tc.query)
|
|
}
|
|
if got[0].Name != tc.name || got[0].CompanyID != tc.companyID || got[0].YahooSymbol != tc.yahoo {
|
|
t.Fatalf("company=%+v; want name=%q company_id=%q yahoo=%q", got[0], tc.name, tc.companyID, tc.yahoo)
|
|
}
|
|
if strings.Contains(got[0].YahooSymbol, " ") || strings.Contains(got[0].YahooSymbol, "INDEX") {
|
|
t.Fatalf("non-Yahoo security label leaked as Yahoo symbol %q", got[0].YahooSymbol)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCompanyCatalogUsesFIGIFallbackWhenISINIsMissing(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "local-figi-fallback.csv")
|
|
fixture := "symbol,name,exchange,mic,country,isin,figi,composite_figi,delisted,listing_score,primary_listing,main_venue,listings,usual_currency,home_known\n" +
|
|
"FALLBACK,Example Company,NMS,XNAS,United States,,BBG000FALLBK,BBG000FALLBK,false,1,true,true,1,true,true\n"
|
|
if err := os.WriteFile(path, []byte(fixture), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog, err := NewFinanceDatabaseCatalogFromSnapshot(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := catalog.SearchCompanies("Example Company", 10)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(got) != 1 || got[0].CompanyID != "figi:BBG000FALLBK" {
|
|
t.Fatalf("company fallback identity=%+v; want figi:BBG000FALLBK", got)
|
|
}
|
|
}
|
|
|
|
func TestSearchExcludesNonEquityAssetClasses(t *testing.T) {
|
|
catalog, err := NewFinanceDatabaseCatalogFromSnapshot(filepath.Join("testdata", "finance_database_equities_primary_2026-11-22.csv"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, symbol := range []string{"QQQ", "ES=F", "AAPL260117C00200000"} {
|
|
if got, err := catalog.SearchCompanies(symbol, 10); err != nil || len(got) != 0 {
|
|
t.Errorf("non-equity %q returned %+v, err=%v", symbol, got, err)
|
|
}
|
|
}
|
|
}
|