Product -> Accounts requests at /api/accounts/v1/requests, signed with the link secret: import.begin/batch/finish/abort for moving a product's users in (EVENTS-3.0-PLAN §4), people.* for product admins (§8). sealLinkValue / openLinkValue seal password hashes and TOTP secrets with a key derived from the link secret; importIdsHash for the final check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
2.7 KiB
TypeScript
75 lines
2.7 KiB
TypeScript
import { readdirSync } from "node:fs";
|
|
import type { z } from "zod";
|
|
import {
|
|
accountsCallSchema,
|
|
churchExportSchema,
|
|
churchSchema,
|
|
eventChangedSchema,
|
|
eventFeedSchema,
|
|
eventSchema,
|
|
hub,
|
|
churchChangedSchema,
|
|
linkConnectSchema,
|
|
linkConnectedSchema,
|
|
linkDisconnectSchema,
|
|
identityClaimsSchema,
|
|
identityRequestSchema,
|
|
importBatchReplySchema,
|
|
peopleEnsureReplySchema,
|
|
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,
|
|
"church-changed.json": churchChangedSchema,
|
|
"link-connect.json": linkConnectSchema,
|
|
"link-connected.json": linkConnectedSchema,
|
|
"link-disconnect.json": linkDisconnectSchema,
|
|
"import-begin.json": identityRequestSchema,
|
|
"import-batch.json": identityRequestSchema,
|
|
"import-batch-reply.json": importBatchReplySchema,
|
|
"import-finish.json": identityRequestSchema,
|
|
"people-ensure.json": identityRequestSchema,
|
|
"people-ensure-reply.json": peopleEnsureReplySchema,
|
|
};
|
|
|
|
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);
|
|
});
|
|
});
|