test: remove outdated ebook pagination tests
- Removed TestPaginationAndFiltering function - Deleted 4 test cases using deprecated /api/ebooks endpoint - Tests for pagination already exist in library_test.go using /api/media-items This is part of legacy code cleanup Phase 3. Phase 3: Test Suite Cleanup
This commit is contained in:
@@ -580,84 +580,3 @@ func TestJWTValidation(t *testing.T) {
|
||||
assert.Equal(t, http.StatusUnauthorized, rr.Code)
|
||||
})
|
||||
}
|
||||
|
||||
// TestPaginationAndFiltering tests query parameter handling
|
||||
func TestPaginationAndFiltering(t *testing.T) {
|
||||
t.Run("Negative limit", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/ebooks?limit=-10&offset=0", nil)
|
||||
req.Header.Set("Authorization", "Bearer valid-token")
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
limit := r.URL.Query().Get("limit")
|
||||
if limit == "-10" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(`{"error":"limit must be positive"}`))
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
handler.ServeHTTP(rr, req)
|
||||
assert.Equal(t, http.StatusBadRequest, rr.Code)
|
||||
})
|
||||
|
||||
t.Run("Negative offset", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/ebooks?limit=10&offset=-5", nil)
|
||||
req.Header.Set("Authorization", "Bearer valid-token")
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
offset := r.URL.Query().Get("offset")
|
||||
if offset == "-5" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(`{"error":"offset must be non-negative"}`))
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
handler.ServeHTTP(rr, req)
|
||||
assert.Equal(t, http.StatusBadRequest, rr.Code)
|
||||
})
|
||||
|
||||
t.Run("Very large limit", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/ebooks?limit=10000&offset=0", nil)
|
||||
req.Header.Set("Authorization", "Bearer valid-token")
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
limit := r.URL.Query().Get("limit")
|
||||
if limit == "10000" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(`{"error":"limit too large"}`))
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
handler.ServeHTTP(rr, req)
|
||||
assert.Equal(t, http.StatusBadRequest, rr.Code)
|
||||
})
|
||||
|
||||
t.Run("Valid pagination", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/api/ebooks?limit=20&offset=0", nil)
|
||||
req.Header.Set("Authorization", "Bearer valid-token")
|
||||
rr := httptest.NewRecorder()
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ebooks := []map[string]interface{}{
|
||||
{"id": uuid.New().String(), "title": "Book 1"},
|
||||
{"id": uuid.New().String(), "title": "Book 2"},
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(ebooks)
|
||||
})
|
||||
|
||||
handler.ServeHTTP(rr, req)
|
||||
assert.Equal(t, http.StatusOK, rr.Code)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user