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>
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/tradarr/backend/internal/api/handlers"
|
|
"github.com/tradarr/backend/internal/auth"
|
|
"github.com/tradarr/backend/internal/config"
|
|
)
|
|
|
|
func TestTicket25BABAAndAMZNKeepPrimaryCompanyDTO(t *testing.T) {
|
|
previous := gin.Mode()
|
|
gin.SetMode(gin.TestMode)
|
|
defer gin.SetMode(previous)
|
|
const secret = "local-ticket25-baba-secret"
|
|
h := handlers.New(nil, &config.Config{JWTSecret: secret}, nil, nil, nil, nil)
|
|
router := SetupRouter(h, secret)
|
|
token, err := auth.GenerateToken("owner", "owner@example.test", "user", secret)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, tc := range []struct{ query, id, name string }{{"BABA", "isin:KYG017191142", "Alibaba Group Holding Limited"}, {"amzn", "isin:US0231351067", "Amazon.com, Inc."}} {
|
|
t.Run(tc.query, func(t *testing.T) {
|
|
request := httptest.NewRequest("GET", "/api/companies/search?q="+tc.query+"&limit=1", nil)
|
|
request.Header.Set("Authorization", "Bearer "+token)
|
|
response := httptest.NewRecorder()
|
|
router.ServeHTTP(response, request)
|
|
if response.Code != 200 {
|
|
t.Fatalf("status=%d body=%s", response.Code, response.Body.String())
|
|
}
|
|
var envelope struct {
|
|
Data []map[string]any `json:"data"`
|
|
}
|
|
if err := json.Unmarshal(response.Body.Bytes(), &envelope); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(envelope.Data) != 1 || envelope.Data[0]["company_id"] != tc.id || envelope.Data[0]["name"] != tc.name {
|
|
t.Fatalf("DTO=%+v", envelope.Data)
|
|
}
|
|
expected := []string{"company_id", "name", "exchange", "country", "mic"}
|
|
if len(envelope.Data[0]) != len(expected) {
|
|
t.Fatalf("DTO fields changed: %+v", envelope.Data[0])
|
|
}
|
|
for _, key := range expected {
|
|
if _, ok := envelope.Data[0][key]; !ok {
|
|
t.Fatalf("DTO missing %s", key)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|