mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
test (telegram): assert webhook callback timeout-safe options
This commit is contained in:
@@ -9,6 +9,7 @@ const handlerSpy = vi.fn(
|
||||
);
|
||||
const setWebhookSpy = vi.fn();
|
||||
const stopSpy = vi.fn();
|
||||
const webhookCallbackSpy = vi.fn(() => handlerSpy);
|
||||
|
||||
const createTelegramBotSpy = vi.fn(() => ({
|
||||
api: { setWebhook: setWebhookSpy },
|
||||
@@ -17,7 +18,10 @@ const createTelegramBotSpy = vi.fn(() => ({
|
||||
|
||||
vi.mock("grammy", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("grammy")>();
|
||||
return { ...actual, webhookCallback: () => handlerSpy };
|
||||
return {
|
||||
...actual,
|
||||
webhookCallback: (...args: unknown[]) => webhookCallbackSpy(...args),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("./bot.js", () => ({
|
||||
@@ -27,6 +31,7 @@ vi.mock("./bot.js", () => ({
|
||||
describe("startTelegramWebhook", () => {
|
||||
it("starts server, registers webhook, and serves health", async () => {
|
||||
createTelegramBotSpy.mockClear();
|
||||
webhookCallbackSpy.mockClear();
|
||||
const abort = new AbortController();
|
||||
const cfg = { bindings: [] };
|
||||
const { server } = await startTelegramWebhook({
|
||||
@@ -52,6 +57,19 @@ describe("startTelegramWebhook", () => {
|
||||
const health = await fetch(`${url}/healthz`);
|
||||
expect(health.status).toBe(200);
|
||||
expect(setWebhookSpy).toHaveBeenCalled();
|
||||
expect(webhookCallbackSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
api: expect.objectContaining({
|
||||
setWebhook: expect.any(Function),
|
||||
}),
|
||||
}),
|
||||
"http",
|
||||
{
|
||||
secretToken: "secret",
|
||||
onTimeout: "return",
|
||||
timeoutMilliseconds: 10_000,
|
||||
},
|
||||
);
|
||||
|
||||
abort.abort();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user