PUT /api/tasks/{id} tests
(t *testing.T)
| 428 | // PUT /api/tasks/{id} tests |
| 429 | |
| 430 | func TestHandleUpdateTask_Success(t *testing.T) { |
| 431 | dir := createTestTaskDir(t) |
| 432 | dp := NewDataProvider(dir, false) |
| 433 | |
| 434 | body := strings.NewReader(`{"status":"completed"}`) |
| 435 | req := httptest.NewRequest(http.MethodPut, "/api/tasks/001", body) |
| 436 | req.SetPathValue("id", "001") |
| 437 | rec := httptest.NewRecorder() |
| 438 | |
| 439 | handleUpdateTask(dp, false)(rec, req) |
| 440 | |
| 441 | if rec.Code != http.StatusOK { |
| 442 | t.Fatalf("expected 200, got %d: %s", rec.Code, rec.Body.String()) |
| 443 | } |
| 444 | |
| 445 | var task map[string]any |
| 446 | if err := json.Unmarshal(rec.Body.Bytes(), &task); err != nil { |
| 447 | t.Fatalf("invalid JSON: %v", err) |
| 448 | } |
| 449 | if task["status"] != "completed" { |
| 450 | t.Errorf("expected status completed, got %v", task["status"]) |
| 451 | } |
| 452 | |
| 453 | // Verify file was actually updated |
| 454 | content, _ := os.ReadFile(filepath.Join(dir, "001-task-one.md")) |
| 455 | if !strings.Contains(string(content), "status: completed") { |
| 456 | t.Error("expected file to contain updated status") |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | func TestHandleUpdateTask_EmptyID(t *testing.T) { |
| 461 | dir := createTestTaskDir(t) |
nothing calls this directly
no test coverage detected