package admin import ( "encoding/json" "fmt" "net/http" "net/http/httptest" "strings" "testing" ) func TestListAccountsPageSizeCapIs5000(t *testing.T) { accounts := make([]string, 0, 150) for i := range 150 { accounts = append(accounts, fmt.Sprintf(`{"email":"u%d@example.com","password":"pwd"}`, i)) } raw := fmt.Sprintf(`{"accounts":[%s]}`, strings.Join(accounts, ",")) router := newHTTPAdminHarness(t, raw, &testingDSMock{}) rec := httptest.NewRecorder() router.ServeHTTP(rec, adminReq(http.MethodGet, "/accounts?page=1&page_size=200", nil)) if rec.Code != http.StatusOK { t.Fatalf("unexpected status: %d body=%s", rec.Code, rec.Body.String()) } var payload map[string]any if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil { t.Fatalf("decode response: %v", err) } items, _ := payload["items"].([]any) if len(items) != 150 { t.Fatalf("expected all 150 accounts with page_size=200, got %d", len(items)) } if ps, _ := payload["page_size"].(float64); ps != 200 { t.Fatalf("expected page_size=200 in response, got %v", payload["page_size"]) } } func TestListAccountsPageSizeAbove5000ClampedTo5000(t *testing.T) { router := newHTTPAdminHarness(t, `{"accounts":[{"email":"u@example.com","password":"pwd"}]}`, &testingDSMock{}) rec := httptest.NewRecorder() router.ServeHTTP(rec, adminReq(http.MethodGet, "/accounts?page=1&page_size=9999", nil)) if rec.Code != http.StatusOK { t.Fatalf("unexpected status: %d body=%s", rec.Code, rec.Body.String()) } var payload map[string]any if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil { t.Fatalf("decode response: %v", err) } if ps, _ := payload["page_size"].(float64); ps != 5000 { t.Fatalf("expected page_size clamped to 5000, got %v", payload["page_size"]) } }