(t *testing.T)
| 1143 | } |
| 1144 | |
| 1145 | func TestHandleWorklog_WithEntries(t *testing.T) { |
| 1146 | dir := createTestTaskDir(t) |
| 1147 | |
| 1148 | worklogContent := `## 2025-01-15T10:00:00Z |
| 1149 | |
| 1150 | Started working on task one. |
| 1151 | |
| 1152 | ## 2025-01-15T14:30:00Z |
| 1153 | |
| 1154 | Completed 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 | |
| 1190 | func TestHandleWorklog_TaskNotFound(t *testing.T) { |
| 1191 | dir := createTestTaskDir(t) |
nothing calls this directly
no test coverage detected