import test from 'node:test'; import assert from 'node:assert/strict'; import request from 'supertest'; import { createWorkerApp } from '../src/worker-app.js'; test('GET /readyz returns healthy response', async () => { const app = createWorkerApp(); const res = await request(app).get('/readyz'); assert.equal(res.status, 200); assert.equal(res.body.ok, true); assert.equal(res.body.service, 'notification-worker-v2'); }); test('POST /tasks/dispatch-notifications returns dispatch summary', async () => { const app = createWorkerApp({ dispatch: async () => ({ claimed: 2, sent: 2, }), }); const res = await request(app) .post('/tasks/dispatch-notifications') .send({}); assert.equal(res.status, 200); assert.equal(res.body.ok, true); assert.equal(res.body.summary.claimed, 2); assert.equal(res.body.summary.sent, 2); }); test('POST /tasks/dispatch-notifications returns 500 on dispatch error', async () => { const app = createWorkerApp({ dispatch: async () => { throw new Error('dispatch exploded'); }, }); const res = await request(app) .post('/tasks/dispatch-notifications') .send({}); assert.equal(res.status, 500); assert.equal(res.body.ok, false); assert.match(res.body.error, /dispatch exploded/); });