master-zapier-plan-draft/packages/verae-access-web/test/health.test.js
George Lambert 2bb3884a1b
Some checks are pending
offline / test (push) Waiting to run
Close remaining IAM JSON doors and re-walk the lab.
CS/sales/accounting/staff list endpoints and sales pricing writes
require IAM; fleet service env sets STAFF_AUTH=1. Department tests
use a private books file so lab NATS does not leak into them.
2026-09-11 19:08:20 -04:00

60 lines
2.2 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)), '..');
const authzRoot = path.join(root, '..', 'verae-access-authz');
const booksRoot = path.join(root, '..', 'zappier-account-balance');
test('web plane can read statement after authz, cannot skip authz', async () => {
const authzPort = 18021;
const booksPort = 18022;
const webPort = 18023;
const booksFile = path.join(os.tmpdir(), `web-books-${process.pid}.json`);
const authz = spawn(process.execPath, ['src/server.js'], {
cwd: authzRoot,
env: { ...process.env, PORT: String(authzPort), NATS_URL: '' },
stdio: ['ignore', 'pipe', 'pipe'],
});
const books = spawn(process.execPath, ['src/server.js'], {
cwd: booksRoot,
env: { ...process.env, PORT: String(booksPort), BOOKS_PATH: booksFile, NATS_URL: '' },
stdio: ['ignore', 'pipe', 'pipe'],
});
const web = spawn(process.execPath, ['src/server.js'], {
cwd: root,
env: {
...process.env,
PORT: String(webPort),
AUTHZ_URL: `http://127.0.0.1:${authzPort}`,
ACCOUNT_BALANCE_URL: `http://127.0.0.1:${booksPort}`,
NATS_URL: '',
},
stdio: ['ignore', 'pipe', 'pipe'],
});
await new Promise((r) => setTimeout(r, 600));
try {
await fetch(`http://127.0.0.1:${booksPort}/adjust`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ customerId: 'c-web', cents: 400, kind: 'reload' }),
});
const h = await (await fetch(`http://127.0.0.1:${webPort}/health`)).json();
assert.equal(h.plane, 'web');
const portal = await fetch(`http://127.0.0.1:${webPort}/portal/`);
assert.equal(portal.status, 200);
assert.match(await portal.text(), /Zappier Portal|portal/i);
const st = await (await fetch(`http://127.0.0.1:${webPort}/statement/c-web`)).json();
assert.equal(st.prepaidCents, 400);
assert.equal(st.plane, 'web');
} finally {
web.kill('SIGTERM');
books.kill('SIGTERM');
authz.kill('SIGTERM');
fs.rmSync(booksFile, { force: true });
}
});