Files
crosscode-platform/apps/accounts/backend/tests/demoScenario.test.ts
T
joshuaandClaude Opus 5.5 ad488c3280 Accounts 1.9.0, @crosscode/demo 1.0.0: messaging.get, WhatsApp opt-out, demo scenarios
Accounts 1.9.0 (one migration):
- messaging.get (sealed settings) and the messaging.changed hint to products
  that asked, on admin or product changes
- the WhatsApp opt-out for every product: whatsapp.optout, Accounts' own WAWP
  webhook, WhatsAppOptOut kept per number, whatsapp_opted_out in user.updated,
  no WhatsApp from Accounts to an opted-out person, "Turn WhatsApp back on"
- demo scenarios: npm run demo -- --profile <scenario> --force replaces the
  church profile (with an SVG logo and icon at /api/demo-assets/) and the demo
  people, ids kept across loads

@crosscode/demo 1.0.0 (new): the eight scenarios' churches, people and logos.

crosscode script: crosscode demo <church> accounts, --scenario on every demo,
Accounts installs and builds packages/demo.

Checked on PostgreSQL 18: migrations, scenario loads, opt-out, npm run demo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 11:05:22 +02:00

93 lines
5.1 KiB
TypeScript

// Accounts 1.9.0: a demo scenario's church and people (docs/APP-1.0-PLAN.md §12, "Demo scenarios").
import assert from 'node:assert/strict';
import { after, before, describe, test } from 'node:test';
import { CHURCH_PATHS, churchSchema } from '@crosscode/contracts';
import { demoPeople } from '@crosscode/demo';
import { startHarness, type Harness } from './support/harness.js';
import { loadScenario } from '../src/demo/scenario.js';
import { church } from '../src/church/profile.js';
import { verifyPassword } from '../src/lib/passwords.js';
let h: Harness;
before(async () => { h = await startHarness(); });
after(async () => { await h.close(); });
const live = async () => h.db.account.findMany({ where: { status: { not: 'deleted' } } });
describe('loading a demo scenario', () => {
test('the church becomes the scenario\'s, with its own logo and icon, and the products are told', async () => {
const real = await h.makeAccount({ email: 'office@hope.test' });
const admin = await h.makeAccount({ email: 'admin.demo@example.com', role: 'admin' });
const r = await loadScenario(h.ctx, 'community-family');
assert.equal(r.church, 'Acacia Hill Church');
const c = await church(h.ctx);
assert.ok(churchSchema.safeParse(c).success);
assert.equal(c.name, 'Acacia Hill Church');
assert.equal(c.shortName, 'Acacia Hill');
assert.equal(c.branding.colours.primary, '#2f6f4f');
assert.deepEqual(c.branding.style, { fontPairing: 'warm', corners: 'soft' });
assert.equal(c.branding.logoUrl, `${h.publicUrl}/api/demo-assets/community-family/logo.svg`);
assert.equal(c.contact.email, 'office.acaciahill@example.com');
assert.ok((await h.db.delivery.findMany({ where: { type: 'church.changed' } })).length >= 1);
// Real people and admins are never touched.
assert.equal((await h.db.account.findUnique({ where: { id: real.id } }))!.status, 'active');
assert.equal((await h.db.account.findUnique({ where: { id: admin.id } }))!.status, 'active');
});
test('every person has an account with the id the other products work out, and the demo password', async () => {
const people = demoPeople('community-family');
const ids = new Set((await live()).map((a) => a.id));
for (const p of people) assert.ok(ids.has(p.id), p.email);
const pastor = (await h.db.account.findUnique({ where: { id: people[0]!.id } }))!;
assert.equal(pastor.name, 'Thabo Nkosi');
assert.equal(pastor.emailVerified, true);
assert.ok(await verifyPassword('Demo@1234', pastor.passwordHash as string));
});
test('loading it again changes nobody\'s id', async () => {
const r = await loadScenario(h.ctx, 'community-family');
assert.equal(r.created, 0);
assert.equal(r.removed, 0);
assert.equal(r.updated, demoPeople('community-family').length);
});
test('another scenario replaces the demo people; switching back brings them back with the same ids', async () => {
const before = demoPeople('community-family');
const r = await loadScenario(h.ctx, 'bold-plant');
assert.equal(r.church, 'Harbour City Church');
assert.equal(r.removed, before.length);
assert.equal(r.created, demoPeople('bold-plant').length);
assert.equal((await h.db.account.findUnique({ where: { id: before[0]!.id } }))!.status, 'deleted');
assert.ok(await h.db.account.findUnique({ where: { email: 'office@hope.test' } }), 'a real person stays');
assert.equal((await h.db.account.findUnique({ where: { email: 'admin.demo@example.com' } }))!.status, 'active', 'an admin stays');
const back = await loadScenario(h.ctx, 'community-family');
assert.equal(back.updated, before.length);
const pastor = (await h.db.account.findUnique({ where: { id: before[0]!.id } }))!;
assert.equal(pastor.status, 'active');
assert.equal(pastor.email, before[0]!.email);
});
test('a scenario with campuses has them in the profile', async () => {
await h.ctx.settings.set('church_profile', JSON.stringify({ name: 'Hope Family Church' }));
// Riverside has about 2 450 people; only its profile is checked here.
const c = await (async () => { await loadScenario(h.ctx, 'clean-campus'); return church(h.ctx); })();
assert.deepEqual(c.campuses.map((x) => x.slug), ['stellenbosch', 'paarl', 'somerset-west']);
assert.equal(c.serviceTimes.filter((s) => s.campus === 'stellenbosch').length, 2);
});
});
describe('demo logos', () => {
test('served as SVG for a scenario, 404 for anything else', async () => {
const res = await fetch(`${h.publicUrl}/api/demo-assets/bold-youth/icon.svg`);
assert.equal(res.status, 200);
assert.equal(res.headers.get('content-type'), 'image/svg+xml; charset=utf-8');
assert.match(await res.text(), /^<svg[^>]*>.*#e4572e/);
const logo = await (await fetch(`${h.publicUrl}/api/demo-assets/heritage-parish/logo.svg`)).text();
assert.match(logo, /St Columba&apos;s Church/);
assert.equal((await fetch(`${h.publicUrl}/api/demo-assets/nowhere/icon.svg`)).status, 404);
assert.equal((await fetch(`${h.publicUrl}/api/demo-assets/bold-youth/secrets.txt`)).status, 404);
assert.equal((await fetch(`${h.publicUrl}${CHURCH_PATHS.profile}`)).status, 200);
});
});