package server import ( "net/http" "net/http/httptest" "testing" ) func TestSearch_FindsTask(t *testing.T) { srv := setupTestServer(t) req := httptest.NewRequest(http.MethodGet, "/search?q=Prvi", nil) w := httptest.NewRecorder() srv.Router.ServeHTTP(w, req) if w.Code != http.StatusOK { t.Fatalf("expected 200, got %d", w.Code) } body := w.Body.String() if !containsStr(body, "T01") { t.Error("expected T01 in search results for 'Prvi'") } } func TestSearch_FindsTaskByID(t *testing.T) { srv := setupTestServer(t) req := httptest.NewRequest(http.MethodGet, "/search?q=T08", nil) w := httptest.NewRecorder() srv.Router.ServeHTTP(w, req) body := w.Body.String() if !containsStr(body, "T08") { t.Error("expected T08 in search results") } } func TestSearch_FindsDocument(t *testing.T) { srv := setupTestServer(t) req := httptest.NewRequest(http.MethodGet, "/search?q=checker", nil) w := httptest.NewRecorder() srv.Router.ServeHTTP(w, req) body := w.Body.String() if !containsStr(body, "checker/CLAUDE.md") { t.Error("expected checker CLAUDE.md in search results") } } func TestSearch_FindsReport(t *testing.T) { srv := setupTestServer(t) req := httptest.NewRequest(http.MethodGet, "/search?q=prolaze", nil) w := httptest.NewRecorder() srv.Router.ServeHTTP(w, req) body := w.Body.String() if !containsStr(body, "T01-report.md") { t.Error("expected T01 report in search results") } } func TestSearch_EmptyQuery(t *testing.T) { srv := setupTestServer(t) req := httptest.NewRequest(http.MethodGet, "/search?q=", nil) w := httptest.NewRecorder() srv.Router.ServeHTTP(w, req) if w.Code != http.StatusOK { t.Fatalf("expected 200, got %d", w.Code) } if w.Body.Len() != 0 { t.Errorf("expected empty response for empty query, got %d bytes", w.Body.Len()) } } func TestSearch_NoResults(t *testing.T) { srv := setupTestServer(t) req := httptest.NewRequest(http.MethodGet, "/search?q=xyznepostoji", nil) w := httptest.NewRecorder() srv.Router.ServeHTTP(w, req) body := w.Body.String() if !containsStr(body, "Nema rezultata") { t.Error("expected 'Nema rezultata' message") } } func TestSearch_CaseInsensitive(t *testing.T) { srv := setupTestServer(t) req := httptest.NewRequest(http.MethodGet, "/search?q=CODER", nil) w := httptest.NewRecorder() srv.Router.ServeHTTP(w, req) body := w.Body.String() if !containsStr(body, "coder") { t.Error("expected case-insensitive match for 'CODER'") } } func TestSearch_HasSnippet(t *testing.T) { srv := setupTestServer(t) req := httptest.NewRequest(http.MethodGet, "/search?q=kodiranja", nil) w := httptest.NewRecorder() srv.Router.ServeHTTP(w, req) body := w.Body.String() if !containsStr(body, "kodiranja") { t.Error("expected snippet with 'kodiranja' text") } }