app: the demo scenarios (APP-1.0-PLAN §12)
npm run demo loads Acacia Hill; --profile/--scenario any of the eight demo churches, around @crosscode/demo's people (the same account ids as Accounts), in the scenario's active-member band: a prayer wall with three months of commitments and the scenario's gaps, a campaign, testimonies, prayer requests, announcements, the church's own devotionals or Cross Code's from the Hub, and events (Cross Events' or the Website's through the feed when linked, else the App's own). The devotionals' passages are copied word for word from the public- domain KJV and BSB by scripts/demo-passages.ts (no Bible text written by hand). The sender never sends anything to a demo person. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import request from 'supertest';
|
||||
import { agent, FREE_BIBLE_TRANSLATION_IDS, parseBibleReference } from '@crosscode/contracts';
|
||||
import { demoChurch, demoParts, demoPeople } from '@crosscode/demo';
|
||||
import { activeMembers } from '../src/members/activity.js';
|
||||
import { fetchMessaging } from '../src/messaging/settings.js';
|
||||
import { queueDevotionals, sendOutbox } from '../src/messaging/send.js';
|
||||
import { sendReminders } from '../src/prayer/jobs.js';
|
||||
import { coverageView } from '../src/prayer/service.js';
|
||||
import { churchProfile } from '../src/church/profile.js';
|
||||
import { DEMO_DEVOTIONALS } from '../src/demo/devotionals.js';
|
||||
import { loadDemo } from '../src/demo/load.js';
|
||||
import { DEMO_PASSAGES } from '../src/demo/passages.js';
|
||||
import { APP_SCENARIOS } from '../src/demo/scenarios.js';
|
||||
import { harness, type Harness } from './support/harness.js';
|
||||
|
||||
const TODAY = '2026-12-01';
|
||||
|
||||
describe('the demo (§12)', () => {
|
||||
it('loads Acacia Hill: the church, its people with their roles and band, a full wall with a few gaps, and no names', async () => {
|
||||
const h = await harness({ linked: false }) as Harness;
|
||||
const r = await loadDemo(h.ctx, 'community-family');
|
||||
const people = demoPeople('community-family');
|
||||
assert.equal(r.church, 'Acacia Hill Church');
|
||||
assert.equal((await churchProfile(h.ctx))?.name, 'Acacia Hill Church');
|
||||
assert.equal(r.members, people.length);
|
||||
assert.equal(await h.db.member.count(), people.length);
|
||||
assert.equal((await activeMembers(h.ctx)).band, agent.demoScenario('community-family').appActiveMembers);
|
||||
|
||||
// The leads have their parts' roles; members have none.
|
||||
const parts = demoParts('community-family');
|
||||
const pastor = people.find((p) => parts.get(p.email)?.includes('pastor'))!;
|
||||
const coordinator = people.find((p) => parts.get(p.email)?.includes('prayer-coordinator'))!;
|
||||
assert.deepEqual((await h.db.member.findUnique({ where: { id: pastor.id } }))!.roles, ['owner', 'pastoral_care']);
|
||||
assert.deepEqual((await h.db.member.findUnique({ where: { id: coordinator.id } }))!.roles, ['prayer_coordinator']);
|
||||
assert.equal(await h.db.member.count({ where: { roles: { has: 'owner' } } }), 1);
|
||||
|
||||
// Nearly every hour covered, with a gap or two in the week ahead; counts only.
|
||||
const days = await Promise.all([0, 1, 2, 3, 4, 5, 6].map((n) => coverageView(h.ctx, `2026-12-0${1 + n}`, null)));
|
||||
const covered = days.reduce((t, d) => t + d.covered, 0);
|
||||
const total = days.reduce((t, d) => t + d.total, 0);
|
||||
assert.ok(covered / total > 0.85 && covered < total, `${covered} of ${total} hours covered`);
|
||||
assert.ok(!JSON.stringify(days).includes(pastor.name.split(' ')[1]!));
|
||||
assert.ok(await h.db.prayedMark.count() > 100);
|
||||
|
||||
// The running campaign, the requests waiting for approval, the announcements and events.
|
||||
const campaign = (await h.ctx.db.prayerCampaign.findMany())[0]!;
|
||||
assert.ok(campaign.startDate <= TODAY && campaign.endDate >= TODAY);
|
||||
assert.equal(await h.db.prayerRequest.count({ where: { moderation: 'pending' } }), 3);
|
||||
assert.equal(await h.db.announcement.count({ where: { pinned: true } }), 1);
|
||||
assert.equal(r.events.from, 'app');
|
||||
assert.equal(await h.db.simpleEvent.count({ where: { publishedAt: { not: null } } }), 3);
|
||||
// Cross Code's devotionals come from the Hub, which this App isn't registered with.
|
||||
assert.equal(r.devotionals.source, 'crosscode');
|
||||
assert.match(r.devotionals.error ?? '', /registered/);
|
||||
|
||||
// Through the API too: Home's public parts answer.
|
||||
assert.equal((await request(h.app).get('/api/v1/announcements')).status, 200);
|
||||
});
|
||||
|
||||
it('loads every scenario, each in its own App band, with its own wall rules and devotionals', async () => {
|
||||
for (const key of agent.DEMO_SCENARIO_KEYS) {
|
||||
const h = await harness({ linked: false }) as Harness;
|
||||
const r = await loadDemo(h.ctx, key);
|
||||
const s = APP_SCENARIOS[key];
|
||||
assert.equal(r.church, demoChurch(key).profile.name, key);
|
||||
assert.equal((await activeMembers(h.ctx)).band, agent.demoScenario(key).appActiveMembers, key);
|
||||
const wall = await h.ctx.settings.json<{ slotMinutes?: number } | null>('prayer_wall', null);
|
||||
assert.equal(wall?.slotMinutes ?? null, s.wall?.slotMinutes ?? null, key);
|
||||
assert.equal(await h.ctx.settings.get('devotionals_source'), s.devotionals, key);
|
||||
const own = await h.db.devotional.findMany({ where: { source: 'church' }, orderBy: { date: 'asc' } });
|
||||
assert.equal(own.length, DEMO_DEVOTIONALS[key]?.days.length ?? 0, key);
|
||||
if (own.length) {
|
||||
assert.equal(own[5]!.date, TODAY, `${key}: today is the sixth`);
|
||||
for (const d of own) assert.ok(FREE_BIBLE_TRANSLATION_IDS.includes(d.translation as never), key);
|
||||
}
|
||||
assert.ok(r.commitments > 10, key);
|
||||
}
|
||||
});
|
||||
|
||||
it('quotes every passage word for word from the generated file (never written by hand)', () => {
|
||||
for (const [key, set] of Object.entries(DEMO_DEVOTIONALS)) {
|
||||
for (const d of set!.days) {
|
||||
assert.ok(parseBibleReference(d.reference).ok, `${key}: ${d.reference}`);
|
||||
assert.ok(DEMO_PASSAGES[`${set!.translation} ${d.reference}`], `${key}: ${d.reference} isn't in passages.ts (run scripts/demo-passages.ts)`);
|
||||
}
|
||||
}
|
||||
assert.equal(Object.keys(DEMO_PASSAGES).length, new Set(Object.values(DEMO_DEVOTIONALS).flatMap((s) => s!.days.map((d) => `${s!.translation} ${d.reference}`))).size);
|
||||
});
|
||||
|
||||
it('replaces the scenario before: its demo members and content go, real members stay', async () => {
|
||||
const h = await harness({ linked: false }) as Harness;
|
||||
await h.db.member.create({ data: { id: 'real-1', name: 'Real Owner', email: 'owner@church.test', roles: ['owner'] } });
|
||||
await loadDemo(h.ctx, 'bold-youth');
|
||||
const before = (await h.db.simpleEvent.findMany()).map((e) => e.id);
|
||||
await loadDemo(h.ctx, 'heritage-parish');
|
||||
const members = await h.ctx.db.member.findMany();
|
||||
assert.equal(members.length, demoPeople('heritage-parish').length + 1);
|
||||
assert.ok(members.every((m) => m.id === 'real-1' || m.email.includes('stcolumbas')));
|
||||
assert.deepEqual(members.find((m) => m.id === 'real-1')!.roles, ['owner']);
|
||||
assert.equal(await h.db.member.count({ where: { roles: { has: 'owner' } } }), 2);
|
||||
// Ignite's events are listed as removed in the feed, so linked products drop their copies.
|
||||
assert.equal(await h.db.feedRemoval.count({ where: { eventId: { in: before } } }), before.length);
|
||||
assert.equal(await h.db.prayerCampaign.count(), 1);
|
||||
assert.equal((await h.db.prayerCampaign.findMany())[0]!.title, 'Forty days of prayer for Lent');
|
||||
});
|
||||
|
||||
it('shows Cross Events\' events through the feed when the church has it, and makes none of its own', async () => {
|
||||
const h = await harness({ linked: false }) as Harness;
|
||||
await h.db.productLink.create({ data: { installId: 'ev-1', product: 'events', url: 'https://events.hope.test', publicKey: 'x', secret: h.ctx.secrets.encrypt('s'), connectedAt: new Date(), showEvents: false } });
|
||||
const r = await loadDemo(h.ctx, 'community-family');
|
||||
assert.equal(r.events.from, 'events');
|
||||
assert.equal(r.events.made, 0);
|
||||
assert.equal(await h.db.simpleEvent.count(), 0);
|
||||
assert.equal((await h.db.productLink.findUnique({ where: { installId: 'ev-1' } }))!.showEvents, true);
|
||||
});
|
||||
|
||||
it('never sends a demo person anything: reminders, devotionals and renewals stop at the sender', async () => {
|
||||
const h = await harness() as Harness;
|
||||
await fetchMessaging(h.ctx);
|
||||
await loadDemo(h.ctx, 'bold-plant');
|
||||
for (let i = 0; i < 24 * 4; i++) {
|
||||
await sendReminders(h.ctx);
|
||||
await queueDevotionals(h.ctx);
|
||||
await sendOutbox(h.ctx, { pauseMs: 0 });
|
||||
h.clock.add(15 * 60e3);
|
||||
}
|
||||
assert.ok(await h.db.outboxMessage.count() > 0, 'something was queued');
|
||||
assert.equal(h.transport.emails.length, 0);
|
||||
assert.equal(h.transport.whatsapps.length, 0);
|
||||
assert.equal(await h.db.outboxMessage.count({ where: { sentAt: null } }), 0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user