MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestHandleDashboardStats_HappyPath

Function TestHandleDashboardStats_HappyPath

internal/auth/auth_test.go:358–400  ·  view source on GitHub ↗

--- 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)

Source from the content-addressed store, hash-verified

356// store.GetDashboardStats. Asserts the JSON shape (sections for today
357// / pending / delivery / window).
358func 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
402func TestHandleDashboardStats_Unauthenticated(t *testing.T) {
403 ua, _, _ := setupUserAuth(t)

Callers

nothing calls this directly

Calls 6

setupUserAuthFunction · 0.85
authedRequestFunction · 0.85
GetUserSessionMethod · 0.80
GetDashboardStatsMethod · 0.80
HandleDashboardStatsMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected