test: dedupe telegram gateway mock reads

This commit is contained in:
Peter Steinberger
2026-05-13 03:47:18 +01:00
parent 1f02abe381
commit b8a27720f2
+30 -13
View File
@@ -78,6 +78,28 @@ function startTelegramAccount(
};
}
function latestMonitorOptions(): {
token?: string;
accountId?: string;
useWebhook?: boolean;
botInfo?: unknown;
} {
const calls = monitorTelegramProvider.mock.calls;
const options = calls[calls.length - 1]?.[0];
if (!options || typeof options !== "object") {
throw new Error("expected monitor Telegram options");
}
return options;
}
function sendMessageOptionsAt(index: number): Record<string, unknown> {
const options = sendMessageTelegram.mock.calls[index]?.[2];
if (!options || typeof options !== "object") {
throw new Error(`expected sendMessageTelegram options ${index}`);
}
return options;
}
afterEach(() => {
clearTelegramRuntime();
probeTelegram.mockReset();
@@ -129,12 +151,10 @@ describe("telegramPlugin gateway startup", () => {
const { task } = startTelegramAccount();
await expect(task).resolves.toBeUndefined();
const monitorOptions = monitorTelegramProvider.mock.calls.at(-1)?.[0] as
| { token?: string; accountId?: string; useWebhook?: boolean }
| undefined;
expect(monitorOptions?.token).toBe("123456:bad-token");
expect(monitorOptions?.accountId).toBe("default");
expect(monitorOptions?.useWebhook).toBe(false);
const monitorOptions = latestMonitorOptions();
expect(monitorOptions.token).toBe("123456:bad-token");
expect(monitorOptions.accountId).toBe("default");
expect(monitorOptions.useWebhook).toBe(false);
});
it("uses the getMe request guard for startup probe timeout", async () => {
@@ -191,10 +211,7 @@ describe("telegramPlugin gateway startup", () => {
const { task } = startTelegramAccount();
await expect(task).resolves.toBeUndefined();
const monitorOptions = monitorTelegramProvider.mock.calls.at(-1)?.[0] as
| { botInfo?: typeof botInfo }
| undefined;
expect(monitorOptions?.botInfo).toBe(botInfo);
expect(latestMonitorOptions().botInfo).toBe(botInfo);
});
it("honors higher per-account timeoutSeconds for startup probe", async () => {
@@ -234,7 +251,7 @@ describe("telegramPlugin outbound attachments", () => {
to: "12345",
text: "hi **boss**",
});
expect(sendMessageTelegram.mock.calls.at(0)?.[2]).not.toHaveProperty("textMode");
expect(sendMessageOptionsAt(0)).not.toHaveProperty("textMode");
await sendText({
cfg: createTelegramConfig(),
@@ -242,7 +259,7 @@ describe("telegramPlugin outbound attachments", () => {
text: "<b>hi boss</b>",
formatting: { parseMode: "HTML" },
});
expect(sendMessageTelegram.mock.calls.at(1)?.[2]?.textMode).toBe("html");
expect(sendMessageOptionsAt(1).textMode).toBe("html");
});
it("preserves explicit HTML parse mode for payload media captions", async () => {
@@ -264,6 +281,6 @@ describe("telegramPlugin outbound attachments", () => {
formatting: { parseMode: "HTML" },
});
expect(sendMessageTelegram.mock.calls.at(0)?.[2]?.textMode).toBe("html");
expect(sendMessageOptionsAt(0).textMode).toBe("html");
});
});