test(telegram): dedupe shared reply/chat-not-found cases

This commit is contained in:
Peter Steinberger
2026-02-21 23:03:24 +00:00
parent fa4e4efd92
commit 1534248169

View File

@@ -1154,7 +1154,10 @@ 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 = [
{ {
name: "message send",
run: async () => {
const chatId = "123"; const chatId = "123";
const sendMessage = vi.fn().mockResolvedValue({ const sendMessage = vi.fn().mockResolvedValue({
message_id: 56, message_id: 56,
@@ -1163,20 +1166,20 @@ describe("shared send behaviors", () => {
const api = { sendMessage } as unknown as { const api = { sendMessage } as unknown as {
sendMessage: typeof sendMessage; sendMessage: typeof sendMessage;
}; };
await sendMessageTelegram(chatId, "reply text", { await sendMessageTelegram(chatId, "reply text", {
token: "tok", token: "tok",
api, api,
replyToMessageId: 100, replyToMessageId: 100,
}); });
expect(sendMessage).toHaveBeenCalledWith(chatId, "reply text", { expect(sendMessage).toHaveBeenCalledWith(chatId, "reply text", {
parse_mode: "HTML", parse_mode: "HTML",
reply_to_message_id: 100, reply_to_message_id: 100,
}); });
} },
},
{ {
name: "sticker send",
run: async () => {
const chatId = "123"; const chatId = "123";
const fileId = "CAACAgIAAxkBAAI...sticker_file_id"; const fileId = "CAACAgIAAxkBAAI...sticker_file_id";
const sendSticker = vi.fn().mockResolvedValue({ const sendSticker = vi.fn().mockResolvedValue({
@@ -1186,46 +1189,59 @@ describe("shared send behaviors", () => {
const api = { sendSticker } as unknown as { const api = { sendSticker } as unknown as {
sendSticker: typeof sendSticker; sendSticker: typeof sendSticker;
}; };
await sendStickerTelegram(chatId, fileId, { await sendStickerTelegram(chatId, fileId, {
token: "tok", token: "tok",
api, api,
replyToMessageId: 500, replyToMessageId: 500,
}); });
expect(sendSticker).toHaveBeenCalledWith(chatId, fileId, { expect(sendSticker).toHaveBeenCalledWith(chatId, fileId, {
reply_to_message_id: 500, reply_to_message_id: 500,
}); });
},
},
] as const;
for (const testCase of cases) {
await testCase.run();
} }
}); });
it("wraps chat-not-found with actionable context", async () => { it("wraps chat-not-found with actionable context", async () => {
const cases = [
{ {
name: "message send",
run: async () => {
const chatId = "123"; const chatId = "123";
const err = new Error("400: Bad Request: chat not found"); const err = new Error("400: Bad Request: chat not found");
const sendMessage = vi.fn().mockRejectedValue(err); const sendMessage = vi.fn().mockRejectedValue(err);
const api = { sendMessage } as unknown as { const api = { sendMessage } as unknown as {
sendMessage: typeof sendMessage; sendMessage: typeof sendMessage;
}; };
await expectChatNotFoundWithChatId( await expectChatNotFoundWithChatId(
sendMessageTelegram(chatId, "hi", { token: "tok", api }), sendMessageTelegram(chatId, "hi", { token: "tok", api }),
chatId, chatId,
); );
} },
},
{ {
name: "sticker send",
run: async () => {
const chatId = "123"; const chatId = "123";
const err = new Error("400: Bad Request: chat not found"); const err = new Error("400: Bad Request: chat not found");
const sendSticker = vi.fn().mockRejectedValue(err); const sendSticker = vi.fn().mockRejectedValue(err);
const api = { sendSticker } as unknown as { const api = { sendSticker } as unknown as {
sendSticker: typeof sendSticker; sendSticker: typeof sendSticker;
}; };
await expectChatNotFoundWithChatId( await expectChatNotFoundWithChatId(
sendStickerTelegram(chatId, "fileId123", { token: "tok", api }), sendStickerTelegram(chatId, "fileId123", { token: "tok", api }),
chatId, chatId,
); );
},
},
] as const;
for (const testCase of cases) {
await testCase.run();
} }
}); });
}); });