From 37f84dd3ea6289d44a55485a45d1ebd662e47186 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sat, 25 Apr 2026 21:34:58 -0400 Subject: [PATCH] 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. --- cmd/server/tests/search_unified_test.go | 10 +++++----- cmd/server/tests/websocket_test.go | 13 ++++--------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/cmd/server/tests/search_unified_test.go b/cmd/server/tests/search_unified_test.go index 61593d5..0bfafc1 100644 --- a/cmd/server/tests/search_unified_test.go +++ b/cmd/server/tests/search_unified_test.go @@ -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") }) } diff --git a/cmd/server/tests/websocket_test.go b/cmd/server/tests/websocket_test.go index 1281e03..8094f84 100644 --- a/cmd/server/tests/websocket_test.go +++ b/cmd/server/tests/websocket_test.go @@ -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)