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:
@@ -388,6 +388,7 @@ func TestCollectionSearchLibraryFilter(t *testing.T) {
|
|||||||
query string
|
query string
|
||||||
libraryID string
|
libraryID string
|
||||||
expectedCount int
|
expectedCount int
|
||||||
|
expectedStatus int
|
||||||
shouldContain string // Comma-separated list of book IDs to check
|
shouldContain string // Comma-separated list of book IDs to check
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@@ -415,7 +416,7 @@ func TestCollectionSearchLibraryFilter(t *testing.T) {
|
|||||||
name: "invalid library_id",
|
name: "invalid library_id",
|
||||||
query: "Harry",
|
query: "Harry",
|
||||||
libraryID: "00000000-0000-0000-0000-000000000000",
|
libraryID: "00000000-0000-0000-0000-000000000000",
|
||||||
expectedCount: 0,
|
expectedStatus: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,10 +436,9 @@ func TestCollectionSearchLibraryFilter(t *testing.T) {
|
|||||||
_ = Body.Close()
|
_ = Body.Close()
|
||||||
}(resp.Body)
|
}(resp.Body)
|
||||||
|
|
||||||
// Log response for debugging
|
if tt.expectedStatus != 0 {
|
||||||
if resp.StatusCode != http.StatusOK {
|
require.Equal(t, tt.expectedStatus, resp.StatusCode)
|
||||||
bodyBytes, _ := io.ReadAll(resp.Body)
|
return
|
||||||
t.Logf("ERROR %d: %s", resp.StatusCode, string(bodyBytes))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var result []map[string]interface{}
|
var result []map[string]interface{}
|
||||||
|
|||||||
Reference in New Issue
Block a user