package api import ( "context" "encoding/json" "net/http" "net/http/httptest" "testing" "task-dashboard/internal/models" ) func TestClaudomatorClient_GetActiveStories(t *testing.T) { stories := []models.ClaudomatorStory{ {ID: "1", Title: "Story One", Status: "IN_PROGRESS"}, {ID: "2", Title: "Story Two", Status: "REVIEW_READY"}, {ID: "3", Title: "Story Three", Status: "DRAFT"}, } server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/api/stories" { http.NotFound(w, r) return } w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(stories) })) defer server.Close() client := ClaudomatorHTTPClient{BaseURL: server.URL} result, err := client.GetActiveStories(context.Background()) if err != nil { t.Fatalf("unexpected error: %v", err) } if len(result) != 2 { t.Fatalf("expected 2 active stories, got %d", len(result)) } statuses := map[string]bool{} for _, s := range result { statuses[s.Status] = true } if !statuses["IN_PROGRESS"] { t.Error("expected IN_PROGRESS story in results") } if !statuses["REVIEW_READY"] { t.Error("expected REVIEW_READY story in results") } if statuses["DRAFT"] { t.Error("DRAFT story should be excluded from results") } }