45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
parseInvalidationEvent,
|
|
toInvalidationEvent,
|
|
} from "./invalidation";
|
|
|
|
describe("invalidation event envelopes", () => {
|
|
it("strips every field except type, opaque id, and version", () => {
|
|
const event = toInvalidationEvent({
|
|
topic: "directory",
|
|
aggregateId: "4afeea7b-6f24-43f3-b747-2db98335e01e",
|
|
eventType: "directory.updated",
|
|
payload: {
|
|
id: "4afeea7b-6f24-43f3-b747-2db98335e01e",
|
|
version: 3,
|
|
title: "private draft title",
|
|
blocks: [{ content: "private" }],
|
|
},
|
|
});
|
|
expect(event).toEqual({
|
|
type: "directory.updated",
|
|
id: "4afeea7b-6f24-43f3-b747-2db98335e01e",
|
|
version: 3,
|
|
});
|
|
});
|
|
|
|
it("rejects unknown, malformed, and topic-mismatched messages", () => {
|
|
expect(parseInvalidationEvent("not json")).toBeNull();
|
|
expect(
|
|
parseInvalidationEvent(
|
|
JSON.stringify({ type: "page.content", id: "id", version: 1 }),
|
|
),
|
|
).toBeNull();
|
|
expect(
|
|
toInvalidationEvent({
|
|
topic: "admin",
|
|
aggregateId: "id",
|
|
eventType: "page.updated",
|
|
payload: { id: "id", version: 1 },
|
|
}),
|
|
).toBeNull();
|
|
});
|
|
});
|