import assert from 'node:assert/strict'; import test from 'node:test'; import { processNextInventoryExportJob } from '../src/inventory-export-worker.js'; test('completes a claimed inventory export job', async () => { const calls = []; const result = await processNextInventoryExportJob({ jobRepository: { async claimNext() { return { id: 'job-1', status: 'PROCESSING' }; }, async complete(id, output) { calls.push(['complete', id, output]); }, }, async exportInventory() { return [{ id: 'item-1' }]; }, }); assert.equal(result.status, 'COMPLETED'); assert.deepEqual(calls, [['complete', 'job-1', [{ id: 'item-1' }]]]); }); test('fails an inventory export job when generation errors', async () => { const calls = []; const result = await processNextInventoryExportJob({ jobRepository: { async claimNext() { return { id: 'job-1', status: 'PROCESSING' }; }, async fail(id, error) { calls.push(['fail', id, error]); }, }, async exportInventory() { throw new Error('export unavailable'); }, }); assert.equal(result.status, 'FAILED'); assert.deepEqual(calls, [['fail', 'job-1', 'export unavailable']]); });