mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 21:54:32 +00:00
test(telegram): dedupe shared reply/chat-not-found cases
This commit is contained in:
@@ -1154,78 +1154,94 @@ describe("sendStickerTelegram", () => {
|
|||||||
|
|
||||||
describe("shared send behaviors", () => {
|
describe("shared send behaviors", () => {
|
||||||
it("includes reply_to_message_id for threaded replies", async () => {
|
it("includes reply_to_message_id for threaded replies", async () => {
|
||||||
{
|
const cases = [
|
||||||
const chatId = "123";
|
{
|
||||||
const sendMessage = vi.fn().mockResolvedValue({
|
name: "message send",
|
||||||
message_id: 56,
|
run: async () => {
|
||||||
chat: { id: chatId },
|
const chatId = "123";
|
||||||
});
|
const sendMessage = vi.fn().mockResolvedValue({
|
||||||
const api = { sendMessage } as unknown as {
|
message_id: 56,
|
||||||
sendMessage: typeof sendMessage;
|
chat: { id: chatId },
|
||||||
};
|
});
|
||||||
|
const api = { sendMessage } as unknown as {
|
||||||
|
sendMessage: typeof sendMessage;
|
||||||
|
};
|
||||||
|
await sendMessageTelegram(chatId, "reply text", {
|
||||||
|
token: "tok",
|
||||||
|
api,
|
||||||
|
replyToMessageId: 100,
|
||||||
|
});
|
||||||
|
expect(sendMessage).toHaveBeenCalledWith(chatId, "reply text", {
|
||||||
|
parse_mode: "HTML",
|
||||||
|
reply_to_message_id: 100,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sticker send",
|
||||||
|
run: async () => {
|
||||||
|
const chatId = "123";
|
||||||
|
const fileId = "CAACAgIAAxkBAAI...sticker_file_id";
|
||||||
|
const sendSticker = vi.fn().mockResolvedValue({
|
||||||
|
message_id: 102,
|
||||||
|
chat: { id: chatId },
|
||||||
|
});
|
||||||
|
const api = { sendSticker } as unknown as {
|
||||||
|
sendSticker: typeof sendSticker;
|
||||||
|
};
|
||||||
|
await sendStickerTelegram(chatId, fileId, {
|
||||||
|
token: "tok",
|
||||||
|
api,
|
||||||
|
replyToMessageId: 500,
|
||||||
|
});
|
||||||
|
expect(sendSticker).toHaveBeenCalledWith(chatId, fileId, {
|
||||||
|
reply_to_message_id: 500,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
|
|
||||||
await sendMessageTelegram(chatId, "reply text", {
|
for (const testCase of cases) {
|
||||||
token: "tok",
|
await testCase.run();
|
||||||
api,
|
|
||||||
replyToMessageId: 100,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(sendMessage).toHaveBeenCalledWith(chatId, "reply text", {
|
|
||||||
parse_mode: "HTML",
|
|
||||||
reply_to_message_id: 100,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const chatId = "123";
|
|
||||||
const fileId = "CAACAgIAAxkBAAI...sticker_file_id";
|
|
||||||
const sendSticker = vi.fn().mockResolvedValue({
|
|
||||||
message_id: 102,
|
|
||||||
chat: { id: chatId },
|
|
||||||
});
|
|
||||||
const api = { sendSticker } as unknown as {
|
|
||||||
sendSticker: typeof sendSticker;
|
|
||||||
};
|
|
||||||
|
|
||||||
await sendStickerTelegram(chatId, fileId, {
|
|
||||||
token: "tok",
|
|
||||||
api,
|
|
||||||
replyToMessageId: 500,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(sendSticker).toHaveBeenCalledWith(chatId, fileId, {
|
|
||||||
reply_to_message_id: 500,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("wraps chat-not-found with actionable context", async () => {
|
it("wraps chat-not-found with actionable context", async () => {
|
||||||
{
|
const cases = [
|
||||||
const chatId = "123";
|
{
|
||||||
const err = new Error("400: Bad Request: chat not found");
|
name: "message send",
|
||||||
const sendMessage = vi.fn().mockRejectedValue(err);
|
run: async () => {
|
||||||
const api = { sendMessage } as unknown as {
|
const chatId = "123";
|
||||||
sendMessage: typeof sendMessage;
|
const err = new Error("400: Bad Request: chat not found");
|
||||||
};
|
const sendMessage = vi.fn().mockRejectedValue(err);
|
||||||
|
const api = { sendMessage } as unknown as {
|
||||||
|
sendMessage: typeof sendMessage;
|
||||||
|
};
|
||||||
|
await expectChatNotFoundWithChatId(
|
||||||
|
sendMessageTelegram(chatId, "hi", { token: "tok", api }),
|
||||||
|
chatId,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sticker send",
|
||||||
|
run: async () => {
|
||||||
|
const chatId = "123";
|
||||||
|
const err = new Error("400: Bad Request: chat not found");
|
||||||
|
const sendSticker = vi.fn().mockRejectedValue(err);
|
||||||
|
const api = { sendSticker } as unknown as {
|
||||||
|
sendSticker: typeof sendSticker;
|
||||||
|
};
|
||||||
|
await expectChatNotFoundWithChatId(
|
||||||
|
sendStickerTelegram(chatId, "fileId123", { token: "tok", api }),
|
||||||
|
chatId,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
|
|
||||||
await expectChatNotFoundWithChatId(
|
for (const testCase of cases) {
|
||||||
sendMessageTelegram(chatId, "hi", { token: "tok", api }),
|
await testCase.run();
|
||||||
chatId,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const chatId = "123";
|
|
||||||
const err = new Error("400: Bad Request: chat not found");
|
|
||||||
const sendSticker = vi.fn().mockRejectedValue(err);
|
|
||||||
const api = { sendSticker } as unknown as {
|
|
||||||
sendSticker: typeof sendSticker;
|
|
||||||
};
|
|
||||||
|
|
||||||
await expectChatNotFoundWithChatId(
|
|
||||||
sendStickerTelegram(chatId, "fileId123", { token: "tok", api }),
|
|
||||||
chatId,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user