package ai import ( "context" "encoding/json" "fmt" "net/http" "net/http/httptest" "testing" "time" "github.com/tradarr/backend/internal/generation" "github.com/tradarr/backend/internal/models" "github.com/tradarr/backend/internal/scraper" ) func TestTicket19LayaReceivesCompanyNameAndSelectedInternalIdentity(t *testing.T) { figi := "BBG00ZMFX1S5" var request struct { States []struct { Indices []map[string]string `json:"indices"` } `json:"states"` } srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/v1/systemone/batch" { t.Errorf("Laya path=%s", r.URL.Path) } if err := json.NewDecoder(r.Body).Decode(&request); err != nil { t.Errorf("decode Laya payload: %v", err) w.WriteHeader(400) return } fmt.Fprint(w, `{"results":[{"answers":{"relevance":{"type":"score","score":0.1,"answer_confidence":0.9}},"usage":{"truncated":false,"state_tokens_dropped":0,"truncated_questions":[]}}],"total_usage":{"input_tokens":10,"output_tokens":0}}`) })) defer srv.Close() ranker, err := NewLayaHTTPRanker(LayaHTTPConfig{BaseURL: srv.URL, Timeout: time.Second}) if err != nil { t.Fatal(err) } _, err = ranker.Rank(context.Background(), "title", []models.UserAsset{{Name: "Baidu, Inc.", Symbol: "9888.HK", FIGI: &figi}}, []generation.Candidate{{ID: "candidate", Article: scraper.Article{Title: "synthetic market headline"}}}) if err != nil { t.Fatal(err) } if len(request.States) != 1 || len(request.States[0].Indices) != 1 { t.Fatalf("Laya indices payload=%+v", request.States) } index := request.States[0].Indices[0] if index["name"] != "Baidu, Inc." || index["symbol"] != "9888.HK" || index["figi"] != figi { t.Fatalf("Laya received wrong company identity: %+v", index) } if index["symbol"] == "SSAAPL INDEX" { t.Fatalf("Bloomberg identifier was sent to Laya as ticker: %+v", index) } }