import { accountsCallSchema, churchSchema, identityClaimsSchema, userDeletedReplySchema } from "../src"; import type { Church } from "../src"; import { sample } from "./helpers"; describe("crosscode.church/1", () => { const church = () => sample("church.json"); it("refuses a service time for a campus that doesn't exist", () => { const c = church(); c.serviceTimes[0]!.campus = "vereeniging"; const r = churchSchema.safeParse(c); expect(r.success).toBe(false); expect(r.error?.issues[0]?.message).toBe('Unknown campus "vereeniging"'); }); it("refuses duplicate campus slugs", () => { const c = church(); c.campuses.push({ ...c.campuses[0]! }); expect(churchSchema.safeParse(c).success).toBe(false); }); it("checks colours, times and phone numbers", () => { const c = church(); expect(churchSchema.safeParse({ ...c, branding: { ...c.branding, colours: { primary: "blue", accent: null } } }).success).toBe(false); expect(churchSchema.safeParse({ ...c, serviceTimes: [{ ...c.serviceTimes[0]!, time: "9am" }] }).success).toBe(false); expect(churchSchema.safeParse({ ...c, contact: { ...c.contact, phone: "016 123 4567" } }).success).toBe(false); }); }); describe("crosscode.identity/1", () => { it("has no roles in the claims (roles stay in each product)", () => { const parsed = identityClaimsSchema.parse({ ...sample("identity-claims.json"), role: "admin" }); expect(parsed).not.toHaveProperty("role"); }); it("knows the authenticator app as a 2FA method", () => { expect(identityClaimsSchema.safeParse({ ...sample("identity-claims.json"), two_factor: "sms" }).success).toBe(false); }); it("tells the back-channel calls apart by type", () => { expect(accountsCallSchema.parse(sample("user-deleted.json")).type).toBe("user.deleted"); expect(accountsCallSchema.safeParse({ ...sample("user-deleted.json"), type: "user.renamed" }).success).toBe(false); }); it("a deferred delete needs a reason and a retry time", () => { expect(userDeletedReplySchema.safeParse({ schema: "crosscode.identity/1", status: "deferred" }).success).toBe(false); expect(userDeletedReplySchema.safeParse({ schema: "crosscode.identity/1", status: "deleted" }).success).toBe(true); }); });