feat(search): find companies by stock symbol
Index exact symbols from selected primary listings, preserve canonical company identities, and add BABA as an explicit alias for Alibaba's primary identity. Update bilingual help and cover symbol collisions, aliases, and DTO stability. Refs #25 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
70
backend/internal/companycatalog/baba_alias_ticket25_test.go
Normal file
70
backend/internal/companycatalog/baba_alias_ticket25_test.go
Normal file
@ -0,0 +1,70 @@
|
||||
package companycatalog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTicket25BABAExplicitAliasResolvesPrimaryAlibaba(t *testing.T) {
|
||||
catalog, err := Default()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, tc := range []struct{ query, id, name, symbol, figi string }{
|
||||
{"BABA", "isin:KYG017191142", "Alibaba Group Holding Limited", "9988.HK", "BBG00QV37ZP9"},
|
||||
{" baba ", "isin:KYG017191142", "Alibaba Group Holding Limited", "9988.HK", "BBG00QV37ZP9"},
|
||||
{"amzn", "isin:US0231351067", "Amazon.com, Inc.", "AMZN", "BBG000BVQ4Z3"},
|
||||
} {
|
||||
t.Run(tc.query, func(t *testing.T) {
|
||||
got, err := catalog.SearchCompanies(tc.query, 1)
|
||||
if err != nil || len(got) != 1 || got[0].CompanyID != tc.id || got[0].Name != tc.name || got[0].YahooSymbol != tc.symbol || got[0].FIGI != tc.figi {
|
||||
t.Fatalf("query=%q result=%+v err=%v", tc.query, got, err)
|
||||
}
|
||||
resolved, err := catalog.ResolveCompany(got[0].CompanyID)
|
||||
if err != nil || resolved != got[0] {
|
||||
t.Fatalf("resolution differs: %+v %v", resolved, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTicket25BABAOverlayDoesNotAdmitNonPrimaryRowsOrSecondarySymbols(t *testing.T) {
|
||||
catalog, err := Default()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(catalog.symbolIDs["BABA"]) != 0 {
|
||||
t.Fatal("BABA was admitted to the primary symbol index")
|
||||
}
|
||||
if len(catalog.companies) != 43126 {
|
||||
t.Fatal("company identities changed")
|
||||
}
|
||||
rows, err := csv.NewReader(bytes.NewReader(embeddedSnapshot)).ReadAll()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
columns := map[string]int{}
|
||||
for i, key := range rows[0] {
|
||||
columns[key] = i
|
||||
}
|
||||
if len(rows)-1 != 47735 {
|
||||
t.Fatal("snapshot size changed")
|
||||
}
|
||||
for _, row := range rows[1:] {
|
||||
if row[columns["symbol"]] == "BABA" || row[columns["primary_listing"]] != "true" || row[columns["delisted"]] != "false" {
|
||||
t.Fatalf("non-primary/delisted row admitted: %s", row[columns["symbol"]])
|
||||
}
|
||||
}
|
||||
for _, query := range []string{"BABAF", "BABAN.MX", "BABA.BA"} {
|
||||
got, err := catalog.SearchCompanies(query, 20)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, company := range got {
|
||||
if company.CompanyID == "isin:KYG017191142" {
|
||||
t.Fatalf("unapproved secondary symbol %q admitted", query)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user