- crosscode.event/1 and crosscode.event-feed/1 (feed, event.changed webhook), with session and registration rules; parseEventFeed skips and reports bad events instead of failing the whole feed. - crosscode.church/1: branding, campuses, service times, contact, links. - crosscode.identity/1: sign-in claims and the user.updated / user.deleted / user.export back-channel calls and replies. - Sign-in return helpers (isSafeReturnPath, encodeState/decodeState, isRegisteredRedirectUri) so every product returns people to the page they came from in the same safe way. - Hub protocol v2: product on register/heartbeat, stats per product, install public key, linked products, customerId/product in licences. - @crosscode/contracts/signing (Node only): the Hub's HMAC scheme. - Samples for every contract in samples/, checked by the tests (120). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
2.2 KiB
TypeScript
50 lines
2.2 KiB
TypeScript
import { accountsCallSchema, churchSchema, identityClaimsSchema, userDeletedReplySchema } from "../src";
|
|
import type { Church } from "../src";
|
|
import { sample } from "./helpers";
|
|
|
|
describe("crosscode.church/1", () => {
|
|
const church = () => sample<Church>("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);
|
|
});
|
|
});
|