mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 07:07:39 +00:00
test(slack): dedupe block and draft stream test fixtures
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user