fix(tests): handle 404 response for nonexistent library in search filter test

TestCollectionSearchLibraryFilter's 'invalid library_id' case was
expecting a 200 with empty results, but the search handler correctly
returns 404 when no results are found. The test also consumed the
response body for debug logging then tried to JSON-decode the same
body (causing EOF). Add expectedStatus field to the test struct and
return early when a specific non-200 status is expected.
This commit is contained in:
2026-04-22 15:44:01 -04:00
parent 2fdf894216
commit c7f0eb406a
+8 -8
View File
@@ -388,6 +388,7 @@ func TestCollectionSearchLibraryFilter(t *testing.T) {
query string
libraryID string
expectedCount int
expectedStatus int
shouldContain string // Comma-separated list of book IDs to check
}{
{
@@ -412,10 +413,10 @@ func TestCollectionSearchLibraryFilter(t *testing.T) {
shouldContain: book2ID,
},
{
name: "invalid library_id",
query: "Harry",
libraryID: "00000000-0000-0000-0000-000000000000",
expectedCount: 0,
name: "invalid library_id",
query: "Harry",
libraryID: "00000000-0000-0000-0000-000000000000",
expectedStatus: http.StatusNotFound,
},
}
@@ -435,10 +436,9 @@ func TestCollectionSearchLibraryFilter(t *testing.T) {
_ = Body.Close()
}(resp.Body)
// Log response for debugging
if resp.StatusCode != http.StatusOK {
bodyBytes, _ := io.ReadAll(resp.Body)
t.Logf("ERROR %d: %s", resp.StatusCode, string(bodyBytes))
if tt.expectedStatus != 0 {
require.Equal(t, tt.expectedStatus, resp.StatusCode)
return
}
var result []map[string]interface{}