Files
crosscode-platform/packages/contracts/tests/samples.test.ts
T
joshuaandClaude Opus 5.5 4952e2cb0f Contracts 1.4.0: crosscode.link/1 and a public key in the v2 heartbeat
- crosscode.link/1 (link.connect / link.connected / link.disconnect), with
  signLink / verifyLink, PEM conversion, link secrets and nonces.
- The v2 heartbeat can carry the install's publicKey; the reply says
  saved / matches / mismatch (Hub 2.2.0). Never a failed heartbeat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 11:58:26 +02:00

64 lines
2.2 KiB
TypeScript

import { readdirSync } from "node:fs";
import type { z } from "zod";
import {
accountsCallSchema,
churchExportSchema,
churchSchema,
eventChangedSchema,
eventFeedSchema,
eventSchema,
hub,
linkConnectSchema,
linkConnectedSchema,
linkDisconnectSchema,
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,
"church-export.json": churchExportSchema,
"link-connect.json": linkConnectSchema,
"link-connected.json": linkConnectedSchema,
"link-disconnect.json": linkDisconnectSchema,
};
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);
});
});