Răsfoiți Sursa

test(api): share helpers and remove duplicated tests

The API tests had their own helper to list fixture entries, copied
blocks of field checks, and wording that differed from file to file.

- Use servertest.FeedEntries, like the Google Reader and Fever tests,
  and read the enclosure from the fixture entry that has one.
- Compare users with shared helpers, which also checks the entry order
  that the lookup by username skipped.
- Use one ID for resources that do not exist, and spell them
  "nonexistent" in test names and messages.
- Table-drive the entry ID pagination parameter tests, and run each
  foreign scope check in its own subtest.
- Replace single-letter variables and a local variable that shadowed
  the handler type.
- Remove the end-to-end pagination test: the entry query tests cover
  the same pages with more orders.
Frédéric Guillot 2 ore în urmă
părinte
comite
96d9b8f030

+ 1 - 1
internal/api/api_key_integration_test.go

@@ -99,7 +99,7 @@ func TestAPIKeysEndpoint(t *testing.T) {
 	// Try to delete the API key again, it should return an error.
 	// Try to delete the API key again, it should return an error.
 	err = regularUserClient.DeleteAPIKey(apiKey.ID)
 	err = regularUserClient.DeleteAPIKey(apiKey.ID)
 	if !errors.Is(err, miniflux.ErrNotFound) {
 	if !errors.Is(err, miniflux.ErrNotFound) {
-		t.Fatalf(`Deleting a non-existent API key should raise a "not found" error, got %v`, err)
+		t.Fatalf(`Deleting a nonexistent API key should raise a "not found" error, got %v`, err)
 	}
 	}
 
 
 	// Try to create an API key with an empty description.
 	// Try to create an API key with an empty description.

+ 91 - 101
internal/api/api_test.go

@@ -24,51 +24,51 @@ import (
 )
 )
 
 
 func TestNewHandlerHandlesOptionsRequests(t *testing.T) {
 func TestNewHandlerHandlesOptionsRequests(t *testing.T) {
-	handler := NewHandler(nil, nil)
+	apiHandler := NewHandler(nil, nil)
 
 
-	r := httptest.NewRequest(http.MethodOptions, "/v1/users", nil)
-	w := httptest.NewRecorder()
+	request := httptest.NewRequest(http.MethodOptions, "/v1/users", nil)
+	recorder := httptest.NewRecorder()
 
 
-	handler.ServeHTTP(w, r)
+	apiHandler.ServeHTTP(recorder, request)
 
 
-	if got := w.Code; got != http.StatusNoContent {
+	if got := recorder.Code; got != http.StatusNoContent {
 		t.Fatalf(`Unexpected status code, got %d instead of %d`, got, http.StatusNoContent)
 		t.Fatalf(`Unexpected status code, got %d instead of %d`, got, http.StatusNoContent)
 	}
 	}
 
 
-	if got := w.Header().Get("Access-Control-Allow-Origin"); got != "*" {
+	if got := recorder.Header().Get("Access-Control-Allow-Origin"); got != "*" {
 		t.Fatalf(`Unexpected Access-Control-Allow-Origin header, got %q`, got)
 		t.Fatalf(`Unexpected Access-Control-Allow-Origin header, got %q`, got)
 	}
 	}
 
 
-	if got := w.Header().Get("Access-Control-Allow-Methods"); got != "GET, POST, PUT, DELETE, OPTIONS" {
+	if got := recorder.Header().Get("Access-Control-Allow-Methods"); got != "GET, POST, PUT, DELETE, OPTIONS" {
 		t.Fatalf(`Unexpected Access-Control-Allow-Methods header, got %q`, got)
 		t.Fatalf(`Unexpected Access-Control-Allow-Methods header, got %q`, got)
 	}
 	}
 
 
-	if got := w.Header().Get("Access-Control-Allow-Headers"); got != "X-Auth-Token, Authorization, Content-Type, Accept" {
+	if got := recorder.Header().Get("Access-Control-Allow-Headers"); got != "X-Auth-Token, Authorization, Content-Type, Accept" {
 		t.Fatalf(`Unexpected Access-Control-Allow-Headers header, got %q`, got)
 		t.Fatalf(`Unexpected Access-Control-Allow-Headers header, got %q`, got)
 	}
 	}
 
 
-	if got := w.Header().Get("Access-Control-Max-Age"); got != "3600" {
+	if got := recorder.Header().Get("Access-Control-Max-Age"); got != "3600" {
 		t.Fatalf(`Unexpected Access-Control-Max-Age header, got %q`, got)
 		t.Fatalf(`Unexpected Access-Control-Max-Age header, got %q`, got)
 	}
 	}
 }
 }
 
 
 func TestVersionHandler(t *testing.T) {
 func TestVersionHandler(t *testing.T) {
-	h := &handler{}
-	r := httptest.NewRequest(http.MethodGet, "/v1/version", nil)
-	w := httptest.NewRecorder()
+	apiHandler := &handler{}
+	request := httptest.NewRequest(http.MethodGet, "/v1/version", nil)
+	recorder := httptest.NewRecorder()
 
 
-	h.versionHandler(w, r)
+	apiHandler.versionHandler(recorder, request)
 
 
-	if got := w.Code; got != http.StatusOK {
+	if got := recorder.Code; got != http.StatusOK {
 		t.Fatalf(`Unexpected status code, got %d instead of %d`, got, http.StatusOK)
 		t.Fatalf(`Unexpected status code, got %d instead of %d`, got, http.StatusOK)
 	}
 	}
 
 
-	if got := w.Header().Get("Content-Type"); got != "application/json" {
+	if got := recorder.Header().Get("Content-Type"); got != "application/json" {
 		t.Fatalf(`Unexpected Content-Type header, got %q`, got)
 		t.Fatalf(`Unexpected Content-Type header, got %q`, got)
 	}
 	}
 
 
 	var responseBody versionResponse
 	var responseBody versionResponse
-	if err := json.NewDecoder(w.Body).Decode(&responseBody); err != nil {
+	if err := json.NewDecoder(recorder.Body).Decode(&responseBody); err != nil {
 		t.Fatalf("Unexpected JSON decoding error: %v", err)
 		t.Fatalf("Unexpected JSON decoding error: %v", err)
 	}
 	}
 
 
@@ -102,15 +102,22 @@ func TestVersionHandler(t *testing.T) {
 }
 }
 
 
 func TestGetEntryIDsHandlerRequiresAuthentication(t *testing.T) {
 func TestGetEntryIDsHandlerRequiresAuthentication(t *testing.T) {
-	handler := NewHandler(nil, nil)
+	apiHandler := NewHandler(nil, nil)
 
 
-	for _, query := range []string{"", "?starred=maybe", "?status=invalid"} {
-		t.Run(query, func(t *testing.T) {
-			r := httptest.NewRequest(http.MethodGet, "/v1/entries/ids"+query, nil)
-			w := httptest.NewRecorder()
-			handler.ServeHTTP(w, r)
+	for _, test := range []struct {
+		name  string
+		query string
+	}{
+		{"no query", ""},
+		{"invalid starred value", "?starred=maybe"},
+		{"invalid status", "?status=invalid"},
+	} {
+		t.Run(test.name, func(t *testing.T) {
+			request := httptest.NewRequest(http.MethodGet, "/v1/entries/ids"+test.query, nil)
+			recorder := httptest.NewRecorder()
+			apiHandler.ServeHTTP(recorder, request)
 
 
-			if got := w.Code; got != http.StatusUnauthorized {
+			if got := recorder.Code; got != http.StatusUnauthorized {
 				t.Fatalf(`Unexpected status code, got %d instead of %d`, got, http.StatusUnauthorized)
 				t.Fatalf(`Unexpected status code, got %d instead of %d`, got, http.StatusUnauthorized)
 			}
 			}
 		})
 		})
@@ -127,11 +134,11 @@ func TestValidateEntryIDsFilters(t *testing.T) {
 		"limit=invalid&offset=-1", // Legacy pagination parsing remains independent.
 		"limit=invalid&offset=-1", // Legacy pagination parsing remains independent.
 	} {
 	} {
 		t.Run("valid/"+query, func(t *testing.T) {
 		t.Run("valid/"+query, func(t *testing.T) {
-			r := httptest.NewRequest(http.MethodGet, "/v1/entries/ids?"+query, nil)
-			if err := validateEntryIDsFilters(r); err != nil {
+			request := httptest.NewRequest(http.MethodGet, "/v1/entries/ids?"+query, nil)
+			if err := validateEntryIDsFilters(request); err != nil {
 				t.Fatal(err)
 				t.Fatal(err)
 			}
 			}
-			if _, err := parseEntryFilters(r, 0, 0); err != nil {
+			if _, err := parseEntryFilters(request, 0, 0); err != nil {
 				t.Fatal(err)
 				t.Fatal(err)
 			}
 			}
 		})
 		})
@@ -143,8 +150,8 @@ func TestValidateEntryIDsFilters(t *testing.T) {
 	} {
 	} {
 		for _, value := range []string{"", "invalid", "-1", "1.5", "9223372036854775808"} {
 		for _, value := range []string{"", "invalid", "-1", "1.5", "9223372036854775808"} {
 			t.Run("invalid/"+name+"/"+value, func(t *testing.T) {
 			t.Run("invalid/"+name+"/"+value, func(t *testing.T) {
-				r := httptest.NewRequest(http.MethodGet, "/v1/entries/ids?"+url.Values{name: {value}}.Encode(), nil)
-				if err := validateEntryIDsFilters(r); err == nil {
+				request := httptest.NewRequest(http.MethodGet, "/v1/entries/ids?"+url.Values{name: {value}}.Encode(), nil)
+				if err := validateEntryIDsFilters(request); err == nil {
 					t.Fatal("Expected invalid numeric parameter to be rejected")
 					t.Fatal("Expected invalid numeric parameter to be rejected")
 				}
 				}
 			})
 			})
@@ -155,8 +162,8 @@ func TestValidateEntryIDsFilters(t *testing.T) {
 func TestValidateEntryIDsFiltersRejectsZeroIDs(t *testing.T) {
 func TestValidateEntryIDsFiltersRejectsZeroIDs(t *testing.T) {
 	for _, name := range []string{"feed_id", "category_id", "before_entry_id", "after_entry_id"} {
 	for _, name := range []string{"feed_id", "category_id", "before_entry_id", "after_entry_id"} {
 		t.Run(name, func(t *testing.T) {
 		t.Run(name, func(t *testing.T) {
-			r := httptest.NewRequest(http.MethodGet, "/v1/entries/ids?"+name+"=0", nil)
-			if err := validateEntryIDsFilters(r); err == nil {
+			request := httptest.NewRequest(http.MethodGet, "/v1/entries/ids?"+name+"=0", nil)
+			if err := validateEntryIDsFilters(request); err == nil {
 				t.Fatal("Expected an explicit zero ID to be rejected")
 				t.Fatal("Expected an explicit zero ID to be rejected")
 			}
 			}
 		})
 		})
@@ -168,8 +175,8 @@ func TestValidateEntryIDsFiltersRejectsMalformedQueryStrings(t *testing.T) {
 		"feed_id=%zz", "status=unread;status=read",
 		"feed_id=%zz", "status=unread;status=read",
 	} {
 	} {
 		t.Run(query, func(t *testing.T) {
 		t.Run(query, func(t *testing.T) {
-			r := httptest.NewRequest(http.MethodGet, "/v1/entries/ids?"+query, nil)
-			if err := validateEntryIDsFilters(r); err == nil {
+			request := httptest.NewRequest(http.MethodGet, "/v1/entries/ids?"+query, nil)
+			if err := validateEntryIDsFilters(request); err == nil {
 				t.Fatal("Expected malformed query parameters to be rejected")
 				t.Fatal("Expected malformed query parameters to be rejected")
 			}
 			}
 		})
 		})
@@ -183,15 +190,15 @@ func TestParseEntryFiltersRejectsValuesPostgreSQLCannotAccept(t *testing.T) {
 	}
 	}
 	for _, query := range queries {
 	for _, query := range queries {
 		t.Run(query, func(t *testing.T) {
 		t.Run(query, func(t *testing.T) {
-			r := httptest.NewRequest(http.MethodGet, "/v1/entries?"+query, nil)
-			if _, err := parseEntryFilters(r, 0, 0); err == nil {
+			request := httptest.NewRequest(http.MethodGet, "/v1/entries?"+query, nil)
+			if _, err := parseEntryFilters(request, 0, 0); err == nil {
 				t.Fatal("Expected the value to be rejected")
 				t.Fatal("Expected the value to be rejected")
 			}
 			}
 		})
 		})
 	}
 	}
 
 
-	r := httptest.NewRequest(http.MethodGet, "/v1/entries?before="+strconv.FormatInt(maxEntryFilterTimestamp-1, 10)+"&search=caf%C3%A9", nil)
-	if _, err := parseEntryFilters(r, 0, 0); err != nil {
+	request := httptest.NewRequest(http.MethodGet, "/v1/entries?before="+strconv.FormatInt(maxEntryFilterTimestamp-1, 10)+"&search=caf%C3%A9", nil)
+	if _, err := parseEntryFilters(request, 0, 0); err != nil {
 		t.Fatalf("Expected the last valid timestamp and UTF-8 search text to be accepted: %v", err)
 		t.Fatalf("Expected the last valid timestamp and UTF-8 search text to be accepted: %v", err)
 	}
 	}
 }
 }
@@ -230,8 +237,8 @@ func TestParseEntryFiltersPreservesEndpointCompatibility(t *testing.T) {
 		{query: "globally_visible=false"},
 		{query: "globally_visible=false"},
 	} {
 	} {
 		t.Run(fmt.Sprintf("feed=%d/category=%d/%s", test.routeFeedID, test.routeCategoryID, test.query), func(t *testing.T) {
 		t.Run(fmt.Sprintf("feed=%d/category=%d/%s", test.routeFeedID, test.routeCategoryID, test.query), func(t *testing.T) {
-			r := httptest.NewRequest(http.MethodGet, "/v1/entries?"+test.query, nil)
-			filters, err := parseEntryFilters(r, test.routeFeedID, test.routeCategoryID)
+			request := httptest.NewRequest(http.MethodGet, "/v1/entries?"+test.query, nil)
+			filters, err := parseEntryFilters(request, test.routeFeedID, test.routeCategoryID)
 			if err != nil {
 			if err != nil {
 				t.Fatal(err)
 				t.Fatal(err)
 			}
 			}
@@ -244,8 +251,8 @@ func TestParseEntryFiltersPreservesEndpointCompatibility(t *testing.T) {
 		})
 		})
 	}
 	}
 
 
-	r := httptest.NewRequest(http.MethodGet, "/v1/entries?status=read&status=unread&status=read&tags=one&tags=two", nil)
-	filters, err := parseEntryFilters(r, 0, 0)
+	request := httptest.NewRequest(http.MethodGet, "/v1/entries?status=read&status=unread&status=read&tags=one&tags=two", nil)
+	filters, err := parseEntryFilters(request, 0, 0)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -273,8 +280,8 @@ func TestParseEntryFiltersRejectsInvalidRouteScopedQueryIDs(t *testing.T) {
 			route.param + "=1&" + route.param + "=invalid",
 			route.param + "=1&" + route.param + "=invalid",
 		} {
 		} {
 			t.Run(route.name+"/"+query, func(t *testing.T) {
 			t.Run(route.name+"/"+query, func(t *testing.T) {
-				r := httptest.NewRequest(http.MethodGet, "/v1/entries?"+query, nil)
-				if _, err := parseEntryFilters(r, route.feedID, route.categoryID); err == nil {
+				request := httptest.NewRequest(http.MethodGet, "/v1/entries?"+query, nil)
+				if _, err := parseEntryFilters(request, route.feedID, route.categoryID); err == nil {
 					t.Fatal("Expected invalid scope query ID to be rejected")
 					t.Fatal("Expected invalid scope query ID to be rejected")
 				}
 				}
 			})
 			})
@@ -327,67 +334,50 @@ func TestRouteScopedEntryHandlersRejectInvalidScopeQueryIDs(t *testing.T) {
 
 
 	for _, test := range tests {
 	for _, test := range tests {
 		t.Run(test.name, func(t *testing.T) {
 		t.Run(test.name, func(t *testing.T) {
-			r := httptest.NewRequest(http.MethodGet, test.path, nil)
+			request := httptest.NewRequest(http.MethodGet, test.path, nil)
 			for name, value := range test.pathValues {
 			for name, value := range test.pathValues {
-				r.SetPathValue(name, value)
+				request.SetPathValue(name, value)
 			}
 			}
-			w := httptest.NewRecorder()
+			recorder := httptest.NewRecorder()
 
 
-			test.handle(newFailingStoreHandler(t), w, r)
+			test.handle(newFailingStoreHandler(t), recorder, request)
 
 
-			if w.Code != http.StatusBadRequest {
-				t.Fatalf("Unexpected status code: got %d, want %d", w.Code, http.StatusBadRequest)
+			if recorder.Code != http.StatusBadRequest {
+				t.Fatalf("Unexpected status code: got %d, want %d", recorder.Code, http.StatusBadRequest)
 			}
 			}
 		})
 		})
 	}
 	}
 }
 }
 
 
-func TestParseEntryIDsParamsDefaults(t *testing.T) {
-	r := httptest.NewRequest(http.MethodGet, "/v1/entries/ids", nil)
-	limit, offset := parseEntryIDsParams(r)
-
-	if limit != 10000 {
-		t.Fatalf(`Expected default limit 10000, got %d`, limit)
-	}
-
-	if offset != 0 {
-		t.Fatalf(`Expected default offset 0, got %d`, offset)
-	}
-}
-
-func TestParseEntryIDsParamsCustomValues(t *testing.T) {
-	r := httptest.NewRequest(http.MethodGet, "/v1/entries/ids?limit=500&offset=100", nil)
-	limit, offset := parseEntryIDsParams(r)
-
-	if limit != 500 {
-		t.Fatalf(`Expected limit 500, got %d`, limit)
-	}
-
-	if offset != 100 {
-		t.Fatalf(`Expected offset 100, got %d`, offset)
-	}
-}
-
-func TestParseEntryIDsParamsLimitCappedAtMaximum(t *testing.T) {
-	r := httptest.NewRequest(http.MethodGet, "/v1/entries/ids?limit=99999", nil)
-	limit, _ := parseEntryIDsParams(r)
-
-	if limit != 10000 {
-		t.Fatalf(`Expected limit capped at 10000, got %d`, limit)
-	}
-}
+func TestParseEntryIDsParams(t *testing.T) {
+	for _, test := range []struct {
+		name   string
+		query  string
+		limit  int
+		offset int
+	}{
+		{"defaults", "", 10000, 0},
+		{"custom values", "?limit=500&offset=100", 500, 100},
+		{"limit capped at maximum", "?limit=99999", 10000, 0},
+		{"zero limit uses default", "?limit=0", 10000, 0},
+	} {
+		t.Run(test.name, func(t *testing.T) {
+			request := httptest.NewRequest(http.MethodGet, "/v1/entries/ids"+test.query, nil)
+			limit, offset := parseEntryIDsParams(request)
 
 
-func TestParseEntryIDsParamsZeroLimitUsesDefault(t *testing.T) {
-	r := httptest.NewRequest(http.MethodGet, "/v1/entries/ids?limit=0", nil)
-	limit, _ := parseEntryIDsParams(r)
+			if limit != test.limit {
+				t.Errorf(`Unexpected limit: got %d, want %d`, limit, test.limit)
+			}
 
 
-	if limit != 10000 {
-		t.Fatalf(`Expected zero limit to use default 10000, got %d`, limit)
+			if offset != test.offset {
+				t.Errorf(`Unexpected offset: got %d, want %d`, offset, test.offset)
+			}
+		})
 	}
 	}
 }
 }
 
 
 func TestNewHandlerSupportsBasePathStripping(t *testing.T) {
 func TestNewHandlerSupportsBasePathStripping(t *testing.T) {
-	scenarios := []struct {
+	tests := []struct {
 		name   string
 		name   string
 		prefix string
 		prefix string
 		path   string
 		path   string
@@ -396,16 +386,16 @@ func TestNewHandlerSupportsBasePathStripping(t *testing.T) {
 		{name: "non empty base path", prefix: "/base", path: "/base/v1/users"},
 		{name: "non empty base path", prefix: "/base", path: "/base/v1/users"},
 	}
 	}
 
 
-	for _, scenario := range scenarios {
-		t.Run(scenario.name, func(t *testing.T) {
-			handler := http.StripPrefix(scenario.prefix, NewHandler(nil, nil))
+	for _, test := range tests {
+		t.Run(test.name, func(t *testing.T) {
+			apiHandler := http.StripPrefix(test.prefix, NewHandler(nil, nil))
 
 
-			r := httptest.NewRequest(http.MethodOptions, scenario.path, nil)
-			w := httptest.NewRecorder()
+			request := httptest.NewRequest(http.MethodOptions, test.path, nil)
+			recorder := httptest.NewRecorder()
 
 
-			handler.ServeHTTP(w, r)
+			apiHandler.ServeHTTP(recorder, request)
 
 
-			if got := w.Code; got != http.StatusNoContent {
+			if got := recorder.Code; got != http.StatusNoContent {
 				t.Fatalf(`Unexpected status code, got %d instead of %d`, got, http.StatusNoContent)
 				t.Fatalf(`Unexpected status code, got %d instead of %d`, got, http.StatusNoContent)
 			}
 			}
 		})
 		})
@@ -431,15 +421,15 @@ func TestBasicAuthIsRejectedWhenLocalAuthDisabled(t *testing.T) {
 		config.Opts = previousOptions
 		config.Opts = previousOptions
 	})
 	})
 
 
-	handler := NewHandler(nil, nil)
+	apiHandler := NewHandler(nil, nil)
 
 
-	r := httptest.NewRequest(http.MethodGet, "/v1/me", nil)
-	r.SetBasicAuth("admin", "password")
-	w := httptest.NewRecorder()
+	request := httptest.NewRequest(http.MethodGet, "/v1/me", nil)
+	request.SetBasicAuth("admin", "password")
+	recorder := httptest.NewRecorder()
 
 
-	handler.ServeHTTP(w, r)
+	apiHandler.ServeHTTP(recorder, request)
 
 
-	if got := w.Code; got != http.StatusUnauthorized {
+	if got := recorder.Code; got != http.StatusUnauthorized {
 		t.Fatalf(`Unexpected status code, got %d instead of %d`, got, http.StatusUnauthorized)
 		t.Fatalf(`Unexpected status code, got %d instead of %d`, got, http.StatusUnauthorized)
 	}
 	}
 }
 }

+ 9 - 11
internal/api/category_integration_test.go

@@ -201,13 +201,13 @@ func TestUpdateCategoryWithOptions(t *testing.T) {
 	}
 	}
 }
 }
 
 
-func TestUpdateInexistingCategory(t *testing.T) {
+func TestUpdateNonexistentCategory(t *testing.T) {
 	t.Parallel()
 	t.Parallel()
 
 
 	client := newAdminClient(t)
 	client := newAdminClient(t)
-	_, err := client.UpdateCategory(123456789, "new title")
+	_, err := client.UpdateCategory(nonexistentID, "new title")
 	if !errors.Is(err, miniflux.ErrNotFound) {
 	if !errors.Is(err, miniflux.ErrNotFound) {
-		t.Fatalf(`Updating an inexisting category should raise an error, got %v`, err)
+		t.Fatalf(`Updating a nonexistent category should raise an error, got %v`, err)
 	}
 	}
 }
 }
 
 
@@ -238,13 +238,13 @@ func TestDeleteCategoryEndpoint(t *testing.T) {
 	}
 	}
 }
 }
 
 
-func TestCannotDeleteInexistingCategory(t *testing.T) {
+func TestCannotDeleteNonexistentCategory(t *testing.T) {
 	t.Parallel()
 	t.Parallel()
 
 
 	client := newAdminClient(t)
 	client := newAdminClient(t)
-	err := client.DeleteCategory(123456789)
+	err := client.DeleteCategory(nonexistentID)
 	if !errors.Is(err, miniflux.ErrNotFound) {
 	if !errors.Is(err, miniflux.ErrNotFound) {
-		t.Fatalf(`Deleting an inexisting category should raise an error, got %v`, err)
+		t.Fatalf(`Deleting a nonexistent category should raise an error, got %v`, err)
 	}
 	}
 }
 }
 
 
@@ -370,9 +370,7 @@ func TestMarkCategoryAsReadEndpoint(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	results := listFeedEntries(t, regularUserClient, feedID, nil)
-
-	for _, entry := range results.Entries {
+	for _, entry := range servertest.FeedEntries(t, regularUserClient, feedID) {
 		if entry.Status != miniflux.EntryStatusRead {
 		if entry.Status != miniflux.EntryStatusRead {
 			t.Errorf(`Status for entry %d was %q instead of %q`, entry.ID, entry.Status, miniflux.EntryStatusRead)
 			t.Errorf(`Status for entry %d was %q instead of %q`, entry.ID, entry.Status, miniflux.EntryStatusRead)
 		}
 		}
@@ -399,8 +397,8 @@ func TestRefreshCategoryEndpoint(t *testing.T) {
 		t.Fatalf(`Refreshing a category with an invalid ID should raise a bad request error, got %v`, err)
 		t.Fatalf(`Refreshing a category with an invalid ID should raise a bad request error, got %v`, err)
 	}
 	}
 
 
-	if err := regularUserClient.RefreshCategory(123456789); !errors.Is(err, miniflux.ErrNotFound) {
-		t.Fatalf(`Refreshing an inexisting category should raise a "not found" error, got %v`, err)
+	if err := regularUserClient.RefreshCategory(nonexistentID); !errors.Is(err, miniflux.ErrNotFound) {
+		t.Fatalf(`Refreshing a nonexistent category should raise a "not found" error, got %v`, err)
 	}
 	}
 
 
 	otherUserClient, _ := newRegularUser(t)
 	otherUserClient, _ := newRegularUser(t)

+ 8 - 24
internal/api/enclosure_integration_test.go

@@ -20,19 +20,11 @@ func TestUpdateEnclosureEndpoint(t *testing.T) {
 
 
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	result := listFeedEntries(t, regularUserClient, feedID, nil)
-
-	var enclosure *miniflux.Enclosure
-	for _, entry := range result.Entries {
-		if len(entry.Enclosures) > 0 {
-			enclosure = entry.Enclosures[0]
-			break
-		}
-	}
-
-	if enclosure == nil {
+	entries := servertest.FeedEntries(t, regularUserClient, feedID)
+	if len(entries[1].Enclosures) == 0 {
 		t.Fatal(`The second fixture entry should have an enclosure`)
 		t.Fatal(`The second fixture entry should have an enclosure`)
 	}
 	}
+	enclosure := entries[1].Enclosures[0]
 
 
 	err := regularUserClient.UpdateEnclosure(enclosure.ID, &miniflux.EnclosureUpdateRequest{
 	err := regularUserClient.UpdateEnclosure(enclosure.ID, &miniflux.EnclosureUpdateRequest{
 		MediaProgression: 20,
 		MediaProgression: 20,
@@ -60,19 +52,11 @@ func TestGetEnclosureEndpoint(t *testing.T) {
 
 
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	result := listFeedEntries(t, regularUserClient, feedID, nil)
-
-	var expectedEnclosure *miniflux.Enclosure
-	for _, entry := range result.Entries {
-		if len(entry.Enclosures) > 0 {
-			expectedEnclosure = entry.Enclosures[0]
-			break
-		}
-	}
-
-	if expectedEnclosure == nil {
+	entries := servertest.FeedEntries(t, regularUserClient, feedID)
+	if len(entries[1].Enclosures) == 0 {
 		t.Fatal(`The second fixture entry should have an enclosure`)
 		t.Fatal(`The second fixture entry should have an enclosure`)
 	}
 	}
+	expectedEnclosure := entries[1].Enclosures[0]
 
 
 	enclosure, err := regularUserClient.Enclosure(expectedEnclosure.ID)
 	enclosure, err := regularUserClient.Enclosure(expectedEnclosure.ID)
 	if err != nil {
 	if err != nil {
@@ -83,7 +67,7 @@ func TestGetEnclosureEndpoint(t *testing.T) {
 		t.Fatalf(`Invalid enclosureID, got %d while expecting %d`, enclosure.ID, expectedEnclosure.ID)
 		t.Fatalf(`Invalid enclosureID, got %d while expecting %d`, enclosure.ID, expectedEnclosure.ID)
 	}
 	}
 
 
-	if _, err = regularUserClient.Enclosure(99999); !errors.Is(err, miniflux.ErrNotFound) {
-		t.Fatalf(`Fetching an inexisting enclosure should raise an error, got %v`, err)
+	if _, err = regularUserClient.Enclosure(nonexistentID); !errors.Is(err, miniflux.ErrNotFound) {
+		t.Fatalf(`Fetching a nonexistent enclosure should raise an error, got %v`, err)
 	}
 	}
 }
 }

+ 62 - 79
internal/api/entry_integration_test.go

@@ -6,7 +6,6 @@ package api_test
 import (
 import (
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
-	"math"
 	"net/http"
 	"net/http"
 	"strings"
 	"strings"
 	"testing"
 	"testing"
@@ -25,7 +24,10 @@ func TestGetAllFeedEntriesEndpoint(t *testing.T) {
 
 
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	results := listFeedEntries(t, regularUserClient, feedID, nil)
+	results, err := regularUserClient.FeedEntries(feedID, nil)
+	if err != nil {
+		t.Fatal(err)
+	}
 
 
 	if len(results.Entries) == 0 {
 	if len(results.Entries) == 0 {
 		t.Fatalf(`Invalid number of entries, got %d`, len(results.Entries))
 		t.Fatalf(`Invalid number of entries, got %d`, len(results.Entries))
@@ -196,23 +198,21 @@ func TestGetGlobalEntriesEndpoint(t *testing.T) {
 		FeedURL:      fixture.FeedURL,
 		FeedURL:      fixture.FeedURL,
 		HideGlobally: true,
 		HideGlobally: true,
 	})
 	})
-
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	feedIDEntry, err := regularUserClient.Feed(feedID)
+	feed, err := regularUserClient.Feed(feedID)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	if feedIDEntry.HideGlobally != true {
+	if !feed.HideGlobally {
 		t.Fatalf(`Expected feed to have globally_hidden set to true, was false.`)
 		t.Fatalf(`Expected feed to have globally_hidden set to true, was false.`)
 	}
 	}
 
 
-	/* Not filtering on GloballyVisible should return all entries */
+	// Not filtering on GloballyVisible should return all entries.
 	feedEntries, err := regularUserClient.Entries(&miniflux.Filter{FeedID: feedID})
 	feedEntries, err := regularUserClient.Entries(&miniflux.Filter{FeedID: feedID})
-
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -221,9 +221,8 @@ func TestGetGlobalEntriesEndpoint(t *testing.T) {
 		t.Fatalf(`Expected entries but response contained none.`)
 		t.Fatalf(`Expected entries but response contained none.`)
 	}
 	}
 
 
-	/* Feed is hidden globally, so this should be empty */
+	// The feed is hidden globally, so this should be empty.
 	globallyVisibleEntries, err := regularUserClient.Entries(&miniflux.Filter{GloballyVisible: true})
 	globallyVisibleEntries, err := regularUserClient.Entries(&miniflux.Filter{GloballyVisible: true})
-
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -242,14 +241,14 @@ func TestGetEntryEndpoints(t *testing.T) {
 
 
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	result := listFeedEntries(t, regularUserClient, feedID, nil)
+	entries := servertest.FeedEntries(t, regularUserClient, feedID)
 
 
-	entry, err := regularUserClient.FeedEntry(feedID, result.Entries[0].ID)
+	entry, err := regularUserClient.FeedEntry(feedID, entries[0].ID)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	if entry.ID != result.Entries[0].ID {
+	if entry.ID != entries[0].ID {
 		t.Fatalf(`Invalid entryID, got %d`, entry.ID)
 		t.Fatalf(`Invalid entryID, got %d`, entry.ID)
 	}
 	}
 
 
@@ -261,21 +260,21 @@ func TestGetEntryEndpoints(t *testing.T) {
 		t.Fatalf(`Invalid feed URL, got %q`, entry.Feed.FeedURL)
 		t.Fatalf(`Invalid feed URL, got %q`, entry.Feed.FeedURL)
 	}
 	}
 
 
-	entry, err = regularUserClient.Entry(result.Entries[0].ID)
+	entry, err = regularUserClient.Entry(entries[0].ID)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	if entry.ID != result.Entries[0].ID {
+	if entry.ID != entries[0].ID {
 		t.Fatalf(`Invalid entryID, got %d`, entry.ID)
 		t.Fatalf(`Invalid entryID, got %d`, entry.ID)
 	}
 	}
 
 
-	entry, err = regularUserClient.CategoryEntry(result.Entries[0].Feed.Category.ID, result.Entries[0].ID)
+	entry, err = regularUserClient.CategoryEntry(entries[0].Feed.Category.ID, entries[0].ID)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	if entry.ID != result.Entries[0].ID {
+	if entry.ID != entries[0].ID {
 		t.Fatalf(`Invalid entryID, got %d`, entry.ID)
 		t.Fatalf(`Invalid entryID, got %d`, entry.ID)
 	}
 	}
 }
 }
@@ -289,13 +288,13 @@ func TestUpdateEntryStatusEndpoint(t *testing.T) {
 
 
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	result := listFeedEntries(t, regularUserClient, feedID, nil)
+	entryID := servertest.FeedEntries(t, regularUserClient, feedID)[0].ID
 
 
-	if err := regularUserClient.UpdateEntries([]int64{result.Entries[0].ID}, miniflux.EntryStatusRead); err != nil {
+	if err := regularUserClient.UpdateEntries([]int64{entryID}, miniflux.EntryStatusRead); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	entry, err := regularUserClient.Entry(result.Entries[0].ID)
+	entry, err := regularUserClient.Entry(entryID)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -314,9 +313,7 @@ func TestUpdateEntriesStarredEndpoint(t *testing.T) {
 
 
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	result := listFeedEntries(t, regularUserClient, feedID, nil)
-
-	entryID := result.Entries[0].ID
+	entryID := servertest.FeedEntries(t, regularUserClient, feedID)[0].ID
 
 
 	// Star the entry without changing its status.
 	// Star the entry without changing its status.
 	if err := regularUserClient.UpdateEntriesStarred([]int64{entryID}, true); err != nil {
 	if err := regularUserClient.UpdateEntriesStarred([]int64{entryID}, true); err != nil {
@@ -358,8 +355,6 @@ func TestGetEntryIDsEndpoint(t *testing.T) {
 
 
 	regularUserClient, _ := newRegularUser(t)
 	regularUserClient, _ := newRegularUser(t)
 
 
-	boolPtr := func(value bool) *bool { return &value }
-
 	// A new user should have no entries at all.
 	// A new user should have no entries at all.
 	result, err := regularUserClient.EntryIDs(nil)
 	result, err := regularUserClient.EntryIDs(nil)
 	if err != nil {
 	if err != nil {
@@ -381,11 +376,7 @@ func TestGetEntryIDsEndpoint(t *testing.T) {
 	// Subscribe to a feed so there are entries.
 	// Subscribe to a feed so there are entries.
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	allEntries := listFeedEntries(t, regularUserClient, feedID, nil)
-
-	if len(allEntries.Entries) != servertest.EntryCount {
-		t.Fatalf(`Expected %d entries in the feed, got %d`, servertest.EntryCount, len(allEntries.Entries))
-	}
+	entries := servertest.FeedEntries(t, regularUserClient, feedID)
 
 
 	// Without filters, all entries should be returned.
 	// Without filters, all entries should be returned.
 	result, err = regularUserClient.EntryIDs(nil)
 	result, err = regularUserClient.EntryIDs(nil)
@@ -393,12 +384,12 @@ func TestGetEntryIDsEndpoint(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	if len(result.EntryIDs) != allEntries.Total {
-		t.Fatalf(`Expected %d entry IDs, got %d`, allEntries.Total, len(result.EntryIDs))
+	if len(result.EntryIDs) != servertest.EntryCount {
+		t.Fatalf(`Expected %d entry IDs, got %d`, servertest.EntryCount, len(result.EntryIDs))
 	}
 	}
 
 
-	if result.Total != allEntries.Total {
-		t.Fatalf(`Expected total %d, got %d`, allEntries.Total, result.Total)
+	if result.Total != servertest.EntryCount {
+		t.Fatalf(`Expected total %d, got %d`, servertest.EntryCount, result.Total)
 	}
 	}
 
 
 	// Filter by status=unread: all entries should be unread initially.
 	// Filter by status=unread: all entries should be unread initially.
@@ -407,12 +398,12 @@ func TestGetEntryIDsEndpoint(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	if len(unreadResult.EntryIDs) != allEntries.Total {
-		t.Fatalf(`Expected %d unread entry IDs, got %d`, allEntries.Total, len(unreadResult.EntryIDs))
+	if len(unreadResult.EntryIDs) != servertest.EntryCount {
+		t.Fatalf(`Expected %d unread entry IDs, got %d`, servertest.EntryCount, len(unreadResult.EntryIDs))
 	}
 	}
 
 
 	// Mark one entry as read and verify status filter results update.
 	// Mark one entry as read and verify status filter results update.
-	firstEntryID := allEntries.Entries[0].ID
+	firstEntryID := entries[0].ID
 	if err := regularUserClient.UpdateEntries([]int64{firstEntryID}, miniflux.EntryStatusRead); err != nil {
 	if err := regularUserClient.UpdateEntries([]int64{firstEntryID}, miniflux.EntryStatusRead); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -422,12 +413,12 @@ func TestGetEntryIDsEndpoint(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	if len(unreadResult.EntryIDs) != allEntries.Total-1 {
-		t.Fatalf(`Expected %d unread entry IDs after marking one as read, got %d`, allEntries.Total-1, len(unreadResult.EntryIDs))
+	if len(unreadResult.EntryIDs) != servertest.EntryCount-1 {
+		t.Fatalf(`Expected %d unread entry IDs after marking one as read, got %d`, servertest.EntryCount-1, len(unreadResult.EntryIDs))
 	}
 	}
 
 
-	if unreadResult.Total != allEntries.Total-1 {
-		t.Fatalf(`Expected total %d after marking one as read, got %d`, allEntries.Total-1, unreadResult.Total)
+	if unreadResult.Total != servertest.EntryCount-1 {
+		t.Fatalf(`Expected total %d after marking one as read, got %d`, servertest.EntryCount-1, unreadResult.Total)
 	}
 	}
 
 
 	for _, id := range unreadResult.EntryIDs {
 	for _, id := range unreadResult.EntryIDs {
@@ -455,8 +446,8 @@ func TestGetEntryIDsEndpoint(t *testing.T) {
 		t.Fatalf(`Expected 1 entry ID with limit=1, got %d`, len(pagedResult.EntryIDs))
 		t.Fatalf(`Expected 1 entry ID with limit=1, got %d`, len(pagedResult.EntryIDs))
 	}
 	}
 
 
-	if pagedResult.Total != allEntries.Total-1 {
-		t.Fatalf(`Expected total %d with limit=1, got %d`, allEntries.Total-1, pagedResult.Total)
+	if pagedResult.Total != servertest.EntryCount-1 {
+		t.Fatalf(`Expected total %d with limit=1, got %d`, servertest.EntryCount-1, pagedResult.Total)
 	}
 	}
 
 
 	// offset=1 should skip the first entry.
 	// offset=1 should skip the first entry.
@@ -474,7 +465,7 @@ func TestGetEntryIDsEndpoint(t *testing.T) {
 	}
 	}
 
 
 	// Filter by starred=true: initially no starred entries.
 	// Filter by starred=true: initially no starred entries.
-	starredResult, err := regularUserClient.EntryIDs(&miniflux.EntryIDsFilter{Starred: boolPtr(true)})
+	starredResult, err := regularUserClient.EntryIDs(&miniflux.EntryIDsFilter{Starred: new(true)})
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -488,7 +479,7 @@ func TestGetEntryIDsEndpoint(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	starredResult, err = regularUserClient.EntryIDs(&miniflux.EntryIDsFilter{Starred: boolPtr(true)})
+	starredResult, err = regularUserClient.EntryIDs(&miniflux.EntryIDsFilter{Starred: new(true)})
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -506,7 +497,7 @@ func TestGetEntryIDsEndpoint(t *testing.T) {
 	}
 	}
 
 
 	// starred=false should exclude the starred entry.
 	// starred=false should exclude the starred entry.
-	notStarredResult, err := regularUserClient.EntryIDs(&miniflux.EntryIDsFilter{Starred: boolPtr(false)})
+	notStarredResult, err := regularUserClient.EntryIDs(&miniflux.EntryIDsFilter{Starred: new(false)})
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -518,7 +509,7 @@ func TestGetEntryIDsEndpoint(t *testing.T) {
 	}
 	}
 
 
 	// Pagination with offset past the single starred result should return 0 entries but total 1.
 	// Pagination with offset past the single starred result should return 0 entries but total 1.
-	pagedStarred, err := regularUserClient.EntryIDs(&miniflux.EntryIDsFilter{Starred: boolPtr(true), Offset: 1})
+	pagedStarred, err := regularUserClient.EntryIDs(&miniflux.EntryIDsFilter{Starred: new(true), Offset: 1})
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -536,7 +527,7 @@ func TestGetEntryIDsEndpoint(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	starredResult, err = regularUserClient.EntryIDs(&miniflux.EntryIDsFilter{Starred: boolPtr(true)})
+	starredResult, err = regularUserClient.EntryIDs(&miniflux.EntryIDsFilter{Starred: new(true)})
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -565,14 +556,14 @@ func TestUpdateEntryEndpoint(t *testing.T) {
 
 
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	result := listFeedEntries(t, regularUserClient, feedID, nil)
+	entryID := servertest.FeedEntries(t, regularUserClient, feedID)[0].ID
 
 
 	entryUpdateRequest := &miniflux.EntryModificationRequest{
 	entryUpdateRequest := &miniflux.EntryModificationRequest{
 		Title:   new("New title"),
 		Title:   new("New title"),
 		Content: new("New content"),
 		Content: new("New content"),
 	}
 	}
 
 
-	updatedEntry, err := regularUserClient.UpdateEntry(result.Entries[0].ID, entryUpdateRequest)
+	updatedEntry, err := regularUserClient.UpdateEntry(entryID, entryUpdateRequest)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -585,7 +576,7 @@ func TestUpdateEntryEndpoint(t *testing.T) {
 		t.Errorf(`Invalid content, got %q`, updatedEntry.Content)
 		t.Errorf(`Invalid content, got %q`, updatedEntry.Content)
 	}
 	}
 
 
-	entry, err := regularUserClient.Entry(result.Entries[0].ID)
+	entry, err := regularUserClient.Entry(entryID)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -608,13 +599,13 @@ func TestToggleStarredEndpoint(t *testing.T) {
 
 
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	result := listFeedEntries(t, regularUserClient, feedID, &miniflux.Filter{Limit: 1})
+	entryID := servertest.FeedEntries(t, regularUserClient, feedID)[0].ID
 
 
-	if err := regularUserClient.ToggleStarred(result.Entries[0].ID); err != nil {
+	if err := regularUserClient.ToggleStarred(entryID); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	entry, err := regularUserClient.Entry(result.Entries[0].ID)
+	entry, err := regularUserClient.Entry(entryID)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -638,18 +629,17 @@ func TestToggleStarredEndpoint(t *testing.T) {
 		t.Fatalf(`The entry should no longer be starred`)
 		t.Fatalf(`The entry should no longer be starred`)
 	}
 	}
 
 
-	nonExistingEntryID := int64(math.MaxInt64)
-	if err := regularUserClient.ToggleStarred(nonExistingEntryID); !errors.Is(err, miniflux.ErrNotFound) {
-		t.Fatalf(`Expected Not Found when toggling the starred flag of a non existent entry: %v`, err)
+	if err := regularUserClient.ToggleStarred(nonexistentID); !errors.Is(err, miniflux.ErrNotFound) {
+		t.Fatalf(`Expected Not Found when toggling the starred flag of a nonexistent entry: %v`, err)
 	}
 	}
 
 
 	otherUserClient, _ := newRegularUser(t)
 	otherUserClient, _ := newRegularUser(t)
 
 
 	otherFeedID := fixture.Subscribe(t, otherUserClient)
 	otherFeedID := fixture.Subscribe(t, otherUserClient)
 
 
-	result = listFeedEntries(t, otherUserClient, otherFeedID, &miniflux.Filter{Limit: 1})
+	otherUserEntryID := servertest.FeedEntries(t, otherUserClient, otherFeedID)[0].ID
 
 
-	if err := regularUserClient.ToggleStarred(result.Entries[0].ID); !errors.Is(err, miniflux.ErrNotFound) {
+	if err := regularUserClient.ToggleStarred(otherUserEntryID); !errors.Is(err, miniflux.ErrNotFound) {
 		t.Fatalf(`Expected Not Found when toggling the starred flag of another user's entry: %v`, err)
 		t.Fatalf(`Expected Not Found when toggling the starred flag of another user's entry: %v`, err)
 	}
 	}
 }
 }
@@ -663,9 +653,7 @@ func TestShareEntryEndpoint(t *testing.T) {
 
 
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	result := listFeedEntries(t, regularUserClient, feedID, &miniflux.Filter{Limit: 1})
-
-	entryID := result.Entries[0].ID
+	entryID := servertest.FeedEntries(t, regularUserClient, feedID)[0].ID
 
 
 	entryBeforeShare, err := regularUserClient.Entry(entryID)
 	entryBeforeShare, err := regularUserClient.Entry(entryID)
 	if err != nil {
 	if err != nil {
@@ -718,21 +706,18 @@ func TestShareEntryEndpoint(t *testing.T) {
 		t.Fatalf(`Unsharing should update the entry change date, got %v before and %v after`, entryAfterShare.ChangedAt, entryAfterUnshare.ChangedAt)
 		t.Fatalf(`Unsharing should update the entry change date, got %v before and %v after`, entryAfterShare.ChangedAt, entryAfterUnshare.ChangedAt)
 	}
 	}
 
 
-	nonExistingEntryID := int64(math.MaxInt64)
-	if _, err = regularUserClient.ShareEntry(nonExistingEntryID); !errors.Is(err, miniflux.ErrNotFound) {
-		t.Fatalf(`Expected Not Found when sharing non existent entry: %v`, err)
+	if _, err = regularUserClient.ShareEntry(nonexistentID); !errors.Is(err, miniflux.ErrNotFound) {
+		t.Fatalf(`Expected Not Found when sharing a nonexistent entry: %v`, err)
 	}
 	}
-	if err = regularUserClient.UnshareEntry(nonExistingEntryID); !errors.Is(err, miniflux.ErrNotFound) {
-		t.Fatalf(`Expected Not Found when unsharing non existent entry: %v`, err)
+	if err = regularUserClient.UnshareEntry(nonexistentID); !errors.Is(err, miniflux.ErrNotFound) {
+		t.Fatalf(`Expected Not Found when unsharing a nonexistent entry: %v`, err)
 	}
 	}
 
 
 	otherUserClient, _ := newRegularUser(t)
 	otherUserClient, _ := newRegularUser(t)
 
 
 	otherFeedID := fixture.Subscribe(t, otherUserClient)
 	otherFeedID := fixture.Subscribe(t, otherUserClient)
 
 
-	result = listFeedEntries(t, otherUserClient, otherFeedID, &miniflux.Filter{Limit: 1})
-
-	otherUserEntryID := result.Entries[0].ID
+	otherUserEntryID := servertest.FeedEntries(t, otherUserClient, otherFeedID)[0].ID
 	if _, err = regularUserClient.ShareEntry(otherUserEntryID); !errors.Is(err, miniflux.ErrNotFound) {
 	if _, err = regularUserClient.ShareEntry(otherUserEntryID); !errors.Is(err, miniflux.ErrNotFound) {
 		t.Fatalf(`Expected Not Found when sharing other user's entry: %v`, err)
 		t.Fatalf(`Expected Not Found when sharing other user's entry: %v`, err)
 	}
 	}
@@ -750,9 +735,9 @@ func TestSaveEntryEndpoint(t *testing.T) {
 
 
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	result := listFeedEntries(t, regularUserClient, feedID, &miniflux.Filter{Limit: 1})
+	entryID := servertest.FeedEntries(t, regularUserClient, feedID)[0].ID
 
 
-	if err := regularUserClient.SaveEntry(result.Entries[0].ID); !errors.Is(err, miniflux.ErrBadRequest) {
+	if err := regularUserClient.SaveEntry(entryID); !errors.Is(err, miniflux.ErrBadRequest) {
 		t.Fatalf(`Saving an entry should raise a bad request error because no integration is configured, got %v`, err)
 		t.Fatalf(`Saving an entry should raise a bad request error because no integration is configured, got %v`, err)
 	}
 	}
 }
 }
@@ -766,9 +751,9 @@ func TestFetchContentEndpoint(t *testing.T) {
 
 
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	result := listFeedEntries(t, regularUserClient, feedID, &miniflux.Filter{Limit: 1})
+	entryID := servertest.FeedEntries(t, regularUserClient, feedID)[0].ID
 
 
-	content, err := regularUserClient.FetchEntryOriginalContent(result.Entries[0].ID)
+	content, err := regularUserClient.FetchEntryOriginalContent(entryID)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
@@ -787,7 +772,7 @@ func TestFlushHistoryEndpoint(t *testing.T) {
 
 
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
-	result := listFeedEntries(t, regularUserClient, feedID, &miniflux.Filter{Limit: 3})
+	entries := servertest.FeedEntries(t, regularUserClient, feedID)
 
 
 	// The API replies before the history is flushed in the background.
 	// The API replies before the history is flushed in the background.
 	waitForNoReadEntries := func() {
 	waitForNoReadEntries := func() {
@@ -809,7 +794,7 @@ func TestFlushHistoryEndpoint(t *testing.T) {
 		}
 		}
 	}
 	}
 
 
-	if err := regularUserClient.UpdateEntries([]int64{result.Entries[0].ID, result.Entries[1].ID}, miniflux.EntryStatusRead); err != nil {
+	if err := regularUserClient.UpdateEntries([]int64{entries[0].ID, entries[1].ID}, miniflux.EntryStatusRead); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
@@ -819,7 +804,7 @@ func TestFlushHistoryEndpoint(t *testing.T) {
 	waitForNoReadEntries()
 	waitForNoReadEntries()
 
 
 	// The endpoint also accepts the DELETE method, which the client does not use.
 	// The endpoint also accepts the DELETE method, which the client does not use.
-	if err := regularUserClient.UpdateEntries([]int64{result.Entries[2].ID}, miniflux.EntryStatusRead); err != nil {
+	if err := regularUserClient.UpdateEntries([]int64{entries[2].ID}, miniflux.EntryStatusRead); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
@@ -836,7 +821,6 @@ func TestImportFeedEntryEndpoint(t *testing.T) {
 
 
 	client, _ := newRegularUser(t)
 	client, _ := newRegularUser(t)
 
 
-	// Create a feed
 	feedID := fixture.Subscribe(t, client)
 	feedID := fixture.Subscribe(t, client)
 
 
 	payload := map[string]any{
 	payload := map[string]any{
@@ -849,7 +833,6 @@ func TestImportFeedEntryEndpoint(t *testing.T) {
 		"published_at": 0,
 		"published_at": 0,
 	}
 	}
 
 
-	// First import
 	firstID, err := client.ImportFeedEntry(feedID, payload)
 	firstID, err := client.ImportFeedEntry(feedID, payload)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
@@ -859,7 +842,7 @@ func TestImportFeedEntryEndpoint(t *testing.T) {
 		t.Fatal("expected non-zero entry ID on first import")
 		t.Fatal("expected non-zero entry ID on first import")
 	}
 	}
 
 
-	// Second import (same payload)
+	// Importing the same external ID again returns the existing entry.
 	secondID, err := client.ImportFeedEntry(feedID, payload)
 	secondID, err := client.ImportFeedEntry(feedID, payload)
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)

+ 0 - 84
internal/api/entry_pagination_integration_test.go

@@ -1,84 +0,0 @@
-// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
-// SPDX-License-Identifier: Apache-2.0
-
-package api_test
-
-import (
-	"fmt"
-	"net/http"
-	"net/http/httptest"
-	"slices"
-	"strings"
-	"testing"
-
-	miniflux "miniflux.app/v2/client"
-)
-
-func TestGetEntriesStablePaginationWithIdenticalPublishedDates(t *testing.T) {
-	t.Parallel()
-
-	const (
-		entryCount = 120
-		pageSize   = 25
-	)
-
-	var feed strings.Builder
-	feed.WriteString(`<?xml version="1.0"?><rss version="2.0"><channel><title>Pagination</title><link>https://example.org</link><description>Pagination test</description>`)
-	for index := range entryCount {
-		fmt.Fprintf(&feed, `<item><guid>pagination-%d</guid><title>Shared pagination title</title><link>https://example.org/%d</link><pubDate>Wed, 01 Jan 2025 00:00:00 GMT</pubDate><description>Shared pagination content</description></item>`, index, index)
-	}
-	feed.WriteString(`</channel></rss>`)
-	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-		w.Header().Set("Content-Type", "application/rss+xml")
-		fmt.Fprint(w, feed.String())
-	}))
-	defer server.Close()
-
-	client, _ := newRegularUser(t)
-	if _, err := client.CreateFeed(&miniflux.FeedCreationRequest{FeedURL: server.URL}); err != nil {
-		t.Fatal(err)
-	}
-
-	all, err := client.EntryIDs(nil)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if all.Total != entryCount || len(all.EntryIDs) != entryCount {
-		t.Fatalf("Got %d IDs and total %d, want %d", len(all.EntryIDs), all.Total, entryCount)
-	}
-
-	for _, direction := range []string{"asc", "desc"} {
-		want := slices.Clone(all.EntryIDs)
-		slices.Sort(want)
-		if direction == "desc" {
-			slices.Reverse(want)
-		}
-
-		for _, search := range []string{"", "pagination"} {
-			t.Run(direction+"/search="+search, func(t *testing.T) {
-				var got []int64
-				for offset := 0; offset < len(want); offset += pageSize {
-					page, err := client.Entries(&miniflux.Filter{
-						Order:     "published_at",
-						Direction: direction,
-						Search:    search,
-						Limit:     pageSize,
-						Offset:    offset,
-					})
-					if err != nil {
-						t.Fatal(err)
-					}
-					if page.Total != len(want) {
-						t.Fatalf("Got total %d, want %d", page.Total, len(want))
-					}
-					for _, entry := range page.Entries {
-						got = append(got, entry.ID)
-					}
-				}
-				if !slices.Equal(got, want) {
-					t.Fatalf("Got IDs %v, want %v", got, want)
-				}
-			})
-		}
-	}
-}

+ 10 - 8
internal/api/entry_query_integration_test.go

@@ -27,7 +27,7 @@ func newEntryQueryAPI(t *testing.T) (http.Handler, *sql.DB) {
 
 
 	databaseURL := os.Getenv("TEST_DATABASE_URL")
 	databaseURL := os.Getenv("TEST_DATABASE_URL")
 	if databaseURL == "" {
 	if databaseURL == "" {
-		t.Skip("Set TEST_DATABASE_URL to a migrated PostgreSQL database to run API query integration tests")
+		t.Skip("Set TEST_DATABASE_URL to a PostgreSQL database to run the integration tests")
 	}
 	}
 
 
 	previousOptions := config.Opts
 	previousOptions := config.Opts
@@ -447,10 +447,12 @@ func TestEntryQueryAPIRejectsForeignScopes(t *testing.T) {
 		"/v1/feeds/16/entries?feed_id=11", "/v1/feeds/16/entries?feed_id=0",
 		"/v1/feeds/16/entries?feed_id=11", "/v1/feeds/16/entries?feed_id=0",
 		"/v1/categories/40/entries?category_id=10", "/v1/categories/40/entries?category_id=0",
 		"/v1/categories/40/entries?category_id=10", "/v1/categories/40/entries?category_id=0",
 	} {
 	} {
-		recorder := entryQueryAPIRequest(api, http.MethodGet, path, "")
-		if recorder.Code != http.StatusBadRequest {
-			t.Fatalf("%s: got status %d, want 400: %s", path, recorder.Code, recorder.Body.String())
-		}
+		t.Run(path, func(t *testing.T) {
+			recorder := entryQueryAPIRequest(api, http.MethodGet, path, "")
+			if recorder.Code != http.StatusBadRequest {
+				t.Fatalf("Got status %d, want 400: %s", recorder.Code, recorder.Body.String())
+			}
+		})
 	}
 	}
 }
 }
 
 
@@ -465,9 +467,9 @@ func TestEntryQueryAPIRejectsInvalidRouteScopedQueryIDs(t *testing.T) {
 		"/v1/categories/10/entries?feed_id=&feed_id=-1",
 		"/v1/categories/10/entries?feed_id=&feed_id=-1",
 	} {
 	} {
 		t.Run(path, func(t *testing.T) {
 		t.Run(path, func(t *testing.T) {
-			w := entryQueryAPIRequest(api, http.MethodGet, path, "")
-			if w.Code != http.StatusBadRequest {
-				t.Fatalf("Got status %d, want 400: %s", w.Code, w.Body.String())
+			recorder := entryQueryAPIRequest(api, http.MethodGet, path, "")
+			if recorder.Code != http.StatusBadRequest {
+				t.Fatalf("Got status %d, want 400: %s", recorder.Code, recorder.Body.String())
 			}
 			}
 		})
 		})
 	}
 	}

+ 19 - 26
internal/api/feed_integration_test.go

@@ -4,9 +4,9 @@
 package api_test
 package api_test
 
 
 import (
 import (
-	"bytes"
 	"errors"
 	"errors"
 	"io"
 	"io"
+	"strings"
 	"testing"
 	"testing"
 
 
 	miniflux "miniflux.app/v2/client"
 	miniflux "miniflux.app/v2/client"
@@ -44,11 +44,7 @@ func TestCannotCreateDuplicatedFeed(t *testing.T) {
 
 
 	regularUserClient, _ := newRegularUser(t)
 	regularUserClient, _ := newRegularUser(t)
 
 
-	feedID := fixture.Subscribe(t, regularUserClient)
-
-	if feedID == 0 {
-		t.Fatalf(`Invalid feedID, got "%v"`, feedID)
-	}
+	fixture.Subscribe(t, regularUserClient)
 
 
 	_, err := regularUserClient.CreateFeed(&miniflux.FeedCreationRequest{
 	_, err := regularUserClient.CreateFeed(&miniflux.FeedCreationRequest{
 		FeedURL: fixture.FeedURL,
 		FeedURL: fixture.FeedURL,
@@ -85,19 +81,19 @@ func TestFeedCreationWithoutCategoryReturnsBadRequest(t *testing.T) {
 	t.Run("OPML import", func(t *testing.T) {
 	t.Run("OPML import", func(t *testing.T) {
 		data := `<?xml version="1.0" encoding="UTF-8"?>
 		data := `<?xml version="1.0" encoding="UTF-8"?>
 <opml version="2.0">
 <opml version="2.0">
-    <body>
-        <outline title="Test" text="Test" xmlUrl="` + fixture.FeedURL + `"></outline>
-    </body>
+	<body>
+		<outline title="Test" text="Test" xmlUrl="` + fixture.FeedURL + `"></outline>
+	</body>
 </opml>`
 </opml>`
 
 
-		err := regularUserClient.Import(io.NopCloser(bytes.NewReader([]byte(data))))
+		err := regularUserClient.Import(io.NopCloser(strings.NewReader(data)))
 		if !errors.Is(err, miniflux.ErrBadRequest) {
 		if !errors.Is(err, miniflux.ErrBadRequest) {
 			t.Fatalf(`Expected a bad request error, got %v`, err)
 			t.Fatalf(`Expected a bad request error, got %v`, err)
 		}
 		}
 	})
 	})
 }
 }
 
 
-func TestCreateFeedWithInexistingCategory(t *testing.T) {
+func TestCreateFeedWithNonexistentCategory(t *testing.T) {
 	t.Parallel()
 	t.Parallel()
 
 
 	fixture := servertest.NewFeedFixture(t)
 	fixture := servertest.NewFeedFixture(t)
@@ -106,11 +102,10 @@ func TestCreateFeedWithInexistingCategory(t *testing.T) {
 
 
 	_, err := regularUserClient.CreateFeed(&miniflux.FeedCreationRequest{
 	_, err := regularUserClient.CreateFeed(&miniflux.FeedCreationRequest{
 		FeedURL:    fixture.FeedURL,
 		FeedURL:    fixture.FeedURL,
-		CategoryID: 123456789,
+		CategoryID: nonexistentID,
 	})
 	})
-
 	if !errors.Is(err, miniflux.ErrBadRequest) {
 	if !errors.Is(err, miniflux.ErrBadRequest) {
-		t.Fatalf(`Creating a feed with an inexisting category should raise an error, got %v`, err)
+		t.Fatalf(`Creating a feed with a nonexistent category should raise an error, got %v`, err)
 	}
 	}
 }
 }
 
 
@@ -272,11 +267,11 @@ func TestUpdateFeedWithInvalidCategory(t *testing.T) {
 	feedID := fixture.Subscribe(t, regularUserClient)
 	feedID := fixture.Subscribe(t, regularUserClient)
 
 
 	feedUpdateRequest := &miniflux.FeedModificationRequest{
 	feedUpdateRequest := &miniflux.FeedModificationRequest{
-		CategoryID: new(int64(123456789)),
+		CategoryID: new(nonexistentID),
 	}
 	}
 
 
 	if _, err := regularUserClient.UpdateFeed(feedID, feedUpdateRequest); !errors.Is(err, miniflux.ErrBadRequest) {
 	if _, err := regularUserClient.UpdateFeed(feedID, feedUpdateRequest); !errors.Is(err, miniflux.ErrBadRequest) {
-		t.Fatalf(`Updating a feed with an inexisting category should raise an error, got %v`, err)
+		t.Fatalf(`Updating a feed with a nonexistent category should raise an error, got %v`, err)
 	}
 	}
 }
 }
 
 
@@ -320,16 +315,16 @@ func TestFeedRuleValidation(t *testing.T) {
 		},
 		},
 	}
 	}
 
 
-	for _, tc := range testCases {
-		t.Run(tc.name, func(t *testing.T) {
+	for _, test := range testCases {
+		t.Run(test.name, func(t *testing.T) {
 			// The URL must not be subscribed yet: a duplicate feed is rejected before its rules are checked.
 			// The URL must not be subscribed yet: a duplicate feed is rejected before its rules are checked.
-			tc.create.FeedURL = servertest.NewFeedFixture(t).FeedURL
-			if _, err := regularUserClient.CreateFeed(&tc.create); !errors.Is(err, miniflux.ErrBadRequest) {
-				t.Errorf(`Creating a feed should reject the %s, got %v`, tc.name, err)
+			test.create.FeedURL = servertest.NewFeedFixture(t).FeedURL
+			if _, err := regularUserClient.CreateFeed(&test.create); !errors.Is(err, miniflux.ErrBadRequest) {
+				t.Errorf(`Creating a feed should reject the %s, got %v`, test.name, err)
 			}
 			}
 
 
-			if _, err := regularUserClient.UpdateFeed(feedID, &tc.update); !errors.Is(err, miniflux.ErrBadRequest) {
-				t.Errorf(`Updating a feed should reject the %s, got %v`, tc.name, err)
+			if _, err := regularUserClient.UpdateFeed(feedID, &test.update); !errors.Is(err, miniflux.ErrBadRequest) {
+				t.Errorf(`Updating a feed should reject the %s, got %v`, test.name, err)
 			}
 			}
 		})
 		})
 	}
 	}
@@ -348,9 +343,7 @@ func TestMarkFeedAsReadEndpoint(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	results := listFeedEntries(t, regularUserClient, feedID, nil)
-
-	for _, entry := range results.Entries {
+	for _, entry := range servertest.FeedEntries(t, regularUserClient, feedID) {
 		if entry.Status != miniflux.EntryStatusRead {
 		if entry.Status != miniflux.EntryStatusRead {
 			t.Errorf(`Status for entry %d was %q instead of %q`, entry.ID, entry.Status, miniflux.EntryStatusRead)
 			t.Errorf(`Status for entry %d was %q instead of %q`, entry.ID, entry.Status, miniflux.EntryStatusRead)
 		}
 		}

+ 6 - 6
internal/api/icon_integration_test.go

@@ -55,23 +55,23 @@ func TestGetFeedIcon(t *testing.T) {
 	}
 	}
 }
 }
 
 
-func TestGetFeedIconWithInexistingFeedID(t *testing.T) {
+func TestGetFeedIconWithNonexistentFeedID(t *testing.T) {
 	t.Parallel()
 	t.Parallel()
 
 
 	client := newAdminClient(t)
 	client := newAdminClient(t)
-	_, err := client.FeedIcon(123456789)
+	_, err := client.FeedIcon(nonexistentID)
 	if !errors.Is(err, miniflux.ErrNotFound) {
 	if !errors.Is(err, miniflux.ErrNotFound) {
-		t.Fatalf(`Fetching the icon of an inexisting feed should raise an error, got %v`, err)
+		t.Fatalf(`Fetching the icon of a nonexistent feed should raise an error, got %v`, err)
 	}
 	}
 }
 }
 
 
-func TestGetIconWithInexistingIconID(t *testing.T) {
+func TestGetIconWithNonexistentIconID(t *testing.T) {
 	t.Parallel()
 	t.Parallel()
 
 
 	client := newAdminClient(t)
 	client := newAdminClient(t)
-	_, err := client.Icon(123456789)
+	_, err := client.Icon(nonexistentID)
 	if !errors.Is(err, miniflux.ErrNotFound) {
 	if !errors.Is(err, miniflux.ErrNotFound) {
-		t.Fatalf(`Fetching an inexisting icon should return a "not found" error, got %v`, err)
+		t.Fatalf(`Fetching a nonexistent icon should return a "not found" error, got %v`, err)
 	}
 	}
 }
 }
 
 

+ 5 - 11
internal/api/integration_server_test.go

@@ -5,6 +5,7 @@ package api_test
 
 
 import (
 import (
 	"fmt"
 	"fmt"
+	"math"
 	"math/rand/v2"
 	"math/rand/v2"
 	"net/http"
 	"net/http"
 	"testing"
 	"testing"
@@ -20,6 +21,10 @@ const (
 
 
 	// regularUserPassword is the password of the users created by newRegularUser.
 	// regularUserPassword is the password of the users created by newRegularUser.
 	regularUserPassword = "regular_test_user_password"
 	regularUserPassword = "regular_test_user_password"
+
+	// nonexistentID is an ID that no category, entry, enclosure, feed or icon has.
+	// It fits the integer columns of PostgreSQL, so that lookups reach the "not found" path.
+	nonexistentID int64 = math.MaxInt32
 )
 )
 
 
 func TestMain(m *testing.M) {
 func TestMain(m *testing.M) {
@@ -91,14 +96,3 @@ func requestStatus(t *testing.T, user *miniflux.User, method, path string) int {
 	status, _ := servertest.Send(t, request)
 	status, _ := servertest.Send(t, request)
 	return status
 	return status
 }
 }
-
-// listFeedEntries returns the entries of the feed that match the filter.
-func listFeedEntries(t *testing.T, client *miniflux.Client, feedID int64, filter *miniflux.Filter) *miniflux.EntryResultSet {
-	t.Helper()
-
-	result, err := client.FeedEntries(feedID, filter)
-	if err != nil {
-		t.Fatal(err)
-	}
-	return result
-}

+ 21 - 23
internal/api/opml_integration_test.go

@@ -4,7 +4,6 @@
 package api_test
 package api_test
 
 
 import (
 import (
-	"bytes"
 	"encoding/json"
 	"encoding/json"
 	"errors"
 	"errors"
 	"io"
 	"io"
@@ -48,16 +47,15 @@ func TestImportEndpoint(t *testing.T) {
 	regularUserClient, _ := newRegularUser(t)
 	regularUserClient, _ := newRegularUser(t)
 
 
 	data := `<?xml version="1.0" encoding="UTF-8"?>
 	data := `<?xml version="1.0" encoding="UTF-8"?>
-    <opml version="2.0">
-        <body>
-            <outline text="Test Category">
-				<outline title="Test" text="Test" xmlUrl="` + fixture.FeedURL + `" htmlUrl="` + fixture.WebsiteURL + `"></outline>
-			</outline>
-		</body>
-	</opml>`
-
-	bytesReader := bytes.NewReader([]byte(data))
-	if err := regularUserClient.Import(io.NopCloser(bytesReader)); err != nil {
+<opml version="2.0">
+	<body>
+		<outline text="Test Category">
+			<outline title="Test" text="Test" xmlUrl="` + fixture.FeedURL + `" htmlUrl="` + fixture.WebsiteURL + `"></outline>
+		</outline>
+	</body>
+</opml>`
+
+	if err := regularUserClient.Import(io.NopCloser(strings.NewReader(data))); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
@@ -85,18 +83,18 @@ func TestImportEndpointSkipsInvalidFeeds(t *testing.T) {
 	regularUserClient, regularUser := newRegularUser(t)
 	regularUserClient, regularUser := newRegularUser(t)
 
 
 	data := `<?xml version="1.0" encoding="UTF-8"?>
 	data := `<?xml version="1.0" encoding="UTF-8"?>
-	<opml version="2.0" xmlns:miniflux="https://miniflux.app/opml">
-		<body>
-			<outline text="Valid Category">
-				<outline title="Valid" xmlUrl="https://example.org/valid.xml"></outline>
-				<outline title="Duplicate" xmlUrl="https://example.org/valid.xml"></outline>
-			</outline>
-			<outline text="Invalid Category">
-				<outline title="Unsupported scheme" xmlUrl="feed://example.org/feed.xml"></outline>
-				<outline title="Invalid rule" xmlUrl="https://example.org/invalid-rule.xml" miniflux:keeplistRules="["></outline>
-			</outline>
-		</body>
-	</opml>`
+<opml version="2.0" xmlns:miniflux="https://miniflux.app/opml">
+	<body>
+		<outline text="Valid Category">
+			<outline title="Valid" xmlUrl="https://example.org/valid.xml"></outline>
+			<outline title="Duplicate" xmlUrl="https://example.org/valid.xml"></outline>
+		</outline>
+		<outline text="Invalid Category">
+			<outline title="Unsupported scheme" xmlUrl="feed://example.org/feed.xml"></outline>
+			<outline title="Invalid rule" xmlUrl="https://example.org/invalid-rule.xml" miniflux:keeplistRules="["></outline>
+		</outline>
+	</body>
+</opml>`
 
 
 	request, err := http.NewRequest(http.MethodPost, servertest.Require(t).URL+"/v1/import", strings.NewReader(data))
 	request, err := http.NewRequest(http.MethodPost, servertest.Require(t).URL+"/v1/import", strings.NewReader(data))
 	if err != nil {
 	if err != nil {

+ 44 - 171
internal/api/user_integration_test.go

@@ -12,6 +12,45 @@ import (
 	"miniflux.app/v2/internal/http/server/servertest"
 	"miniflux.app/v2/internal/http/server/servertest"
 )
 )
 
 
+// checkDefaultUserSettings fails the test when a setting of the user is not the default of a new user.
+func checkDefaultUserSettings(t *testing.T, user *miniflux.User) {
+	t.Helper()
+
+	if user.Password != "" {
+		t.Errorf(`The password must not be returned, got %q`, user.Password)
+	}
+
+	settings := []struct {
+		name      string
+		got, want any
+	}{
+		{"language", user.Language, "en_US"},
+		{"theme", user.Theme, "light_serif"},
+		{"timezone", user.Timezone, "UTC"},
+		{"entries per page", user.EntriesPerPage, 100},
+		{"display mode", user.DisplayMode, "standalone"},
+		{"gesture navigation", user.GestureNav, "tap"},
+		{"default reading speed", user.DefaultReadingSpeed, 265},
+		{"CJK reading speed", user.CJKReadingSpeed, 500},
+	}
+	for _, setting := range settings {
+		if setting.got != setting.want {
+			t.Errorf(`Unexpected %s: got %v, want %v`, setting.name, setting.got, setting.want)
+		}
+	}
+}
+
+// checkSameUser fails the test when the users differ, ignoring the last login time that every API request updates.
+func checkSameUser(t *testing.T, got, want *miniflux.User) {
+	t.Helper()
+
+	gotUser, wantUser := *got, *want
+	gotUser.LastLoginAt, wantUser.LastLoginAt = nil, nil
+	if gotUser != wantUser {
+		t.Errorf(`Unexpected user: got %#v, want %#v`, gotUser, wantUser)
+	}
+}
+
 func TestGetMeEndpoint(t *testing.T) {
 func TestGetMeEndpoint(t *testing.T) {
 	t.Parallel()
 	t.Parallel()
 
 
@@ -47,45 +86,11 @@ func TestGetUsersEndpointAsAdmin(t *testing.T) {
 		t.Fatalf(`Invalid userID, got "%v"`, adminUser.ID)
 		t.Fatalf(`Invalid userID, got "%v"`, adminUser.ID)
 	}
 	}
 
 
-	if adminUser.Password != "" {
-		t.Fatalf(`Invalid password, got "%v"`, adminUser.Password)
-	}
-
-	if adminUser.Language != "en_US" {
-		t.Fatalf(`Invalid language, got "%v"`, adminUser.Language)
-	}
-
-	if adminUser.Theme != "light_serif" {
-		t.Fatalf(`Invalid theme, got "%v"`, adminUser.Theme)
-	}
-
-	if adminUser.Timezone != "UTC" {
-		t.Fatalf(`Invalid timezone, got "%v"`, adminUser.Timezone)
-	}
-
 	if !adminUser.IsAdmin {
 	if !adminUser.IsAdmin {
 		t.Fatalf(`Invalid role, got "%v"`, adminUser.IsAdmin)
 		t.Fatalf(`Invalid role, got "%v"`, adminUser.IsAdmin)
 	}
 	}
 
 
-	if adminUser.EntriesPerPage != 100 {
-		t.Fatalf(`Invalid entries per page, got "%v"`, adminUser.EntriesPerPage)
-	}
-
-	if adminUser.DisplayMode != "standalone" {
-		t.Fatalf(`Invalid web app display mode, got "%v"`, adminUser.DisplayMode)
-	}
-
-	if adminUser.GestureNav != "tap" {
-		t.Fatalf(`Invalid gesture navigation, got "%v"`, adminUser.GestureNav)
-	}
-
-	if adminUser.DefaultReadingSpeed != 265 {
-		t.Fatalf(`Invalid default reading speed, got "%v"`, adminUser.DefaultReadingSpeed)
-	}
-
-	if adminUser.CJKReadingSpeed != 500 {
-		t.Fatalf(`Invalid cjk reading speed, got "%v"`, adminUser.CJKReadingSpeed)
-	}
+	checkDefaultUserSettings(t, &adminUser)
 }
 }
 
 
 func TestGetUsersEndpointAsRegularUser(t *testing.T) {
 func TestGetUsersEndpointAsRegularUser(t *testing.T) {
@@ -114,45 +119,11 @@ func TestCreateUserEndpointAsAdmin(t *testing.T) {
 		t.Fatalf(`Invalid username, got "%v" instead of "%v"`, regularTestUser.Username, username)
 		t.Fatalf(`Invalid username, got "%v" instead of "%v"`, regularTestUser.Username, username)
 	}
 	}
 
 
-	if regularTestUser.Password != "" {
-		t.Fatalf(`Invalid password, got "%v"`, regularTestUser.Password)
-	}
-
-	if regularTestUser.Language != "en_US" {
-		t.Fatalf(`Invalid language, got "%v"`, regularTestUser.Language)
-	}
-
-	if regularTestUser.Theme != "light_serif" {
-		t.Fatalf(`Invalid theme, got "%v"`, regularTestUser.Theme)
-	}
-
-	if regularTestUser.Timezone != "UTC" {
-		t.Fatalf(`Invalid timezone, got "%v"`, regularTestUser.Timezone)
-	}
-
 	if regularTestUser.IsAdmin {
 	if regularTestUser.IsAdmin {
 		t.Fatalf(`Invalid role, got "%v"`, regularTestUser.IsAdmin)
 		t.Fatalf(`Invalid role, got "%v"`, regularTestUser.IsAdmin)
 	}
 	}
 
 
-	if regularTestUser.EntriesPerPage != 100 {
-		t.Fatalf(`Invalid entries per page, got "%v"`, regularTestUser.EntriesPerPage)
-	}
-
-	if regularTestUser.DisplayMode != "standalone" {
-		t.Fatalf(`Invalid web app display mode, got "%v"`, regularTestUser.DisplayMode)
-	}
-
-	if regularTestUser.GestureNav != "tap" {
-		t.Fatalf(`Invalid gesture navigation, got "%v"`, regularTestUser.GestureNav)
-	}
-
-	if regularTestUser.DefaultReadingSpeed != 265 {
-		t.Fatalf(`Invalid default reading speed, got "%v"`, regularTestUser.DefaultReadingSpeed)
-	}
-
-	if regularTestUser.CJKReadingSpeed != 500 {
-		t.Fatalf(`Invalid cjk reading speed, got "%v"`, regularTestUser.CJKReadingSpeed)
-	}
+	checkDefaultUserSettings(t, regularTestUser)
 }
 }
 
 
 func TestCreateUserEndpointAsRegularUser(t *testing.T) {
 func TestCreateUserEndpointAsRegularUser(t *testing.T) {
@@ -217,61 +188,11 @@ func TestGetUserByIDEndpointAsAdmin(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	if userByID.ID != user.ID {
-		t.Errorf(`Invalid userID, got "%v" instead of "%v"`, userByID.ID, user.ID)
-	}
-
-	if userByID.Username != user.Username {
-		t.Errorf(`Invalid username, got "%v" instead of "%v"`, userByID.Username, user.Username)
-	}
-
 	if userByID.Password != "" {
 	if userByID.Password != "" {
 		t.Errorf(`The password field must be empty, got "%v"`, userByID.Password)
 		t.Errorf(`The password field must be empty, got "%v"`, userByID.Password)
 	}
 	}
 
 
-	if userByID.Language != user.Language {
-		t.Errorf(`Invalid language, got "%v"`, userByID.Language)
-	}
-
-	if userByID.Theme != user.Theme {
-		t.Errorf(`Invalid theme, got "%v"`, userByID.Theme)
-	}
-
-	if userByID.Timezone != user.Timezone {
-		t.Errorf(`Invalid timezone, got "%v"`, userByID.Timezone)
-	}
-
-	if userByID.IsAdmin != user.IsAdmin {
-		t.Errorf(`Invalid role, got "%v"`, userByID.IsAdmin)
-	}
-
-	if userByID.EntriesPerPage != user.EntriesPerPage {
-		t.Errorf(`Invalid entries per page, got "%v"`, userByID.EntriesPerPage)
-	}
-
-	if userByID.DisplayMode != user.DisplayMode {
-		t.Errorf(`Invalid web app display mode, got "%v"`, userByID.DisplayMode)
-	}
-
-	if userByID.GestureNav != user.GestureNav {
-		t.Errorf(`Invalid gesture navigation, got "%v"`, userByID.GestureNav)
-	}
-
-	if userByID.DefaultReadingSpeed != user.DefaultReadingSpeed {
-		t.Errorf(`Invalid default reading speed, got "%v"`, userByID.DefaultReadingSpeed)
-	}
-
-	if userByID.CJKReadingSpeed != user.CJKReadingSpeed {
-		t.Errorf(`Invalid cjk reading speed, got "%v"`, userByID.CJKReadingSpeed)
-	}
-
-	if userByID.EntryDirection != user.EntryDirection {
-		t.Errorf(`Invalid entry direction, got "%v"`, userByID.EntryDirection)
-	}
-
-	if userByID.EntryOrder != user.EntryOrder {
-		t.Errorf(`Invalid entry order, got "%v"`, userByID.EntryOrder)
-	}
+	checkSameUser(t, userByID, user)
 }
 }
 
 
 func TestGetUserByIDEndpointAsRegularUser(t *testing.T) {
 func TestGetUserByIDEndpointAsRegularUser(t *testing.T) {
@@ -298,57 +219,11 @@ func TestGetUserByUsernameEndpointAsAdmin(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	if userByUsername.ID != user.ID {
-		t.Errorf(`Invalid userID, got "%v" instead of "%v"`, userByUsername.ID, user.ID)
-	}
-
-	if userByUsername.Username != user.Username {
-		t.Errorf(`Invalid username, got "%v" instead of "%v"`, userByUsername.Username, user.Username)
-	}
-
 	if userByUsername.Password != "" {
 	if userByUsername.Password != "" {
 		t.Errorf(`The password field must be empty, got "%v"`, userByUsername.Password)
 		t.Errorf(`The password field must be empty, got "%v"`, userByUsername.Password)
 	}
 	}
 
 
-	if userByUsername.Language != user.Language {
-		t.Errorf(`Invalid language, got "%v"`, userByUsername.Language)
-	}
-
-	if userByUsername.Theme != user.Theme {
-		t.Errorf(`Invalid theme, got "%v"`, userByUsername.Theme)
-	}
-
-	if userByUsername.Timezone != user.Timezone {
-		t.Errorf(`Invalid timezone, got "%v"`, userByUsername.Timezone)
-	}
-
-	if userByUsername.IsAdmin != user.IsAdmin {
-		t.Errorf(`Invalid role, got "%v"`, userByUsername.IsAdmin)
-	}
-
-	if userByUsername.EntriesPerPage != user.EntriesPerPage {
-		t.Errorf(`Invalid entries per page, got "%v"`, userByUsername.EntriesPerPage)
-	}
-
-	if userByUsername.DisplayMode != user.DisplayMode {
-		t.Errorf(`Invalid web app display mode, got "%v"`, userByUsername.DisplayMode)
-	}
-
-	if userByUsername.GestureNav != user.GestureNav {
-		t.Errorf(`Invalid gesture navigation, got "%v"`, userByUsername.GestureNav)
-	}
-
-	if userByUsername.DefaultReadingSpeed != user.DefaultReadingSpeed {
-		t.Errorf(`Invalid default reading speed, got "%v"`, userByUsername.DefaultReadingSpeed)
-	}
-
-	if userByUsername.CJKReadingSpeed != user.CJKReadingSpeed {
-		t.Errorf(`Invalid cjk reading speed, got "%v"`, userByUsername.CJKReadingSpeed)
-	}
-
-	if userByUsername.EntryDirection != user.EntryDirection {
-		t.Errorf(`Invalid entry direction, got "%v"`, userByUsername.EntryDirection)
-	}
+	checkSameUser(t, userByUsername, user)
 }
 }
 
 
 func TestGetUserByUsernameEndpointAsRegularUser(t *testing.T) {
 func TestGetUserByUsernameEndpointAsRegularUser(t *testing.T) {
@@ -507,9 +382,7 @@ func TestMarkUserAsReadEndpoint(t *testing.T) {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 
 
-	results := listFeedEntries(t, regularUserClient, feedID, nil)
-
-	for _, entry := range results.Entries {
+	for _, entry := range servertest.FeedEntries(t, regularUserClient, feedID) {
 		if entry.Status != miniflux.EntryStatusRead {
 		if entry.Status != miniflux.EntryStatusRead {
 			t.Errorf(`Status for entry %d was %q instead of %q`, entry.ID, entry.Status, miniflux.EntryStatusRead)
 			t.Errorf(`Status for entry %d was %q instead of %q`, entry.ID, entry.Status, miniflux.EntryStatusRead)
 		}
 		}