summaryrefslogtreecommitdiff
path: root/internal/api/claudomator_test.go
blob: 4a2cb00e9a1458eee5eb062633b6e680654f94de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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")
	}
}