Admin API and screens: dashboard and setup checklist, template and style, pages and blocks, ministries, leadership, media library with the storage limit, publish and history. Pending changes with who and when, discard one, one Publish, restore any version (each version keeps the working copy's rows, never sent to visitors). Preview on the site's own addresses with a bar (widths, back, publish); shared preview links for 7 days or until revoked. Roles checked, same-origin changes only. Publish refreshes the public pages at once (WEBSITE_CONTENT_CACHE_SECONDS). E2E on a production build: the admin's flows and axe on every screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
58 lines
3.0 KiB
TypeScript
58 lines
3.0 KiB
TypeScript
/**
|
|
* The e2e backend (playwright.config.ts): the Website's backend on port 5310 with the in-memory
|
|
* database from the backend tests (no Postgres needed) and the demo church published. The pages
|
|
* run with `next dev` on 3310 and send /api here.
|
|
*
|
|
* Test helpers: POST /test/demo?template=<id> loads the demo church on that template;
|
|
* POST /test/design { variants?, style?, home? } changes the design and publishes again.
|
|
*/
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import express from 'express';
|
|
import { websiteTemplateSchema } from '@crosscode/contracts';
|
|
import { createApp } from '../backend/src/app.js';
|
|
import { createCtx } from '../backend/src/context.js';
|
|
import { loadDemo } from '../backend/src/demo/demoChurch.js';
|
|
import { loadConfig } from '../backend/src/lib/config.js';
|
|
import { hashToken } from '../backend/src/lib/crypto.js';
|
|
import { publish } from '../backend/src/site/snapshot.js';
|
|
import { memoryDb } from '../backend/tests/support/memoryDb.js';
|
|
|
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
const uploads = path.join(here, '.uploads');
|
|
fs.mkdirSync(uploads, { recursive: true });
|
|
|
|
const db = memoryDb();
|
|
const ctx = createCtx(loadConfig({ WEBSITE_URL: 'http://localhost:3310', NODE_ENV: 'test', JOBS_ENABLED: 'false', HUB_URL: 'http://127.0.0.1:1', UPLOAD_DIR: uploads, TRUST_PROXY: 'true' }), db as never);
|
|
await loadDemo(ctx, websiteTemplateSchema.parse(process.env.DEMO_TEMPLATE ?? 'heritage'), { uploadDir: uploads });
|
|
|
|
const app = express();
|
|
app.post('/test/demo', async (req, res) => {
|
|
const t = websiteTemplateSchema.safeParse(req.query.template);
|
|
if (!t.success) return res.status(400).json({ error: 'template' });
|
|
await loadDemo(ctx, t.data, { uploadDir: uploads });
|
|
return res.json({ ok: true, template: t.data });
|
|
});
|
|
app.post('/test/design', express.json(), async (req, res) => {
|
|
const d = (await db.siteDesign.findUnique({ where: { id: 1 } })) as { variants: object; style: object; home: unknown };
|
|
await db.siteDesign.update({ where: { id: 1 }, data: {
|
|
variants: { ...d.variants, ...(req.body.variants ?? {}) },
|
|
style: { ...d.style, ...(req.body.style ?? {}) },
|
|
home: req.body.home ?? d.home,
|
|
} });
|
|
const v = await publish(ctx, { id: 'e2e', role: 'system' });
|
|
res.json({ ok: true, version: v.number });
|
|
});
|
|
// A signed-in admin without Accounts: the role's user and a session; the spec sets the cookie.
|
|
app.post('/test/session', async (req, res) => {
|
|
const role = String(req.query.role ?? 'editor');
|
|
const id = `00000000-0000-4000-8000-${String(Math.floor(Math.random() * 1e12)).padStart(12, '0')}`;
|
|
const token = `e2e-${id}`;
|
|
await db.websiteUser.create({ data: { id, name: `Test ${role}`, email: `${id}@hope.test`, role: role as never } });
|
|
await db.session.create({ data: { tokenHash: hashToken(token), userId: id, expiresAt: new Date(Date.now() + 864e5) } });
|
|
res.json({ cookie: { name: 'ccw_session', value: token } });
|
|
});
|
|
app.use(createApp(ctx));
|
|
app.listen(5310, '127.0.0.1', () => console.log('[e2e] Website backend on 5310 with the demo church.'));
|