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

Function TestHandleTaskByID_WithWorklog

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

Source from the content-addressed store, hash-verified

122}
123
124func TestHandleTaskByID_WithWorklog(t *testing.T) {
125 dir := createTestTaskDir(t)
126
127 worklogContent := `## 2025-01-15T10:00:00Z
128
129Started working.
130
131## 2025-01-15T14:30:00Z
132
133Done.
134`
135 createWorklogFile(t, dir, "001", worklogContent)
136
137 dp := NewDataProvider(dir, false)
138
139 req := httptest.NewRequest(http.MethodGet, "/api/tasks/001", nil)
140 req.SetPathValue("id", "001")
141 rec := httptest.NewRecorder()
142
143 handleTaskByID(dp)(rec, req)
144
145 if rec.Code != http.StatusOK {
146 t.Fatalf("expected 200, got %d", rec.Code)
147 }
148
149 var task map[string]any
150 if err := json.Unmarshal(rec.Body.Bytes(), &task); err != nil {
151 t.Fatalf("invalid JSON: %v", err)
152 }
153
154 entryCount, ok := task["worklog_entries"].(float64)
155 if !ok || int(entryCount) != 2 {
156 t.Errorf("expected worklog_entries=2, got %v", task["worklog_entries"])
157 }
158
159 updated, ok := task["worklog_updated"].(string)
160 if !ok || !strings.Contains(updated, "2025-01-15") {
161 t.Errorf("expected worklog_updated with 2025-01-15, got %v", task["worklog_updated"])
162 }
163}
164
165func TestHandleTaskByID_EmptyID(t *testing.T) {
166 dir := createTestTaskDir(t)

Callers

nothing calls this directly

Calls 4

createTestTaskDirFunction · 0.85
createWorklogFileFunction · 0.85
NewDataProviderFunction · 0.85
handleTaskByIDFunction · 0.85

Tested by

no test coverage detected