



























@@ -78,6 +78,28 @@ function startTelegramAccount(
7878};
7979}
808081+function latestMonitorOptions(): {
82+token?: string;
83+accountId?: string;
84+useWebhook?: boolean;
85+botInfo?: unknown;
86+} {
87+const calls = monitorTelegramProvider.mock.calls;
88+const options = calls[calls.length - 1]?.[0];
89+if (!options || typeof options !== "object") {
90+throw new Error("expected monitor Telegram options");
91+}
92+return options;
93+}
94+95+function sendMessageOptionsAt(index: number): Record<string, unknown> {
96+const options = sendMessageTelegram.mock.calls[index]?.[2];
97+if (!options || typeof options !== "object") {
98+throw new Error(`expected sendMessageTelegram options ${index}`);
99+}
100+return options;
101+}
102+81103afterEach(() => {
82104clearTelegramRuntime();
83105probeTelegram.mockReset();
@@ -129,12 +151,10 @@ describe("telegramPlugin gateway startup", () => {
129151const { task } = startTelegramAccount();
130152131153await expect(task).resolves.toBeUndefined();
132-const monitorOptions = monitorTelegramProvider.mock.calls.at(-1)?.[0] as
133-| { token?: string; accountId?: string; useWebhook?: boolean }
134-| undefined;
135-expect(monitorOptions?.token).toBe("123456:bad-token");
136-expect(monitorOptions?.accountId).toBe("default");
137-expect(monitorOptions?.useWebhook).toBe(false);
154+const monitorOptions = latestMonitorOptions();
155+expect(monitorOptions.token).toBe("123456:bad-token");
156+expect(monitorOptions.accountId).toBe("default");
157+expect(monitorOptions.useWebhook).toBe(false);
138158});
139159140160it("uses the getMe request guard for startup probe timeout", async () => {
@@ -191,10 +211,7 @@ describe("telegramPlugin gateway startup", () => {
191211const { task } = startTelegramAccount();
192212193213await expect(task).resolves.toBeUndefined();
194-const monitorOptions = monitorTelegramProvider.mock.calls.at(-1)?.[0] as
195-| { botInfo?: typeof botInfo }
196-| undefined;
197-expect(monitorOptions?.botInfo).toBe(botInfo);
214+expect(latestMonitorOptions().botInfo).toBe(botInfo);
198215});
199216200217it("honors higher per-account timeoutSeconds for startup probe", async () => {
@@ -234,15 +251,15 @@ describe("telegramPlugin outbound attachments", () => {
234251to: "12345",
235252text: "hi **boss**",
236253});
237-expect(sendMessageTelegram.mock.calls.at(0)?.[2]).not.toHaveProperty("textMode");
254+expect(sendMessageOptionsAt(0)).not.toHaveProperty("textMode");
238255239256await sendText({
240257cfg: createTelegramConfig(),
241258to: "12345",
242259text: "<b>hi boss</b>",
243260formatting: { parseMode: "HTML" },
244261});
245-expect(sendMessageTelegram.mock.calls.at(1)?.[2]?.textMode).toBe("html");
262+expect(sendMessageOptionsAt(1).textMode).toBe("html");
246263});
247264248265it("preserves explicit HTML parse mode for payload media captions", async () => {
@@ -264,6 +281,6 @@ describe("telegramPlugin outbound attachments", () => {
264281formatting: { parseMode: "HTML" },
265282});
266283267-expect(sendMessageTelegram.mock.calls.at(0)?.[2]?.textMode).toBe("html");
284+expect(sendMessageOptionsAt(0).textMode).toBe("html");
268285});
269286});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。