fix(tests): repair TestUnifiedSearch and TestWebSocketProgressBroadcast

TestUnifiedSearch: Search for 'zzzznonexistent' instead of 'test' which
matches leftover test data from other tests. Fixes false 200 instead of 404.

TestWebSocketProgressBroadcast: Update to new progress endpoint
/api/media-items/:id/progress with correct PUT body format matching
ProgressService (percentage, epubcfi). Use book_id instead of
media_item_id to match WebSocket broadcast payload field names.
This commit is contained in:
2026-04-25 21:34:58 -04:00
parent 630283ab3f
commit 7f66a62d45
2 changed files with 9 additions and 14 deletions
+5 -5
View File
@@ -93,14 +93,14 @@ func TestUnifiedSearch(t *testing.T) {
assert.Equal(t, http.StatusOK, rec.Code, "Should filter by has_cover")
})
t.Run("Missing library_id", func(t *testing.T) {
req := httptest.NewRequest("GET", "/api/media-items/search?q=test", nil)
t.Run("Missing library_id searches all libraries", func(t *testing.T) {
req := httptest.NewRequest("GET", "/api/media-items/search?q=zzzznonexistent", nil)
req.Header.Set("Authorization", "Bearer "+setup.UserToken)
rec := httptest.NewRecorder()
setup.Server.Config.Handler.ServeHTTP(rec, req)
// library_id is now optional - searches all libraries when omitted
// Returns 404 when no results match the search query
assert.Equal(t, http.StatusNotFound, rec.Code, "Should return 404 when no results found")
// library_id is optional - searches all libraries when omitted
// Returns 404 when no results match
assert.Equal(t, http.StatusNotFound, rec.Code, "Should return 404 when no results match")
})
}
+4 -9
View File
@@ -119,19 +119,14 @@ func TestWebSocketProgressBroadcast(t *testing.T) {
ws.SetReadDeadline(time.Now().Add(5 * time.Second))
_, _, _ = ws.ReadMessage()
// Update progress via HTTP API
// Update progress via HTTP API to new media-item progress endpoint
progressReq := map[string]interface{}{
"source": "test",
"location": map[string]interface{}{
"percentage": 0.5,
},
"device_metadata": map[string]interface{}{
"device_type": "web",
},
"percentage": 0.5,
"epubcfi": "epubcfi(/6/4/2:10)",
}
body, _ := json.Marshal(progressReq)
req, _ := http.NewRequest("POST", setup.Server.URL+"/api/progress/"+mediaID, strings.NewReader(string(body)))
req, _ := http.NewRequest("PUT", setup.Server.URL+"/api/media-items/"+mediaID+"/progress", bytes.NewBuffer(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+token)