caelum0x 315020a760 feat: Wave E — api platform surface (51 services, 288 routes, 19 indexers, 481 tests)
- routes across all domains: trade finance, compliance, dpp, logistics, commodities,
  energy, workforce, data + cross-cutting (auth/webhooks/exports/reports/admin/analytics)
- service layer per domain aggregating chain reads + infra repositories into typed DTOs
- indexer handlers mapping every contract group's events to repository upserts
- api + workspace typecheck green

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-01 00:19:24 +03:00

56 lines
1.9 KiB
TypeScript

/**
* /reports route tests — platform summary + per-domain report + validation.
*/
import { describe, expect, it } from 'vitest';
import reportsPlugin from '../../src/routes/reports.js';
import { buildApp, makeDb, type Row } from '../routers-kit.js';
const seeded: Record<string, readonly Row[]> = {
suppliers: [{ id: 's1' }, { id: 's2' }],
deals: [
{ id: 'd1', state: 'funded' },
{ id: 'd2', state: 'released' },
],
financing_listings: [{ id: 'l1' }],
indexer_events: [
{ id: 'e1', group_name: 'finance' },
{ id: 'e2', group_name: 'settlement' },
],
};
describe('reports router', () => {
it('lists report domains', async () => {
const app = await buildApp(reportsPlugin, { db: makeDb() });
const res = await app.inject({ method: 'GET', url: '/reports' });
expect(res.json().data.domains).toContain('finance');
await app.close();
});
it('returns a platform summary', async () => {
const app = await buildApp(reportsPlugin, { db: makeDb(seeded) });
const res = await app.inject({ method: 'GET', url: '/reports/summary' });
expect(res.statusCode).toBe(200);
const data = res.json().data;
expect(data.totals.suppliers).toBe(2);
expect(data.totals.deals).toBe(2);
expect(data.finance.listings).toBe(1);
await app.close();
});
it('returns a per-domain report', async () => {
const app = await buildApp(reportsPlugin, { db: makeDb(seeded) });
const res = await app.inject({ method: 'GET', url: '/reports/settlement' });
expect(res.statusCode).toBe(200);
expect(res.json().data.domain).toBe('settlement');
expect(res.json().data.metrics.released).toBe(1);
await app.close();
});
it('400s an unknown domain', async () => {
const app = await buildApp(reportsPlugin, { db: makeDb() });
const res = await app.inject({ method: 'GET', url: '/reports/unknown' });
expect(res.statusCode).toBe(400);
await app.close();
});
});