feat(search): add exact company aliases
Embed a versioned local alias overlay and rank exact aliases before legal-name matches and word prefixes. Normalize Unicode consistently, deduplicate by company identity before limiting, and update bilingual search guidance and tests. Refs #24 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
47
backend/internal/api/company_alias_ticket24_test.go
Normal file
47
backend/internal/api/company_alias_ticket24_test.go
Normal file
@ -0,0 +1,47 @@
|
||||
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 TestTicket24CompanyAliasKeepsCanonicalDTOAndIdentity(t *testing.T) {
|
||||
old := gin.Mode()
|
||||
gin.SetMode(gin.TestMode)
|
||||
defer gin.SetMode(old)
|
||||
const secret = "local-ticket24-secret"
|
||||
handler := handlers.New(nil, &config.Config{JWTSecret: secret}, nil, nil, nil, nil)
|
||||
router := SetupRouter(handler, secret)
|
||||
token, err := auth.GenerateToken("owner", "owner@example.test", "user", secret)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
request := httptest.NewRequest("GET", "/api/companies/search?q=IBM&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]["name"] != "International Business Machines Corporation" || envelope.Data[0]["company_id"] != "isin:US4592001014" {
|
||||
t.Fatalf("unexpected alias DTO %+v", envelope.Data)
|
||||
}
|
||||
allowed := map[string]bool{"company_id": true, "name": true, "exchange": true, "country": true, "mic": true}
|
||||
for key := range envelope.Data[0] {
|
||||
if !allowed[key] {
|
||||
t.Fatalf("DTO expanded with %q", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user