This commit is contained in:
@@ -4,6 +4,7 @@ import test from 'node:test';
|
||||
import {
|
||||
createInMemoryImageDerivativeQueue,
|
||||
processNextImageDerivativeJob,
|
||||
processNextPersistentImageDerivativeJob,
|
||||
runImageDerivativeJob,
|
||||
} from '../src/image-derivative-worker.js';
|
||||
|
||||
@@ -66,4 +67,32 @@ test('claims queued jobs and persists their processing lifecycle', async () => {
|
||||
assert.equal(result.status, 'COMPLETED');
|
||||
assert.equal(queue.getJob('job-3').status, 'COMPLETED');
|
||||
assert.equal(queue.getJob('job-3').derivatives[0].key, 'queued.jpg-thumbnail.webp');
|
||||
});
|
||||
|
||||
test('claims and persists a durable image derivative job lifecycle', async () => {
|
||||
const calls = [];
|
||||
const jobRepository = {
|
||||
async claimNext() {
|
||||
return { id: 'job-4', sourceKey: 'durable.jpg', status: 'PROCESSING' };
|
||||
},
|
||||
async complete(id, derivatives) {
|
||||
calls.push({ action: 'complete', id, derivatives });
|
||||
},
|
||||
async fail() {
|
||||
throw new Error('A successful durable job must not fail.');
|
||||
},
|
||||
};
|
||||
|
||||
const result = await processNextPersistentImageDerivativeJob({
|
||||
jobRepository,
|
||||
async loadSource(sourceKey) { return { sourceKey, data: Buffer.from('image') }; },
|
||||
processor: { async process() { return [{ name: 'thumbnail', key: 'durable-thumbnail.webp' }]; } },
|
||||
});
|
||||
|
||||
assert.equal(result.status, 'COMPLETED');
|
||||
assert.deepEqual(calls, [{
|
||||
action: 'complete',
|
||||
id: 'job-4',
|
||||
derivatives: [{ name: 'thumbnail', key: 'durable-thumbnail.webp' }],
|
||||
}]);
|
||||
});
|
||||
Reference in New Issue
Block a user