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:
2026-03-06 01:52:19 -05:00
parent ba2f29983c
commit 4d8e3e5358
8 changed files with 140 additions and 51 deletions
+19 -3
View File
@@ -84,10 +84,26 @@ func TestWorker_DirectoryScanJob(t *testing.T) {
Status: services.JobStatusPending,
}
services.WorkerInstance.Enqueue(job)
// Use EnqueueJob which returns errors
err = services.WorkerInstance.EnqueueJob(job)
require.NoError(t, err, "Failed to enqueue job")
// Poll for job completion
timeout := time.Now().Add(10 * time.Second)
for time.Now().Before(timeout) {
if status, exists := services.WorkerInstance.GetJobStatus(job.ID); exists {
if status.Status == services.JobStatusCompleted || status.Status == services.JobStatusFailed {
break
}
}
time.Sleep(100 * time.Millisecond)
}
// Wait for job to process
time.Sleep(2 * time.Second)
// Debug: Check job status after polling
if finalStatus, exists := services.WorkerInstance.GetJobStatus(job.ID); exists {
t.Logf("Job %s final status: %s, error: %s", job.ID, finalStatus.Status, finalStatus.Error)
} else {
t.Logf("Job %s not found in results", job.ID)
}
// Check that items were created in database
ctx := context.Background()