test: share twitch send success mocks

This commit is contained in:
Peter Steinberger 2026-03-13 21:16:46 +00:00
parent a8508f2b31
commit 867dc6a185
1 changed files with 18 additions and 15 deletions

View File

@ -55,7 +55,10 @@ describe("send", () => {
installTwitchTestHooks();
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 { getClientManager } = await import("./client-manager-registry.js");
const { stripMarkdownForTwitch } = await import("./utils/markdown.js");
@ -64,10 +67,18 @@ describe("send", () => {
vi.mocked(getClientManager).mockReturnValue({
sendMessage: vi.fn().mockResolvedValue({
ok: true,
messageId: "twitch-msg-123",
messageId: params.messageId,
}),
} 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(
"#testchannel",
@ -83,18 +94,10 @@ describe("send", () => {
});
it("should strip markdown when enabled", async () => {
const { getAccountConfig } = await import("./config.js");
const { getClientManager } = await import("./client-manager-registry.js");
const { stripMarkdownForTwitch } = await import("./utils/markdown.js");
vi.mocked(getAccountConfig).mockReturnValue(mockAccount);
vi.mocked(getClientManager).mockReturnValue({
sendMessage: vi.fn().mockResolvedValue({
ok: true,
const { stripMarkdownForTwitch } = await mockSuccessfulSend({
messageId: "twitch-msg-456",
}),
} as unknown as ReturnType<typeof getClientManager>);
vi.mocked(stripMarkdownForTwitch).mockImplementation((text) => text.replace(/\*\*/g, ""));
stripMarkdown: (text) => text.replace(/\*\*/g, ""),
});
await sendMessageTwitchInternal(
"#testchannel",