test: improve test infrastructure and fix integration tests
- Add folder to library before scanning in fsnotify integration test - Update API endpoint paths from /items to /media-items - Refactor test server setup to support WebSocket hijacking - Add JobsHandler to test server configuration - Implement proper job status polling instead of fixed delays - Consolidate addFolderToLibrary helper into test_helpers.go - Remove duplicate helper function from media_item_isbn_test.go - Add error logging for search test failures - Improve test robustness with better nil handling and type assertions - Update worker test to use EnqueueJob and poll for completion - Add global worker instance reset in test cleanup - Fix media_scanner_test to initialize folders before testing
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@@ -373,6 +374,10 @@ func TestCollectionSearchLibraryFilter(t *testing.T) {
|
||||
lib1Resp := createLibrary(t, client, setup, "Library 1 - Search Test")
|
||||
lib2Resp := createLibrary(t, client, setup, "Library 2 - Search Test")
|
||||
|
||||
// Add folders to libraries (required before adding media items)
|
||||
addFolderToLibrary(t, setup, lib1Resp["id"].(string), "/app/uploads")
|
||||
addFolderToLibrary(t, setup, lib2Resp["id"].(string), "/app/uploads")
|
||||
|
||||
// Add books to each library
|
||||
book1ID := createTestMediaItemIDInLibrary(t, client, setup, lib1Resp["id"].(string), "Harry Potter 1")
|
||||
book2ID := createTestMediaItemIDInLibrary(t, client, setup, lib2Resp["id"].(string), "Harry Potter 2")
|
||||
@@ -427,6 +432,12 @@ func TestCollectionSearchLibraryFilter(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Log response for debugging
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||
t.Logf("ERROR %d: %s", resp.StatusCode, string(bodyBytes))
|
||||
}
|
||||
|
||||
var result []map[string]interface{}
|
||||
json.NewDecoder(resp.Body).Decode(&result)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user