veza/veza-backend-api/internal/elasticsearch/search_service_test.go
senke ba88086f20 feat(v0.10.2): Recherche fulltext Elasticsearch - F361-F365
- Elasticsearch 8.x dans docker-compose.dev
- Package internal/elasticsearch: client, config, mappings, indices
- Sync PG→ES: reindex tracks/users/playlists, IndexTrack/DeleteTrack
- SearchService ES: multi_match + fuzziness (typo tolerance), highlighting
- Fallback gracieux: PostgreSQL si ELASTICSEARCH_URL absent
- Routes: GET /search, GET /search/suggestions, POST /admin/search/reindex
- Frontend: searchApi cursor/limit params (extensibilité)
- docs/ENV_VARIABLES: ELASTICSEARCH_URL, ELASTICSEARCH_INDEX, ELASTICSEARCH_AUTO_INDEX
- Roadmap v0.10.2 → DONE
2026-03-09 10:13:18 +01: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)
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)
}
}