MCPcopy Create free account
hub / github.com/driangle/taskmd / TestHandleTaskByID_Success

Function TestHandleTaskByID_Success

apps/cli/internal/web/handlers_test.go:82–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

80}
81
82func TestHandleTaskByID_Success(t *testing.T) {
83 dir := createTestTaskDir(t)
84 dp := NewDataProvider(dir, false)
85
86 req := httptest.NewRequest(http.MethodGet, "/api/tasks/001", nil)
87 req.SetPathValue("id", "001")
88 rec := httptest.NewRecorder()
89
90 handleTaskByID(dp)(rec, req)
91
92 if rec.Code != http.StatusOK {
93 t.Fatalf("expected 200, got %d", rec.Code)
94 }
95
96 ct := rec.Header().Get("Content-Type")
97 if ct != "application/json" {
98 t.Fatalf("expected application/json, got %s", ct)
99 }
100
101 var task map[string]any
102 if err := json.Unmarshal(rec.Body.Bytes(), &task); err != nil {
103 t.Fatalf("invalid JSON: %v", err)
104 }
105
106 if task["id"] != "001" {
107 t.Fatalf("expected task ID 001, got %v", task["id"])
108 }
109
110 if task["title"] != "Task One" {
111 t.Fatalf("expected title 'Task One', got %v", task["title"])
112 }
113
114 // Verify body is included
115 body, ok := task["body"]
116 if !ok {
117 t.Fatal("expected body field in response")
118 }
119 if body == "" || body == nil {
120 t.Fatal("expected non-empty body")
121 }
122}
123
124func TestHandleTaskByID_WithWorklog(t *testing.T) {
125 dir := createTestTaskDir(t)

Callers

nothing calls this directly

Calls 3

createTestTaskDirFunction · 0.85
NewDataProviderFunction · 0.85
handleTaskByIDFunction · 0.85

Tested by

no test coverage detected