feat(jobs): echo worker + CLI bootstrap
Job queue starts only in the CLI gate (not inside createApp), so tests manage their own queue lifecycle. waitForJob() takes a (name, id) pair to match pg-boss v10's getJobById signature. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
22
tests/jobs/workers/echo.test.js
Normal file
22
tests/jobs/workers/echo.test.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { resetDb } from '../../helpers/db.js';
|
||||
import { migrateUp } from '../../../lib/db/migrate.js';
|
||||
import { stopBoss, waitForJob } from '../../helpers/boss.js';
|
||||
import * as queue from '../../../lib/jobs/queue.js';
|
||||
import { registerWorkers } from '../../../lib/jobs/index.js';
|
||||
|
||||
beforeEach(async () => {
|
||||
await resetDb(); await migrateUp();
|
||||
await queue.start();
|
||||
await registerWorkers();
|
||||
});
|
||||
afterEach(async () => { await stopBoss(); });
|
||||
|
||||
describe('echo worker', () => {
|
||||
it('completes with the expected output', async () => {
|
||||
const id = await queue.enqueue('echo', { ping: 7 });
|
||||
const j = await waitForJob('echo', id);
|
||||
expect(j.state).toBe('completed');
|
||||
expect(j.output).toEqual({ pong: 7 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user