Files
crosscode-platform/packages/contracts/tests/samples.test.ts
T
joshuaandClaude Opus 5.5 ea1575f716 Contracts: event, event feed, church, identity, sign-in return, Hub protocol v2
- 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>
2026-11-04 09:47:40 +02:00

56 lines
2.0 KiB
TypeScript

import { readdirSync } from "node:fs";
import type { z } from "zod";
import {
accountsCallSchema,
churchSchema,
eventChangedSchema,
eventFeedSchema,
eventSchema,
hub,
identityClaimsSchema,
userDeletedReplySchema,
userExportReplySchema,
} from "../src";
import { SAMPLES, sample } from "./helpers";
/** Every sample file and the schema it must pass. A new sample without an entry fails the test. */
const SCHEMAS: Record<string, z.ZodType> = {
"event.json": eventSchema,
"event-simple.json": eventSchema,
"event-feed.json": eventFeedSchema,
"event-changed.json": eventChangedSchema,
"church.json": churchSchema,
"identity-claims.json": identityClaimsSchema,
"user-updated.json": accountsCallSchema,
"user-deleted.json": accountsCallSchema,
"user-deleted-reply.json": userDeletedReplySchema,
"user-export.json": accountsCallSchema,
"user-export-reply.json": userExportReplySchema,
"hub-register-request.json": hub.registerRequestSchema,
"hub-register-response.json": hub.registerResponseSchema,
"hub-heartbeat-events.json": hub.heartbeatRequestSchema,
"hub-heartbeat-website.json": hub.heartbeatRequestSchema,
"hub-heartbeat-app.json": hub.heartbeatRequestSchema,
"hub-heartbeat-accounts.json": hub.heartbeatRequestSchema,
"hub-heartbeat-response.json": hub.heartbeatResponseSchema,
"hub-licence-payload.json": hub.licencePayloadSchema,
};
describe("samples", () => {
const files = readdirSync(SAMPLES).filter((f) => f.endsWith(".json"));
it("every sample has a schema", () => {
expect(files.filter((f) => !(f in SCHEMAS))).toEqual([]);
});
it.each(Object.entries(SCHEMAS))("%s is valid", (file, schema) => {
const result = schema.safeParse(sample(file));
expect(result.success ? [] : result.error.issues).toEqual([]);
});
it.each(Object.entries(SCHEMAS))("%s keeps every field it sends (no field is silently dropped)", (file, schema) => {
const input = sample(file);
expect(schema.parse(input)).toEqual(input);
});
});