Files
crosscode-platform/packages/demo/tests/demo.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

78 lines
3.7 KiB
TypeScript

import { agent, churchObjectSchema, DEMO_EMAIL_DOMAIN, hub } from "@crosscode/contracts";
import { DEMO_CHURCHES, demoChurch, demoIconSvg, demoId, demoLogoSvg, demoParts, demoPeople } from "../src";
describe("demo churches", () => {
it("has one per scenario, with unique names, slugs and shapes the profile accepts", () => {
expect(DEMO_CHURCHES.map((c) => c.scenario)).toEqual([...agent.DEMO_SCENARIO_KEYS]);
expect(new Set(DEMO_CHURCHES.map((c) => c.slug)).size).toBe(8);
expect(new Set(DEMO_CHURCHES.map((c) => c.profile.name)).size).toBe(8);
for (const c of DEMO_CHURCHES) {
const { colours, style, contact, ...rest } = c.profile;
const profile = { ...rest, branding: { logoUrl: null, iconUrl: null, colours, style }, contact: { ...contact, phone: null, whatsapp: null } };
const check = churchObjectSchema.omit({ schema: true, customerId: true, updatedAt: true, links: true }).safeParse(profile);
expect(check.success ? [] : check.error.issues).toEqual([]);
expect(contact.email!.endsWith(`@${DEMO_EMAIL_DOMAIN}`)).toBe(true);
for (const s of c.profile.social) expect(s.url.startsWith("https://example.com/")).toBe(true);
}
});
it("matches the contracts' scenario (church name, campuses, language)", () => {
for (const s of agent.DEMO_SCENARIOS) {
const c = demoChurch(s.key);
expect(c.profile.name.startsWith(s.church)).toBe(true);
expect(Math.max(1, c.profile.campuses.length)).toBe(s.campuses);
expect(c.profile.locale.startsWith(s.language)).toBe(true);
}
});
});
describe("demo people", () => {
it("are at example.com, unique, with ids that stay the same", () => {
for (const key of agent.DEMO_SCENARIO_KEYS) {
const people = demoPeople(key);
expect(new Set(people.map((p) => p.email)).size).toBe(people.length);
expect(new Set(people.map((p) => p.id)).size).toBe(people.length);
for (const p of people) expect(p.email.endsWith(`@${DEMO_EMAIL_DOMAIN}`)).toBe(true);
expect(demoPeople(key).map((p) => p.id)).toEqual(people.map((p) => p.id));
}
});
it("put the App in the scenario's band", () => {
for (const s of agent.DEMO_SCENARIOS) expect(hub.activeMemberBand(demoPeople(s.key).length)).toBe(s.appActiveMembers);
});
it("have a pastor and a prayer coordinator; a person with two parts has one account", () => {
for (const key of agent.DEMO_SCENARIO_KEYS) {
const people = demoPeople(key);
expect(people.filter((p) => p.part === "pastor")).toHaveLength(1);
expect(people.filter((p) => p.part === "prayer-coordinator")).toHaveLength(1);
}
const plant = demoParts("bold-plant");
expect([...plant.values()].some((parts) => parts.includes("pastor") && parts.includes("devotional-writer"))).toBe(true);
});
it("spread a multi-campus church's members over its campuses", () => {
const campuses = new Set(demoPeople("clean-campus").map((p) => p.campus));
expect(campuses).toEqual(new Set(["stellenbosch", "paarl", "somerset-west"]));
expect(new Set(demoPeople("community-family").map((p) => p.campus))).toEqual(new Set([null]));
});
it("demoId is a stable version-5 UUID", () => {
expect(demoId("a")).toBe(demoId("a"));
expect(demoId("a")).not.toBe(demoId("b"));
expect(demoId("a")).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
});
});
describe("logos", () => {
it("are SVG in the church's colour, with its name", () => {
for (const c of DEMO_CHURCHES) {
const icon = demoIconSvg(c.scenario);
const logo = demoLogoSvg(c.scenario);
expect(icon.startsWith("<svg")).toBe(true);
expect(icon).toContain(c.profile.colours.primary);
expect(logo).toContain(c.profile.name.replace(/'/g, "&apos;"));
}
});
});