--- Dashboard stats endpoint --- TestHandleDashboardStats_HappyPath: GET /api/dashboard/stats wraps store.GetDashboardStats. Asserts the JSON shape (sections for today pending / delivery / window).
(t *testing.T)
| 356 | // store.GetDashboardStats. Asserts the JSON shape (sections for today |
| 357 | // / pending / delivery / window). |
| 358 | func TestHandleDashboardStats_HappyPath(t *testing.T) { |
| 359 | ua, store, token := setupUserAuth(t) |
| 360 | ctx := context.Background() |
| 361 | |
| 362 | // Need to look up the user that setupUserAuth created so we can |
| 363 | // seed usage rows against the right user_id. |
| 364 | user, _ := store.GetUserSession(ctx, token) |
| 365 | |
| 366 | // Seed today + yesterday rows. |
| 367 | _, err := store.GetDashboardStats(ctx, user.ID, 0) |
| 368 | if err != nil { |
| 369 | t.Fatalf("pre-seed GetDashboardStats: %v", err) |
| 370 | } |
| 371 | |
| 372 | req := authedRequest("GET", "/api/dashboard/stats", token) |
| 373 | w := httptest.NewRecorder() |
| 374 | ua.HandleDashboardStats(w, req) |
| 375 | |
| 376 | if w.Code != http.StatusOK { |
| 377 | t.Fatalf("status = %d, want 200; body=%s", w.Code, w.Body.String()) |
| 378 | } |
| 379 | |
| 380 | var got struct { |
| 381 | Today struct { |
| 382 | Inbound int `json:"inbound"` |
| 383 | Outbound int `json:"outbound"` |
| 384 | InboundDeltaPct int `json:"inbound_delta_pct"` |
| 385 | OutboundDeltaPct int `json:"outbound_delta_pct"` |
| 386 | } `json:"today"` |
| 387 | Pending struct { |
| 388 | Count int `json:"count"` |
| 389 | OldestSeconds int `json:"oldest_seconds"` |
| 390 | } `json:"pending"` |
| 391 | DeliverySuccessPct float64 `json:"delivery_success_pct"` |
| 392 | SampleWindowDays int `json:"sample_window_days"` |
| 393 | } |
| 394 | if err := json.NewDecoder(w.Body).Decode(&got); err != nil { |
| 395 | t.Fatalf("decode: %v", err) |
| 396 | } |
| 397 | if got.SampleWindowDays != 7 { |
| 398 | t.Errorf("sample_window_days = %d, want 7", got.SampleWindowDays) |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | func TestHandleDashboardStats_Unauthenticated(t *testing.T) { |
| 403 | ua, _, _ := setupUserAuth(t) |
nothing calls this directly
no test coverage detected