(t *testing.T)
| 52 | } |
| 53 | |
| 54 | func TestHandleTasks(t *testing.T) { |
| 55 | dir := createTestTaskDir(t) |
| 56 | dp := NewDataProvider(dir, false) |
| 57 | |
| 58 | req := httptest.NewRequest(http.MethodGet, "/api/tasks", nil) |
| 59 | rec := httptest.NewRecorder() |
| 60 | |
| 61 | handleTasks(dp)(rec, req) |
| 62 | |
| 63 | if rec.Code != http.StatusOK { |
| 64 | t.Fatalf("expected 200, got %d", rec.Code) |
| 65 | } |
| 66 | |
| 67 | ct := rec.Header().Get("Content-Type") |
| 68 | if ct != "application/json" { |
| 69 | t.Fatalf("expected application/json, got %s", ct) |
| 70 | } |
| 71 | |
| 72 | var tasks []map[string]any |
| 73 | if err := json.Unmarshal(rec.Body.Bytes(), &tasks); err != nil { |
| 74 | t.Fatalf("invalid JSON: %v", err) |
| 75 | } |
| 76 | |
| 77 | if len(tasks) != 2 { |
| 78 | t.Fatalf("expected 2 tasks, got %d", len(tasks)) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | func TestHandleTaskByID_Success(t *testing.T) { |
| 83 | dir := createTestTaskDir(t) |
nothing calls this directly
no test coverage detected