mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 15:18:28 +00:00
test: add fetch mock helper and reaction coverage
This commit is contained in:
@@ -1001,6 +1001,44 @@ describe("createTelegramBot", () => {
|
||||
expect(enqueueSystemEventSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("enqueues one event per added emoji reaction", async () => {
|
||||
onSpy.mockReset();
|
||||
enqueueSystemEventSpy.mockReset();
|
||||
|
||||
loadConfig.mockReturnValue({
|
||||
channels: {
|
||||
telegram: { dmPolicy: "open", reactionNotifications: "all" },
|
||||
},
|
||||
});
|
||||
|
||||
createTelegramBot({ token: "tok" });
|
||||
const handler = getOnHandler("message_reaction") as (
|
||||
ctx: Record<string, unknown>,
|
||||
) => Promise<void>;
|
||||
|
||||
await handler({
|
||||
update: { update_id: 505 },
|
||||
messageReaction: {
|
||||
chat: { id: 1234, type: "private" },
|
||||
message_id: 42,
|
||||
user: { id: 9, first_name: "Ada" },
|
||||
date: 1736380800,
|
||||
old_reaction: [{ type: "emoji", emoji: "👍" }],
|
||||
new_reaction: [
|
||||
{ type: "emoji", emoji: "👍" },
|
||||
{ type: "emoji", emoji: "🔥" },
|
||||
{ type: "emoji", emoji: "🎉" },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(enqueueSystemEventSpy).toHaveBeenCalledTimes(2);
|
||||
expect(enqueueSystemEventSpy.mock.calls.map((call) => call[0])).toEqual([
|
||||
"Telegram reaction added: 🔥 by Ada on msg 42",
|
||||
"Telegram reaction added: 🎉 by Ada on msg 42",
|
||||
]);
|
||||
});
|
||||
|
||||
it("routes forum group reactions to the general topic (thread id not available on reactions)", async () => {
|
||||
onSpy.mockReset();
|
||||
enqueueSystemEventSpy.mockReset();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { type Mock, describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
||||
import { withFetchPreconnect } from "../test-utils/fetch-mock.js";
|
||||
import { probeTelegram } from "./probe.js";
|
||||
|
||||
describe("probeTelegram retry logic", () => {
|
||||
@@ -38,7 +39,7 @@ describe("probeTelegram retry logic", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
fetchMock = vi.fn();
|
||||
global.fetch = fetchMock;
|
||||
global.fetch = withFetchPreconnect(fetchMock);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user