Files
openclaw/extensions/slack/src/blocks.test-helpers.ts
2026-05-01 20:26:34 +01:00

60 lines
1.3 KiB
TypeScript

import type { WebClient } from "@slack/web-api";
import { vi } from "vitest";
type SlackEditTestClient = WebClient & {
chat: {
update: ReturnType<typeof vi.fn>;
};
};
type SlackSendTestClient = WebClient & {
conversations: {
open: ReturnType<typeof vi.fn>;
};
chat: {
postMessage: ReturnType<typeof vi.fn>;
};
};
const slackBlockTestState = vi.hoisted(() => ({
account: {
accountId: "default",
botToken: "xoxb-test",
botTokenSource: "config",
config: {},
},
config: {},
}));
vi.mock("./accounts.js", async () => {
const actual = await vi.importActual<typeof import("./accounts.js")>("./accounts.js");
return {
...actual,
resolveSlackAccount: () => slackBlockTestState.account,
};
});
// Kept for compatibility with existing tests; mocks install at module evaluation.
export function installSlackBlockTestMocks() {
return;
}
export function createSlackEditTestClient(): SlackEditTestClient {
return {
chat: {
update: vi.fn(async () => ({ ok: true })),
},
} as unknown as SlackEditTestClient;
}
export function createSlackSendTestClient(): SlackSendTestClient {
return {
conversations: {
open: vi.fn(async () => ({ channel: { id: "D123" } })),
},
chat: {
postMessage: vi.fn(async () => ({ ts: "171234.567" })),
},
} as unknown as SlackSendTestClient;
}