master-zapier-plan-draft/packages/zappier-account-balance/test/health.test.js
George Lambert 9cc0018708
Some checks are pending
offline / test (push) Waiting to run
Add customer names on the ledger, staff session login, and exclusive jobs.events.
Account-balance stores display names and looks up by name. Edge writes
names on customer create/edit; staff UIs join from edge when needed.
New verae-staff-session issues a host cookie; department HTML redirects
when STAFF_AUTH=1. JOBS_EVENTS_EXCLUSIVE lets jobs-events own the durable
consumer. Catalog index is cards; disabled fleet machines are grey.
2026-09-11 18:11:21 -04:00

34 lines
1.3 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { spawn } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
test('account-balance health and statement', async () => {
const port = 18010;
const books = path.join(os.tmpdir(), `books-health-${Date.now()}.json`);
const child = spawn(process.execPath, ['src/server.js'], {
cwd: root,
env: { ...process.env, PORT: String(port), BOOKS_PATH: books },
stdio: ['ignore', 'pipe', 'pipe'],
});
await new Promise((r) => setTimeout(r, 400));
try {
const h = await (await fetch(`http://127.0.0.1:${port}/health`)).json();
assert.equal(h.role, 'zappier-account-balance');
await fetch(`http://127.0.0.1:${port}/adjust`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ customerId: 'c1', cents: 200, reason: 'test' }),
});
const st = await (await fetch(`http://127.0.0.1:${port}/statement/c1`)).json();
assert.equal(st.prepaidCents, 200);
} finally {
child.kill('SIGTERM');
fs.rmSync(books, { force: true });
}
});