(t *testing.T)
| 1351 | } |
| 1352 | |
| 1353 | func TestHandleTasks_WithProject(t *testing.T) { |
| 1354 | defaultDir := createTestTaskDir(t) |
| 1355 | projectDir := createProjectTaskDir(t) |
| 1356 | |
| 1357 | defaultDP := NewDataProvider(defaultDir, false) |
| 1358 | resolver := NewProjectResolver(func(id string) (string, []PhaseInfo, error) { |
| 1359 | if id == "proj-a" { |
| 1360 | return projectDir, nil, nil |
| 1361 | } |
| 1362 | return "", nil, ErrProjectNotFound |
| 1363 | }, false) |
| 1364 | |
| 1365 | handler := setupProjectMiddleware(resolver, handleTasks(defaultDP)) |
| 1366 | |
| 1367 | // With ?project=proj-a, should return project tasks. |
| 1368 | req := httptest.NewRequest(http.MethodGet, "/api/tasks?project=proj-a", nil) |
| 1369 | rec := httptest.NewRecorder() |
| 1370 | handler.ServeHTTP(rec, req) |
| 1371 | |
| 1372 | if rec.Code != http.StatusOK { |
| 1373 | t.Fatalf("expected 200, got %d: %s", rec.Code, rec.Body.String()) |
| 1374 | } |
| 1375 | |
| 1376 | var tasks []map[string]any |
| 1377 | if err := json.Unmarshal(rec.Body.Bytes(), &tasks); err != nil { |
| 1378 | t.Fatalf("invalid JSON: %v", err) |
| 1379 | } |
| 1380 | if len(tasks) != 1 { |
| 1381 | t.Fatalf("expected 1 project task, got %d", len(tasks)) |
| 1382 | } |
| 1383 | if tasks[0]["id"] != "P01" { |
| 1384 | t.Fatalf("expected task id P01, got %v", tasks[0]["id"]) |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | func TestHandleTasks_WithoutProject_ReturnsDefault(t *testing.T) { |
| 1389 | defaultDir := createTestTaskDir(t) |
nothing calls this directly
no test coverage detected