mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-22 12:06:42 +02:00
Add bun:test integration suite that exercises every public and host endpoint plus the rate-bucket sweeper against a real Postgres. The Hono app factory was extracted from index.ts into app.ts so tests can build their own instance with a header-based auth mock instead of spinning up mana-auth + JWKS. Coverage: - health route smoke - public RSVP: snapshot fetch (incl. 404, cancelled, summary privacy), submit, validation (name, status, email, plus-ones, cancelled), upsert dedup (incl. null/missing email parity), summary aggregation across yes/no/maybe + plus-ones, rate-limit cap (5/h), absolute per-token cap (20) - host events: publish (auth, idempotent token reuse, ownership), snapshot update (partial, ownership, 404), delete (cascade FK to rsvps + buckets, ownership, idempotent), get rsvps (ownership) - sweeper: removes >2h-old buckets, keeps fresh ones, no-op on empty Mock auth lives in a small helper that injects an X-Test-User header into a fake middleware, so the same createApp() factory powers both production (real jwtAuth) and tests (header mock).
30 lines
975 B
TypeScript
30 lines
975 B
TypeScript
/**
|
|
* mana-events — Public RSVP & event sharing service.
|
|
*
|
|
* Hono + Bun runtime. Stores published event snapshots and the public
|
|
* RSVP responses they collect. Hosts authenticate via mana-auth JWT;
|
|
* RSVP endpoints are intentionally unauthenticated so anyone with a
|
|
* share link can respond.
|
|
*
|
|
* The Hono app itself lives in app.ts so unit tests can import it
|
|
* without triggering the production bootstrap (sweeper, log, port).
|
|
*/
|
|
|
|
import { createApp } from './app';
|
|
import { loadConfig } from './config';
|
|
import { getDb } from './db/connection';
|
|
import { startRateBucketSweeper } from './lib/cleanup';
|
|
|
|
const config = loadConfig();
|
|
const db = getDb(config.databaseUrl);
|
|
|
|
// Background cleanup of stale rate-limit buckets so they don't
|
|
// accumulate for the lifetime of long-published events.
|
|
startRateBucketSweeper(db);
|
|
|
|
console.log(`mana-events starting on port ${config.port}...`);
|
|
|
|
export default {
|
|
port: config.port,
|
|
fetch: createApp(db, config).fetch,
|
|
};
|