Slack: validate runtime blocks in send and edit paths

This commit is contained in:
Colin
2026-02-16 13:04:42 -05:00
committed by Peter Steinberger
parent c01c6b7079
commit 6e790303df
5 changed files with 126 additions and 4 deletions

View File

@@ -62,4 +62,41 @@ describe("sendMessageSlack blocks", () => {
).rejects.toThrow(/does not support blocks with mediaUrl/i);
expect(client.chat.postMessage).not.toHaveBeenCalled();
});
it("rejects empty blocks arrays from runtime callers", async () => {
const client = createClient();
await expect(
sendMessageSlack("channel:C123", "hi", {
token: "xoxb-test",
client,
blocks: [],
}),
).rejects.toThrow(/must contain at least one block/i);
expect(client.chat.postMessage).not.toHaveBeenCalled();
});
it("rejects blocks arrays above Slack max count", async () => {
const client = createClient();
const blocks = Array.from({ length: 51 }, () => ({ type: "divider" }));
await expect(
sendMessageSlack("channel:C123", "hi", {
token: "xoxb-test",
client,
blocks,
}),
).rejects.toThrow(/cannot exceed 50 items/i);
expect(client.chat.postMessage).not.toHaveBeenCalled();
});
it("rejects blocks missing type from runtime callers", async () => {
const client = createClient();
await expect(
sendMessageSlack("channel:C123", "hi", {
token: "xoxb-test",
client,
blocks: [{} as { type: string }],
}),
).rejects.toThrow(/non-empty string type/i);
expect(client.chat.postMessage).not.toHaveBeenCalled();
});
});