Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/worker/src/jobs/automation-forward.test.ts
T

32 lines
1.4 KiB
TypeScript

// R-P12c — worker seam tests: envelope parsing (tenant mismatch fail-closed)
// and companion-consumer skip behaviour for non-automation events.
import { describe, expect, test } from "vitest";
import { AutomationExecutorJobError, parseAutomationExecutorOutboxJob } from "./automation-forward.js";
describe("parseAutomationExecutorOutboxJob", () => {
test("accepts a well-formed automation.execution.requested envelope", () => {
expect(
parseAutomationExecutorOutboxJob({
eventType: "automation.execution.requested",
tenantId: "tenant-a",
payload: { executionId: "exec-1", tenantId: "tenant-a" },
})
).toEqual({ tenantId: "tenant-a", executionId: "exec-1" });
});
test("rejects foreign event types, missing ids and tenant mismatches fail-closed", () => {
expect(() => parseAutomationExecutorOutboxJob({ eventType: "workflow.trigger.event", tenantId: "t", payload: {} })).toThrow(AutomationExecutorJobError);
expect(() => parseAutomationExecutorOutboxJob({ eventType: "automation.execution.requested", tenantId: "", payload: { executionId: "e" } })).toThrow(
AutomationExecutorJobError
);
expect(() =>
parseAutomationExecutorOutboxJob({
eventType: "automation.execution.requested",
tenantId: "tenant-a",
payload: { executionId: "exec-1", tenantId: "tenant-b" },
})
).toThrow(/tenantId mismatch/);
});
});