Files
crosscode-platform/apps/events/e2e/support/accounts-server.mts
T
joshuaandClaude Opus 5.5 5819ea87fb e2e: sign-in spec enters the emailed code; linked-products waits for the click and the 60 s cache
The Events e2e suite on Postgres: 111/111 (volunteers 'asks for cover' is
flaky: it passed alone and in the run before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 15:19:26 +02:00

49 lines
2.7 KiB
TypeScript

/**
* The church's Accounts for Cross Events' end-to-end tests (3.0.0, playwright.config.ts): the real
* Accounts backend on 127.0.0.1:5221 with its in-memory database (no Postgres of its own), behind
* its pages on 127.0.0.1:3221 (`next dev` in apps/accounts/frontend). Its own address (127.0.0.1)
* differs from the Events site's (localhost), so their cookies stay apart as on two domains.
*
* Test helpers: POST /test/link { installId, url, secret } links Events, as Connect would;
* GET /test/code?to=<email> answers the last code emailed to that address.
*/
import http from 'node:http';
import { ed25519PublicToPem, generateEd25519 } from '@crosscode/contracts/signing';
import { createApp } from '../../../accounts/backend/src/app.ts';
import { createCtx } from '../../../accounts/backend/src/context.ts';
import { loadConfig } from '../../../accounts/backend/src/lib/config.ts';
import { MemoryMessenger } from '../../../accounts/backend/src/lib/messages.ts';
import { createProvider } from '../../../accounts/backend/src/oidc/provider.ts';
import { memoryDb } from '../../../accounts/backend/tests/support/memoryDb.ts';
const WEB = 'http://127.0.0.1:3221';
const db = memoryDb();
const messenger = new MemoryMessenger();
const ctx = createCtx(loadConfig({ ACCOUNTS_URL: WEB, NODE_ENV: 'test', JOBS_ENABLED: 'false', LINKS_ALLOW_PRIVATE: 'true', HUB_URL: 'http://127.0.0.1:1', TRUST_PROXY: 'true' }), db as never, { messenger });
await ctx.settings.setMany({
hub_install_id: '7e2d1c0b-9a8f-4e6d-8c5b-4a3f2e1d0c9b',
church_profile: JSON.stringify({ name: 'E2E Church', shortName: 'E2E' }),
});
const provider = await createProvider(ctx);
const app = createApp(ctx, provider);
http.createServer((req, res) => {
if (req.method === 'GET' && req.url?.startsWith('/test/code?')) {
const to = new URL(req.url, WEB).searchParams.get('to') ?? '';
res.writeHead(200, { 'content-type': 'text/plain' }).end(messenger.lastCode(to) ?? '');
return;
}
if (req.method === 'POST' && req.url === '/test/link') {
let body = '';
req.on('data', (c) => { body += c; });
req.on('end', async () => {
const { installId, url, secret } = JSON.parse(body) as { installId: string; url: string; secret: string };
const data = { product: 'events', url, publicKey: ed25519PublicToPem(generateEd25519().publicKey), secret: ctx.secrets.encrypt(secret), connectedAt: new Date() };
await db.productLink.upsert({ where: { installId }, create: { installId, ...data }, update: data });
res.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify({ ok: true }));
});
return;
}
app(req, res);
}).listen(5221, '127.0.0.1', () => console.log('[e2e] Accounts on 5221'));