//go:build integration

package search_test

import (
	"testing"

	"github.com/ultisuite/ulti-backend/internal/integrationtest"
)

func TestSearchPostgresEmptyQuery(t *testing.T) {
	h := integrationtest.RequireHarness(t)
	client, _ := integrationtest.RequireUserClient(t, h)

	resp, err := client.Get("/api/v1/search?q=hello")
	integrationtest.FailIf(err, t, "search")
	integrationtest.FailUnlessStatus(t, resp, 200)

	var body map[string]any
	integrationtest.DecodeJSON(t, resp, &body)
	if body["results"] == nil {
		t.Fatalf("missing results field: %#v", body)
	}
}

func TestSearchRequiresAuth(t *testing.T) {
	h := integrationtest.RequireHarness(t)
	client := integrationtest.NewClient(h.Server.URL, "")

	resp, err := client.Get("/api/v1/search?q=test")
	integrationtest.FailIf(err, t, "search without auth")
	if resp.Status != 401 {
		t.Fatalf("status = %d, want 401", resp.Status)
	}
}
