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

Function TestHandleStats

apps/cli/internal/web/handlers_test.go:374–407  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

372}
373
374func TestHandleStats(t *testing.T) {
375 dir := createTestTaskDir(t)
376 dp := NewDataProvider(dir, false)
377
378 req := httptest.NewRequest(http.MethodGet, "/api/stats", nil)
379 rec := httptest.NewRecorder()
380
381 handleStats(dp)(rec, req)
382
383 if rec.Code != http.StatusOK {
384 t.Fatalf("expected 200, got %d", rec.Code)
385 }
386
387 var m metrics.Metrics
388 if err := json.Unmarshal(rec.Body.Bytes(), &m); err != nil {
389 t.Fatalf("invalid JSON: %v", err)
390 }
391
392 if m.TotalTasks != 2 {
393 t.Fatalf("expected 2 total tasks, got %d", m.TotalTasks)
394 }
395
396 // Verify tags are included (test fixtures have "setup" and "core")
397 if len(m.TagsByCount) != 2 {
398 t.Fatalf("expected 2 tags, got %d", len(m.TagsByCount))
399 }
400 // Both have count 1, so alphabetical: core first, setup second
401 if m.TagsByCount[0].Tag != "core" {
402 t.Errorf("expected first tag 'core', got %q", m.TagsByCount[0].Tag)
403 }
404 if m.TagsByCount[1].Tag != "setup" {
405 t.Errorf("expected second tag 'setup', got %q", m.TagsByCount[1].Tag)
406 }
407}
408
409func TestHandleValidate(t *testing.T) {
410 dir := createTestTaskDir(t)

Callers

nothing calls this directly

Calls 3

createTestTaskDirFunction · 0.85
NewDataProviderFunction · 0.85
handleStatsFunction · 0.85

Tested by

no test coverage detected