master-zapier-plan-draft/packages/zappier-sales-pricing/test/health.test.js
George Lambert ac38676645
Some checks are pending
offline / test (push) Waiting to run
Add NATS account-balance SoT and statement review for customers, CS, and sales
Internal billing now uses verae.billing.* request-reply and pubs. zappier-account-balance tracks prepaid, credits, usage, and payments. Portal, admin, CS, and sales all review the same statement. Independent Forgejo repos stay split via push-module-repos.
2026-09-11 15:35:37 -04:00

58 lines
1.9 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { spawn } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
test('sales-pricing health', async () => {
const port = 18012;
const child = spawn(process.execPath, ['src/server.js'], {
cwd: root,
env: { ...process.env, PORT: String(port) },
stdio: ['ignore', 'pipe', 'pipe'],
});
await new Promise((r) => setTimeout(r, 400));
try {
const r = await fetch(`http://127.0.0.1:${port}/health`);
assert.equal((await r.json()).role, 'zappier-sales-pricing');
const home = await fetch(`http://127.0.0.1:${port}/`);
assert.equal(home.status, 200);
} finally {
child.kill('SIGTERM');
}
});
test('sales review via account-balance HTTP', async () => {
const booksPort = 18016;
const salesPort = 18017;
const books = spawn(process.execPath, ['src/server.js'], {
cwd: path.join(root, '..', 'zappier-account-balance'),
env: { ...process.env, PORT: String(booksPort) },
stdio: ['ignore', 'pipe', 'pipe'],
});
const sales = spawn(process.execPath, ['src/server.js'], {
cwd: root,
env: {
...process.env,
PORT: String(salesPort),
ACCOUNT_BALANCE_URL: `http://127.0.0.1:${booksPort}`,
},
stdio: ['ignore', 'pipe', 'pipe'],
});
await new Promise((r) => setTimeout(r, 500));
try {
await fetch(`http://127.0.0.1:${booksPort}/adjust`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ customerId: 'c-sales', cents: 300, reason: 'promo', agent: 'sales' }),
});
const st = await (await fetch(`http://127.0.0.1:${salesPort}/review/c-sales`)).json();
assert.equal(st.prepaidCents, 300);
assert.equal(st.source, 'account-balance');
} finally {
sales.kill('SIGTERM');
books.kill('SIGTERM');
}
});