fix(tests): update worker tests for API changes and error handling
- Update ListMediaItems calls to include required Limit and Offset parameters - Change Enqueue() to EnqueueJob() to match updated worker API - Add error assertions for job enqueue operations with descriptive messages - Ensure all database queries use proper pagination parameters This ensures tests properly validate error conditions and use the latest worker service API.
This commit is contained in:
@@ -107,7 +107,10 @@ func TestWorker_DirectoryScanJob(t *testing.T) {
|
||||
|
||||
// Check that items were created in database
|
||||
ctx := context.Background()
|
||||
items, err := setup.DB.ListMediaItems(ctx, database.ListMediaItemsParams{})
|
||||
items, err := setup.DB.ListMediaItems(ctx, database.ListMediaItemsParams{
|
||||
Limit: 1000,
|
||||
Offset: 0,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Should have at least 3 items (our test files)
|
||||
@@ -161,7 +164,8 @@ func TestWorker_SetFoldersJob(t *testing.T) {
|
||||
Status: services.JobStatusPending,
|
||||
}
|
||||
|
||||
services.WorkerInstance.Enqueue(job)
|
||||
err = services.WorkerInstance.EnqueueJob(job)
|
||||
require.NoError(t, err, "Failed to enqueue set folders job")
|
||||
|
||||
// Wait for job to process
|
||||
time.Sleep(1 * time.Second)
|
||||
@@ -228,14 +232,18 @@ func TestWorker_ConcurrentJobs(t *testing.T) {
|
||||
},
|
||||
Status: services.JobStatusPending,
|
||||
}
|
||||
services.WorkerInstance.Enqueue(job)
|
||||
err = services.WorkerInstance.EnqueueJob(job)
|
||||
require.NoError(t, err, "Failed to enqueue set folders job")
|
||||
}
|
||||
|
||||
// Wait for all jobs to process
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
// Verify all directories were processed
|
||||
allItems, err := setup.DB.ListMediaItems(ctx, database.ListMediaItemsParams{})
|
||||
allItems, err := setup.DB.ListMediaItems(ctx, database.ListMediaItemsParams{
|
||||
Limit: 1000,
|
||||
Offset: 0,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, allItems, "Should have media items from concurrent jobs")
|
||||
}
|
||||
@@ -278,7 +286,8 @@ func TestWorker_JobStatusTracking(t *testing.T) {
|
||||
Status: services.JobStatusPending,
|
||||
}
|
||||
|
||||
services.WorkerInstance.Enqueue(job)
|
||||
err = services.WorkerInstance.EnqueueJob(job)
|
||||
require.NoError(t, err, "Failed to enqueue set folders job")
|
||||
|
||||
// Poll job status
|
||||
var finalStatus string
|
||||
|
||||
Reference in New Issue
Block a user