test: merge slack validation cases

This commit is contained in:
Peter Steinberger
2026-03-17 10:02:34 +00:00
parent 6646ca61cc
commit 4a95e6529f

View File

@@ -1281,10 +1281,11 @@ describe("slack actions adapter", () => {
} }
}); });
it("rejects invalid send block combinations before dispatch", async () => { it("rejects invalid Slack payloads before dispatch", async () => {
const cases = [ const cases = [
{ {
name: "invalid JSON", name: "invalid JSON",
action: "send" as const,
params: { params: {
to: "channel:C1", to: "channel:C1",
message: "", message: "",
@@ -1294,6 +1295,7 @@ describe("slack actions adapter", () => {
}, },
{ {
name: "empty blocks", name: "empty blocks",
action: "send" as const,
params: { params: {
to: "channel:C1", to: "channel:C1",
message: "", message: "",
@@ -1303,6 +1305,7 @@ describe("slack actions adapter", () => {
}, },
{ {
name: "blocks with media", name: "blocks with media",
action: "send" as const,
params: { params: {
to: "channel:C1", to: "channel:C1",
message: "", message: "",
@@ -1311,29 +1314,34 @@ describe("slack actions adapter", () => {
}, },
error: /does not support blocks with media/i, error: /does not support blocks with media/i,
}, },
] as const; {
name: "edit missing message and blocks",
for (const testCase of cases) { action: "edit" as const,
handleSlackAction.mockClear();
await expectSlackSendRejected(testCase.params, testCase.error);
}
});
it("rejects edit when both message and blocks are missing", async () => {
const { cfg, actions } = slackHarness();
await expect(
actions.handleAction?.({
channel: "slack",
action: "edit",
cfg,
params: { params: {
channelId: "C1", channelId: "C1",
messageId: "171234.567", messageId: "171234.567",
message: "", message: "",
}, },
}), error: /edit requires message or blocks/i,
).rejects.toThrow(/edit requires message or blocks/i); },
expect(handleSlackAction).not.toHaveBeenCalled(); ] as const;
for (const testCase of cases) {
handleSlackAction.mockClear();
if (testCase.action === "send") {
await expectSlackSendRejected(testCase.params, testCase.error);
} else {
const { cfg, actions } = slackHarness();
await expect(
actions.handleAction?.({
channel: "slack",
action: "edit",
cfg,
params: testCase.params,
}),
).rejects.toThrow(testCase.error);
}
expect(handleSlackAction, testCase.name).not.toHaveBeenCalled();
}
}); });
}); });