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

Function TestHandleWorklog_WithEntries

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

Source from the content-addressed store, hash-verified

1143}
1144
1145func TestHandleWorklog_WithEntries(t *testing.T) {
1146 dir := createTestTaskDir(t)
1147
1148 worklogContent := `## 2025-01-15T10:00:00Z
1149
1150Started working on task one.
1151
1152## 2025-01-15T14:30:00Z
1153
1154Completed initial implementation.
1155`
1156 createWorklogFile(t, dir, "001", worklogContent)
1157
1158 dp := NewDataProvider(dir, false)
1159
1160 req := httptest.NewRequest(http.MethodGet, "/api/tasks/001/worklog", nil)
1161 req.SetPathValue("id", "001")
1162 rec := httptest.NewRecorder()
1163
1164 handleWorklog(dp)(rec, req)
1165
1166 if rec.Code != http.StatusOK {
1167 t.Fatalf("expected 200, got %d", rec.Code)
1168 }
1169
1170 var entries []WorklogEntryJSON
1171 if err := json.Unmarshal(rec.Body.Bytes(), &entries); err != nil {
1172 t.Fatalf("invalid JSON: %v", err)
1173 }
1174
1175 if len(entries) != 2 {
1176 t.Fatalf("expected 2 worklog entries, got %d", len(entries))
1177 }
1178
1179 if entries[0].Timestamp != "2025-01-15T10:00:00Z" {
1180 t.Errorf("expected first timestamp 2025-01-15T10:00:00Z, got %s", entries[0].Timestamp)
1181 }
1182 if !strings.Contains(entries[0].Content, "Started working") {
1183 t.Errorf("expected first entry content about starting, got %q", entries[0].Content)
1184 }
1185 if !strings.Contains(entries[1].Content, "Completed initial") {
1186 t.Errorf("expected second entry content about completing, got %q", entries[1].Content)
1187 }
1188}
1189
1190func TestHandleWorklog_TaskNotFound(t *testing.T) {
1191 dir := createTestTaskDir(t)

Callers

nothing calls this directly

Calls 4

createTestTaskDirFunction · 0.85
createWorklogFileFunction · 0.85
NewDataProviderFunction · 0.85
handleWorklogFunction · 0.85

Tested by

no test coverage detected