Initial import of zappier-account-balance from zapier monorepo
This commit is contained in:
commit
e629d65568
10 changed files with 418 additions and 0 deletions
30
test/health.test.js
Normal file
30
test/health.test.js
Normal 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');
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue