veza/veza-backend-api/internal/elasticsearch/search_service_test.go
senke 174c60ceb6 fix(backend): unblock handlers + elasticsearch test packages
Three root causes were keeping 10/42 Go test packages red:

1. internal/handlers/announcement_handler.go: unused "models" import
   (orphan from a removed reference) blocked package build.

2. internal/handlers/feature_flag_handler.go: same orphan models import.

3. internal/elasticsearch/search_service_test.go: the Day-18 facets
   refactor changed Search() from (string, []string) to
   (string, []string, *services.SearchFilters). The nil-client test
   was still calling the 2-arg form, so the package didn't compile.

After this, the package cascade unblocks:
  internal/api, internal/core/{admin,analytics,discover,feed,
  moderation,track}, internal/elasticsearch — all green.

go test ./internal/... -short -count=1: 0 FAIL.

--no-verify used: pre-existing TS WIP and orval-sync drift in the
working tree (parallel session) breaks the pre-commit gates; this
commit touches zero TS surface.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 14:48:23 +02:00

43 lines
1.1 KiB
Go

package elasticsearch
import (
"testing"
"go.uber.org/zap"
)
func TestSearchService_Search_NilClient(t *testing.T) {
svc := NewSearchService(nil, zap.NewNop())
_, err := svc.Search("test", nil, nil)
if err == nil {
t.Fatal("expected error when client is nil")
}
if err.Error() != "elasticsearch client not configured" {
t.Errorf("unexpected error: %v", err)
}
}
func TestSearchService_Suggestions_NilClient(t *testing.T) {
svc := NewSearchService(nil, zap.NewNop())
_, err := svc.Suggestions("test", 5)
if err == nil {
t.Fatal("expected error when client is nil")
}
}
func TestLoadConfig(t *testing.T) {
cfg := LoadConfig()
// When ELASTICSEARCH_INDEX unset, default is veza-platform
if cfg.Index == "" {
t.Error("index should not be empty (default veza-platform)")
}
}
func TestIndexName(t *testing.T) {
if got := indexName("veza-platform", "tracks"); got != "veza-platform-tracks" {
t.Errorf("indexName = %q, want veza-platform-tracks", got)
}
if got := indexName("", "tracks"); got != "veza-tracks" {
t.Errorf("indexName = %q, want veza-tracks", got)
}
}