Add NATS account-balance SoT and statement review for customers, CS, and sales
Some checks are pending
offline / test (push) Waiting to run

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.
This commit is contained in:
George Lambert 2026-09-11 15:35:37 -04:00
parent a1a5b957fd
commit ac38676645
135 changed files with 3078 additions and 130 deletions

View file

@ -0,0 +1,16 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { AccountBooks, handle } from '../src/books.js';
import { SUBJECTS } from '../src/subjects.js';
test('adjust credits prepaid and statement lists credits usage payments', () => {
const books = new AccountBooks();
handle(SUBJECTS.BALANCE_ADJUST, { customerId: 'c1', cents: 500, reason: 'goodwill', agent: 'cs' }, books);
handle(SUBJECTS.USAGE_RECORDED, { customerId: 'c1', endpointId: 'timestamp', cents: 4 }, books);
handle(SUBJECTS.PAYMENT_RECORDED, { customerId: 'c1', cents: 1000, reason: 'reload' }, books);
const st = handle(SUBJECTS.STATEMENT_GET, { customerId: 'c1' }, books);
assert.equal(st.prepaidCents, 1496);
assert.equal(st.credits[0].cents, 500);
assert.equal(st.usage[0].endpointId, 'timestamp');
assert.equal(st.payments[0].kind, 'payment');
});

View file

@ -0,0 +1,30 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { spawn } from 'node:child_process';
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 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 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');
}
});