mirror of https://github.com/openclaw/openclaw.git
test: share twitch send success mocks
This commit is contained in:
parent
a8508f2b31
commit
867dc6a185
|
|
@ -55,7 +55,10 @@ describe("send", () => {
|
||||||
installTwitchTestHooks();
|
installTwitchTestHooks();
|
||||||
|
|
||||||
describe("sendMessageTwitchInternal", () => {
|
describe("sendMessageTwitchInternal", () => {
|
||||||
it("should send a message successfully", async () => {
|
async function mockSuccessfulSend(params: {
|
||||||
|
messageId: string;
|
||||||
|
stripMarkdown?: (text: string) => string;
|
||||||
|
}) {
|
||||||
const { getAccountConfig } = await import("./config.js");
|
const { getAccountConfig } = await import("./config.js");
|
||||||
const { getClientManager } = await import("./client-manager-registry.js");
|
const { getClientManager } = await import("./client-manager-registry.js");
|
||||||
const { stripMarkdownForTwitch } = await import("./utils/markdown.js");
|
const { stripMarkdownForTwitch } = await import("./utils/markdown.js");
|
||||||
|
|
@ -64,10 +67,18 @@ describe("send", () => {
|
||||||
vi.mocked(getClientManager).mockReturnValue({
|
vi.mocked(getClientManager).mockReturnValue({
|
||||||
sendMessage: vi.fn().mockResolvedValue({
|
sendMessage: vi.fn().mockResolvedValue({
|
||||||
ok: true,
|
ok: true,
|
||||||
messageId: "twitch-msg-123",
|
messageId: params.messageId,
|
||||||
}),
|
}),
|
||||||
} as unknown as ReturnType<typeof getClientManager>);
|
} as unknown as ReturnType<typeof getClientManager>);
|
||||||
vi.mocked(stripMarkdownForTwitch).mockImplementation((text) => text);
|
vi.mocked(stripMarkdownForTwitch).mockImplementation(
|
||||||
|
params.stripMarkdown ?? ((text) => text),
|
||||||
|
);
|
||||||
|
|
||||||
|
return { stripMarkdownForTwitch };
|
||||||
|
}
|
||||||
|
|
||||||
|
it("should send a message successfully", async () => {
|
||||||
|
await mockSuccessfulSend({ messageId: "twitch-msg-123" });
|
||||||
|
|
||||||
const result = await sendMessageTwitchInternal(
|
const result = await sendMessageTwitchInternal(
|
||||||
"#testchannel",
|
"#testchannel",
|
||||||
|
|
@ -83,18 +94,10 @@ describe("send", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should strip markdown when enabled", async () => {
|
it("should strip markdown when enabled", async () => {
|
||||||
const { getAccountConfig } = await import("./config.js");
|
const { stripMarkdownForTwitch } = await mockSuccessfulSend({
|
||||||
const { getClientManager } = await import("./client-manager-registry.js");
|
messageId: "twitch-msg-456",
|
||||||
const { stripMarkdownForTwitch } = await import("./utils/markdown.js");
|
stripMarkdown: (text) => text.replace(/\*\*/g, ""),
|
||||||
|
});
|
||||||
vi.mocked(getAccountConfig).mockReturnValue(mockAccount);
|
|
||||||
vi.mocked(getClientManager).mockReturnValue({
|
|
||||||
sendMessage: vi.fn().mockResolvedValue({
|
|
||||||
ok: true,
|
|
||||||
messageId: "twitch-msg-456",
|
|
||||||
}),
|
|
||||||
} as unknown as ReturnType<typeof getClientManager>);
|
|
||||||
vi.mocked(stripMarkdownForTwitch).mockImplementation((text) => text.replace(/\*\*/g, ""));
|
|
||||||
|
|
||||||
await sendMessageTwitchInternal(
|
await sendMessageTwitchInternal(
|
||||||
"#testchannel",
|
"#testchannel",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue