fix(notifications): replace Cloud Run job with worker service
This commit is contained in:
47
backend/command-api/test/notification-worker.test.js
Normal file
47
backend/command-api/test/notification-worker.test.js
Normal file
@@ -0,0 +1,47 @@
|
||||
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/);
|
||||
});
|
||||
Reference in New Issue
Block a user