import { brandStyleSchema, churchExportSchema, churchSchema, CORNERS, FONT_PAIRING_IDS, FONT_PAIRINGS, hub, identityRequestSchema, TEMPLATE_FONT_PAIRINGS, WEBSITE_TEMPLATES, } from "../src"; import type { Church, ChurchExport } from "../src"; import { sample } from "./helpers"; describe("brand style (1.17.0)", () => { it("has the 8 confirmed font pairings, ids unchanged", () => { // These ids are stored in churches' profiles: changing or removing one is a breaking change. expect(FONT_PAIRING_IDS).toEqual(["classic", "scholarly", "editorial", "impact", "contemporary", "friendly", "warm", "modern"]); expect(CORNERS).toEqual(["sharp", "soft", "round"]); }); it("each template recommends three different pairings, and every pairing is recommended somewhere", () => { expect(Object.keys(TEMPLATE_FONT_PAIRINGS).sort()).toEqual([...WEBSITE_TEMPLATES].sort()); for (const picks of Object.values(TEMPLATE_FONT_PAIRINGS)) expect(new Set(picks).size).toBe(3); const recommended = new Set(Object.values(TEMPLATE_FONT_PAIRINGS).flat()); expect([...recommended].sort()).toEqual([...FONT_PAIRING_IDS].sort()); }); it("every pairing names a heading and a body font", () => { for (const p of Object.values(FONT_PAIRINGS)) { expect(p.heading.family.length).toBeGreaterThan(0); expect(p.body.family.length).toBeGreaterThan(0); } }); it("a profile without a style still parses (Accounts before 1.7.0)", () => { const c = sample("church.json"); delete c.branding.style; const parsed = churchSchema.parse(c); expect(parsed.branding.style).toBeUndefined(); }); it("an unknown pairing or corner from a newer Accounts reads as null instead of failing", () => { expect(brandStyleSchema.parse({ fontPairing: "gothic", corners: "pointy" })).toEqual({ fontPairing: null, corners: null }); const c = sample("church.json"); const parsed = churchSchema.parse({ ...c, branding: { ...c.branding, style: { fontPairing: "gothic", corners: "round" } } }); expect(parsed.branding.style).toEqual({ fontPairing: null, corners: "round" }); }); }); describe("the Website's export (1.17.0)", () => { const data = () => sample("church-export-website.json"); it("is optional, so Events' and Accounts' exports are unchanged", () => { const events = churchExportSchema.parse(sample("church-export.json")); expect(events.website).toBeUndefined(); }); it("refuses an unknown template, a page path that isn't one, and media outside uploads/", () => { const d = data(); const bad = (website: object) => churchExportSchema.safeParse({ ...d, website: { ...d.website, ...website } }).success; expect(bad({ template: "minimal" })).toBe(false); expect(bad({ pages: [{ ...d.website!.pages[0]!, path: "about" }] })).toBe(false); expect(bad({ media: [{ path: "../etc/passwd", alt: null, caption: null }] })).toBe(false); }); it("a message is a YouTube-feed or hand-added link", () => { const d = data(); const msg = { ...d.website!.messages[0]!, source: "upload" }; expect(churchExportSchema.safeParse({ ...d, website: { ...d.website, messages: [msg] } }).success).toBe(false); }); }); describe("licence storage limit (1.17.0)", () => { it("is optional, and only whole non-negative bytes", () => { const lic = sample("hub-licence-payload-website.json"); expect(hub.licencePayloadSchema.parse(lic).limits.storageBytes).toBe(10737418240); expect(hub.licencePayloadSchema.parse(sample("hub-licence-payload.json")).limits.storageBytes).toBeUndefined(); expect(hub.licencePayloadSchema.safeParse({ ...lic, limits: { ...lic.limits, storageBytes: -1 } }).success).toBe(false); }); }); describe("church.update (1.17.0)", () => { const req = () => sample>("church-update.json"); it("needs an actor and something to change", () => { expect(identityRequestSchema.safeParse({ ...req(), actor: null }).success).toBe(false); expect(identityRequestSchema.safeParse({ ...req(), church: {} }).success).toBe(false); }); it("takes part of branding (only the style), but not the fields Accounts fills in", () => { const parsed = identityRequestSchema.parse({ ...req(), church: { branding: { style: { fontPairing: "modern", corners: null } } } }); expect(parsed.type === "church.update" && parsed.church.branding).toEqual({ style: { fontPairing: "modern", corners: null } }); const withLinks = identityRequestSchema.parse({ ...req(), church: { name: "Hope", links: { accounts: "https://evil.example" }, customerId: "x" } }); expect(withLinks.type === "church.update" && Object.keys(withLinks.church)).toEqual(["name"]); }); it("still checks what it's given", () => { expect(identityRequestSchema.safeParse({ ...req(), church: { branding: { colours: { primary: "blue", accent: null } } } }).success).toBe(false); }); });