Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -0,0 +1,62 @@
import { describe, expect, it } from "vitest";
import {
buildPortalStatusMailDeliveryMetadata,
buildPortalStatusMailOutboxEvent,
parsePortalStatusMailDeliveryMetadata,
parsePortalStatusMailOutboxEnvelope,
PORTAL_STATUS_MAIL_DEBOUNCE_MS,
PORTAL_STATUS_MAIL_EVENT_TYPE,
} from "./portal-status-mail.js";
const payload = {
tenantId: "tenant_1",
projectId: "project_1",
previousStageId: "stage_old",
expectedStageId: "stage_new",
stageChangeId: "change_1",
};
describe("portal status mail contract", () => {
it("builds a PII-free, five-minute delayed and idempotent outbox event", () => {
const now = new Date("2026-07-15T10:00:00.000Z");
const event = buildPortalStatusMailOutboxEvent(payload, { now });
expect(event).toEqual({
tenantId: "tenant_1",
type: PORTAL_STATUS_MAIL_EVENT_TYPE,
dispatchKey: "portal-status:change_1",
scheduledAt: new Date(now.getTime() + PORTAL_STATUS_MAIL_DEBOUNCE_MS),
payload: { version: 1, ...payload },
});
expect(JSON.stringify(event)).not.toMatch(/@|customer|recipient|email/iu);
});
it("validates the dispatcher envelope and rejects tenant/key drift or extra payload fields", () => {
const event = buildPortalStatusMailOutboxEvent(payload);
const envelope = {
outboxEventId: "outbox_1",
tenantId: event.tenantId,
eventType: event.type,
dispatchKey: event.dispatchKey,
payload: event.payload,
};
expect(parsePortalStatusMailOutboxEnvelope(envelope)).toEqual(envelope);
expect(() => parsePortalStatusMailOutboxEnvelope({ ...envelope, tenantId: "tenant_2" })).toThrow(/tenant scope/iu);
expect(() => parsePortalStatusMailOutboxEnvelope({ ...envelope, dispatchKey: "portal-status:change_2" })).toThrow(/dispatch key/iu);
expect(() => parsePortalStatusMailOutboxEnvelope({ ...envelope, payload: { ...event.payload, email: "secret@example.test" } })).toThrow(
/unsupported shape/iu
);
});
it("keeps permanent-failure metadata bound to an internal user id", () => {
const metadata = buildPortalStatusMailDeliveryMetadata({
stageChangeId: "change_1",
projectId: "project_1",
expectedStageId: "stage_new",
internalRecipientUserId: "tenant_user_1",
});
expect(parsePortalStatusMailDeliveryMetadata(metadata)).toEqual(metadata);
expect(parsePortalStatusMailDeliveryMetadata({ ...metadata, internalRecipientUserId: "contains spaces" })).toBeNull();
});
});