test(slack): dedupe block and draft stream test fixtures

This commit is contained in:
Peter Steinberger
2026-02-18 12:57:51 +00:00
parent 3daf730fcc
commit 7bca5f5400
4 changed files with 138 additions and 144 deletions

View File

@@ -1,38 +1,12 @@
import type { WebClient } from "@slack/web-api";
import { describe, expect, it, vi } from "vitest";
vi.mock("../config/config.js", () => ({
loadConfig: () => ({}),
}));
vi.mock("./accounts.js", () => ({
resolveSlackAccount: () => ({
accountId: "default",
botToken: "xoxb-test",
botTokenSource: "config",
config: {},
}),
}));
import { describe, expect, it } from "vitest";
import { createSlackSendTestClient, installSlackBlockTestMocks } from "./blocks.test-helpers.js";
installSlackBlockTestMocks();
const { sendMessageSlack } = await import("./send.js");
function createClient() {
return {
conversations: {
open: vi.fn(async () => ({ channel: { id: "D123" } })),
},
chat: {
postMessage: vi.fn(async () => ({ ts: "171234.567" })),
},
} as unknown as WebClient & {
conversations: { open: ReturnType<typeof vi.fn> };
chat: { postMessage: ReturnType<typeof vi.fn> };
};
}
describe("sendMessageSlack blocks", () => {
it("posts blocks with fallback text when message is empty", async () => {
const client = createClient();
const client = createSlackSendTestClient();
const result = await sendMessageSlack("channel:C123", "", {
token: "xoxb-test",
client,
@@ -51,7 +25,7 @@ describe("sendMessageSlack blocks", () => {
});
it("derives fallback text from image blocks", async () => {
const client = createClient();
const client = createSlackSendTestClient();
await sendMessageSlack("channel:C123", "", {
token: "xoxb-test",
client,
@@ -66,7 +40,7 @@ describe("sendMessageSlack blocks", () => {
});
it("derives fallback text from video blocks", async () => {
const client = createClient();
const client = createSlackSendTestClient();
await sendMessageSlack("channel:C123", "", {
token: "xoxb-test",
client,
@@ -89,7 +63,7 @@ describe("sendMessageSlack blocks", () => {
});
it("derives fallback text from file blocks", async () => {
const client = createClient();
const client = createSlackSendTestClient();
await sendMessageSlack("channel:C123", "", {
token: "xoxb-test",
client,
@@ -104,7 +78,7 @@ describe("sendMessageSlack blocks", () => {
});
it("rejects blocks combined with mediaUrl", async () => {
const client = createClient();
const client = createSlackSendTestClient();
await expect(
sendMessageSlack("channel:C123", "hi", {
token: "xoxb-test",
@@ -117,7 +91,7 @@ describe("sendMessageSlack blocks", () => {
});
it("rejects empty blocks arrays from runtime callers", async () => {
const client = createClient();
const client = createSlackSendTestClient();
await expect(
sendMessageSlack("channel:C123", "hi", {
token: "xoxb-test",
@@ -129,7 +103,7 @@ describe("sendMessageSlack blocks", () => {
});
it("rejects blocks arrays above Slack max count", async () => {
const client = createClient();
const client = createSlackSendTestClient();
const blocks = Array.from({ length: 51 }, () => ({ type: "divider" }));
await expect(
sendMessageSlack("channel:C123", "hi", {
@@ -142,7 +116,7 @@ describe("sendMessageSlack blocks", () => {
});
it("rejects blocks missing type from runtime callers", async () => {
const client = createClient();
const client = createSlackSendTestClient();
await expect(
sendMessageSlack("channel:C123", "hi", {
token: "xoxb-test",