Files
openclaw/extensions/slack/src/blocks.test-helpers.ts
Josh Avant b965ef3802 Channels: stabilize lane harness and monitor tests (#50167)
* Channels: stabilize lane harness regressions

* Signal tests: stabilize tool-result harness dispatch

* Telegram tests: harden polling restart assertions

* Discord tests: stabilize channel lane harness coverage

* Slack tests: align slash harness runtime mocks

* Telegram tests: harden dispatch and pairing scenarios

* Telegram tests: fix SessionEntry typing in bot callback override case

* Slack tests: avoid slash runtime mock deadlock

* Tests: address bot review follow-ups

* Discord: restore accounts runtime-api seam

* Tests: stabilize Discord and Telegram channel harness assertions

* Tests: clarify Discord mock seam and remove unused Telegram import

* changelog

Signed-off-by: joshavant <830519+joshavant@users.noreply.github.com>

---------

Signed-off-by: joshavant <830519+joshavant@users.noreply.github.com>
2026-03-19 01:47:48 -05:00

68 lines
1.6 KiB
TypeScript

import type { WebClient } from "@slack/web-api";
import { vi } from "vitest";
export type SlackEditTestClient = WebClient & {
chat: {
update: ReturnType<typeof vi.fn>;
};
};
export 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("openclaw/plugin-sdk/config-runtime", async (importOriginal) => {
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/config-runtime")>();
return {
...actual,
loadConfig: () => slackBlockTestState.config,
};
});
vi.mock("./accounts.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("./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;
}