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:
@@ -41,27 +41,6 @@ func createTestLibrary(t *testing.T, ts *httptest.Server, token, name string) st
|
||||
return result["id"].(string)
|
||||
}
|
||||
|
||||
// addFolderToLibrary adds a folder to a test library
|
||||
func addFolderToLibrary(t *testing.T, ts *httptest.Server, token, libraryID, folderPath string) {
|
||||
t.Helper()
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"folder_path": folderPath,
|
||||
}
|
||||
|
||||
body, _ := json.Marshal(payload)
|
||||
req, _ := http.NewRequest("POST", ts.URL+"/api/libraries/"+libraryID+"/folders", bytes.NewBuffer(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
require.NoError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
require.Equal(t, http.StatusCreated, resp.StatusCode)
|
||||
}
|
||||
|
||||
// TestMediaItemISBNNormalization tests ISBN normalization with media-items endpoint
|
||||
func TestMediaItemISBNNormalization(t *testing.T) {
|
||||
setup := setupTestServer(t)
|
||||
@@ -71,7 +50,7 @@ func TestMediaItemISBNNormalization(t *testing.T) {
|
||||
libID := createTestLibrary(t, setup.Server, token, "test-isbn-lib")
|
||||
|
||||
// Add a folder to the library (required before adding media items)
|
||||
addFolderToLibrary(t, setup.Server, token, libID, "/app/uploads")
|
||||
addFolderToLibrary(t, setup, libID, "/app/uploads")
|
||||
|
||||
// Test ISBN normalization cases
|
||||
testCases := []struct {
|
||||
@@ -211,7 +190,7 @@ func TestMediaItemISBNEdgeCases(t *testing.T) {
|
||||
|
||||
token := setup.Token
|
||||
libID := createTestLibrary(t, setup.Server, token, "test-isbn-edge-lib")
|
||||
addFolderToLibrary(t, setup.Server, token, libID, "/app/uploads")
|
||||
addFolderToLibrary(t, setup, libID, "/app/uploads")
|
||||
|
||||
t.Run("Empty ISBN should be accepted", func(t *testing.T) {
|
||||
payload := map[string]interface{}{
|
||||
@@ -296,7 +275,7 @@ func TestMediaItemsPagination(t *testing.T) {
|
||||
|
||||
token := setup.Token
|
||||
libID := createTestLibrary(t, setup.Server, token, "test-pagination-lib")
|
||||
addFolderToLibrary(t, setup.Server, token, libID, "/app/uploads")
|
||||
addFolderToLibrary(t, setup, libID, "/app/uploads")
|
||||
|
||||
// Create some test media items
|
||||
for i := 1; i <= 5; i++ {
|
||||
@@ -433,7 +412,7 @@ func TestMediaItemLibraryRequirement(t *testing.T) {
|
||||
|
||||
t.Run("Create media-item with existing library should succeed", func(t *testing.T) {
|
||||
libID := createTestLibrary(t, setup.Server, token, "test-req-lib")
|
||||
addFolderToLibrary(t, setup.Server, token, libID, "/app/uploads")
|
||||
addFolderToLibrary(t, setup, libID, "/app/uploads")
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"title": "Valid Book",
|
||||
@@ -471,7 +450,7 @@ func TestUpdateMediaItemISBN(t *testing.T) {
|
||||
|
||||
token := setup.Token
|
||||
libID := createTestLibrary(t, setup.Server, token, "test-update-lib")
|
||||
addFolderToLibrary(t, setup.Server, token, libID, "/app/uploads")
|
||||
addFolderToLibrary(t, setup, libID, "/app/uploads")
|
||||
|
||||
// First create a media item
|
||||
createPayload := map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user