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(" { it("every scenario has women and men among its leads and members", () => { for (const key of agent.DEMO_SCENARIO_KEYS) { const people = demoPeople(key); const women = people.filter((p) => p.gender === "female").length; expect(women).toBeGreaterThan(people.length * 0.3); expect(people.length - women).toBeGreaterThan(people.length * 0.2); } expect(demoPeople("community-family").find((p) => p.part === "pastor")?.gender).toBe("male"); expect(demoPeople("heritage-parish").find((p) => p.part === "pastor")?.gender).toBe("female"); }); });