test(telegram): table-drive sticker and forum-topic cases

This commit is contained in:
Peter Steinberger
2026-02-21 23:04:40 +00:00
parent b1c50cc5c0
commit d5cc357737

View File

@@ -1077,26 +1077,46 @@ describe("sendStickerTelegram", () => {
botCtorSpy.mockReset(); botCtorSpy.mockReset();
}); });
it("sends a sticker by file_id", async () => { const positiveSendCases = [
const chatId = "123"; {
const fileId = "CAACAgIAAxkBAAI...sticker_file_id"; name: "sends a sticker by file_id",
const sendSticker = vi.fn().mockResolvedValue({ fileId: "CAACAgIAAxkBAAI...sticker_file_id",
message_id: 100, expectedFileId: "CAACAgIAAxkBAAI...sticker_file_id",
chat: { id: chatId }, expectedMessageId: 100,
}); assertResult: true,
const api = { sendSticker } as unknown as { },
sendSticker: typeof sendSticker; {
}; name: "trims whitespace from fileId",
fileId: " fileId123 ",
expectedFileId: "fileId123",
expectedMessageId: 106,
assertResult: false,
},
] as const;
const res = await sendStickerTelegram(chatId, fileId, { for (const testCase of positiveSendCases) {
token: "tok", it(testCase.name, async () => {
api, const chatId = "123";
}); const sendSticker = vi.fn().mockResolvedValue({
message_id: testCase.expectedMessageId,
chat: { id: chatId },
});
const api = { sendSticker } as unknown as {
sendSticker: typeof sendSticker;
};
expect(sendSticker).toHaveBeenCalledWith(chatId, fileId, undefined); const res = await sendStickerTelegram(chatId, testCase.fileId, {
expect(res.messageId).toBe("100"); token: "tok",
expect(res.chatId).toBe(chatId); api,
}); });
expect(sendSticker).toHaveBeenCalledWith(chatId, testCase.expectedFileId, undefined);
if (testCase.assertResult) {
expect(res.messageId).toBe(String(testCase.expectedMessageId));
expect(res.chatId).toBe(chatId);
}
});
}
it("throws error when fileId is blank", async () => { it("throws error when fileId is blank", async () => {
for (const fileId of ["", " "]) { for (const fileId of ["", " "]) {
@@ -1132,24 +1152,6 @@ describe("sendStickerTelegram", () => {
expect(sendSticker).toHaveBeenNthCalledWith(2, chatId, "fileId123", undefined); expect(sendSticker).toHaveBeenNthCalledWith(2, chatId, "fileId123", undefined);
expect(res.messageId).toBe("109"); expect(res.messageId).toBe("109");
}); });
it("trims whitespace from fileId", async () => {
const chatId = "123";
const sendSticker = vi.fn().mockResolvedValue({
message_id: 106,
chat: { id: chatId },
});
const api = { sendSticker } as unknown as {
sendSticker: typeof sendSticker;
};
await sendStickerTelegram(chatId, " fileId123 ", {
token: "tok",
api,
});
expect(sendSticker).toHaveBeenCalledWith(chatId, "fileId123", undefined);
});
}); });
describe("shared send behaviors", () => { describe("shared send behaviors", () => {
@@ -1438,43 +1440,54 @@ describe("sendPollTelegram", () => {
}); });
describe("createForumTopicTelegram", () => { describe("createForumTopicTelegram", () => {
it("uses base chat id when target includes topic suffix", async () => { const cases = [
const createForumTopic = vi.fn().mockResolvedValue({ {
message_thread_id: 272, name: "uses base chat id when target includes topic suffix",
name: "Build Updates", target: "telegram:group:-1001234567890:topic:271",
}); title: "x",
const api = { createForumTopic } as unknown as Bot["api"]; response: { message_thread_id: 272, name: "Build Updates" },
expectedCall: ["-1001234567890", "x", undefined] as const,
expectedResult: {
topicId: 272,
name: "Build Updates",
chatId: "-1001234567890",
},
},
{
name: "forwards optional icon fields",
target: "-1001234567890",
title: "Roadmap",
response: { message_thread_id: 300, name: "Roadmap" },
options: {
iconColor: 0x6fb9f0,
iconCustomEmojiId: " 1234567890 ",
},
expectedCall: [
"-1001234567890",
"Roadmap",
{ icon_color: 0x6fb9f0, icon_custom_emoji_id: "1234567890" },
] as const,
expectedResult: {
topicId: 300,
name: "Roadmap",
chatId: "-1001234567890",
},
},
] as const;
const result = await createForumTopicTelegram("telegram:group:-1001234567890:topic:271", "x", { for (const testCase of cases) {
token: "tok", it(testCase.name, async () => {
api, const createForumTopic = vi.fn().mockResolvedValue(testCase.response);
}); const api = { createForumTopic } as unknown as Bot["api"];
expect(createForumTopic).toHaveBeenCalledWith("-1001234567890", "x", undefined); const result = await createForumTopicTelegram(testCase.target, testCase.title, {
expect(result).toEqual({ token: "tok",
topicId: 272, api,
name: "Build Updates", ...testCase.options,
chatId: "-1001234567890", });
});
});
it("forwards optional icon fields", async () => { expect(createForumTopic).toHaveBeenCalledWith(...testCase.expectedCall);
const createForumTopic = vi.fn().mockResolvedValue({ expect(result).toEqual(testCase.expectedResult);
message_thread_id: 300,
name: "Roadmap",
}); });
const api = { createForumTopic } as unknown as Bot["api"]; }
await createForumTopicTelegram("-1001234567890", "Roadmap", {
token: "tok",
api,
iconColor: 0x6fb9f0,
iconCustomEmojiId: " 1234567890 ",
});
expect(createForumTopic).toHaveBeenCalledWith("-1001234567890", "Roadmap", {
icon_color: 0x6fb9f0,
icon_custom_emoji_id: "1234567890",
});
});
}); });