import test from 'node:test';
import assert from 'node:assert/strict';
import { handle } from '../src/app.js';
import { deps, CP_OK, PG_CLEAR } from './helpers.js';
const CP = '/counterpartycheck/v1/preview', PG = '/payguard/v1/preview';
test('HTTP: POST /v1/screen -> receipt; POST /v1/verify; GET routes', async () => {
const { d } = await deps({ [CP]: CP_OK, [PG]: PG_CLEAR });
const r = await handle(new Request('http://x/v1/screen', { method: 'POST', body: JSON.stringify({ payTo: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' }) }), d);
assert.equal(r.status, 200);
const j = await r.json();
const v = await (await handle(new Request('http://x/v1/verify', { method: 'POST', body: JSON.stringify(j.receipt) }), d)).json();
assert.equal(v.valid, true);
assert.equal((await handle(new Request('http://x/v1/screen?payTo=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'), d)).status, 200);
assert.equal((await (await handle(new Request('http://x/v1/ledger/verify'), d)).json()).valid, true);
assert.equal((await (await handle(new Request('http://x/v1/pubkey'), d)).json()).crv, 'Ed25519');
assert.equal((await handle(new Request('http://x/v1/screen', { method: 'POST', body: 'nope' }), d)).status, 400);
assert.equal((await handle(new Request('http://x/zzz'), d)).status, 404);
const pk = JSON.stringify(await (await handle(new Request('http://x/v1/pubkey'), d)).json());
assert.ok(!pk.includes('"d"'));
});
agentgate-source: code mirror on Cloudflare Pages. All repos