- Backend: the church profile from Accounts (src/accounts/church.ts, kept 10 minutes, last copy kept while Accounts is down), public GET /api/v2/church, and church.changed accepted at POST /api/church/v1/changed (signed with the Accounts link; it answered 404 before). - Frontend: brandAttributes on <html>, @crosscode/ui/fonts.css, body and h1-h3 use the church's pairing, --radius follows its corners; the dashboard and setup screens (data-cc-staff) keep their fonts and 0.5rem. - The shared ChurchFooter on public pages when Accounts is connected (terms and cookie settings below it); header links to the church's other sites. - @crosscode/ui 0.3.0: ChurchFooter takes `bottom`. - Tests: tests/churchProfile.test.ts (8); e2e/church-brand.spec.ts and a /test/profile hook on the e2e Accounts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
3.4 KiB
TypeScript
64 lines
3.4 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; POST /test/profile changes
|
|
* the church profile (3.7.0, church-brand.spec.ts), as an admin's save in Accounts would.
|
|
*/
|
|
import http from 'node:http';
|
|
import { ed25519PublicToPem, generateEd25519 } from '@crosscode/contracts/signing';
|
|
import { createApp } from '../../../accounts/backend/src/app.ts';
|
|
import { updateProfile } from '../../../accounts/backend/src/church/profile.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/profile') {
|
|
let body = '';
|
|
req.on('data', (c) => { body += c; });
|
|
req.on('end', async () => {
|
|
try {
|
|
const church = await updateProfile(ctx, JSON.parse(body));
|
|
res.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(church));
|
|
} catch (e) {
|
|
res.writeHead(400, { 'content-type': 'application/json' }).end(JSON.stringify({ message: (e as Error).message }));
|
|
}
|
|
});
|
|
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'));
|