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

Function TestHandleUpdateTask_Success

apps/cli/internal/web/handlers_test.go:430–458  ·  view source on GitHub ↗

PUT /api/tasks/{id} tests

(t *testing.T)

Source from the content-addressed store, hash-verified

428// PUT /api/tasks/{id} tests
429
430func 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
460func TestHandleUpdateTask_EmptyID(t *testing.T) {
461 dir := createTestTaskDir(t)

Callers

nothing calls this directly

Calls 4

createTestTaskDirFunction · 0.85
NewDataProviderFunction · 0.85
handleUpdateTaskFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected