mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:30:43 +00:00
test: cover Telegram webhook timeout reply continuation
This commit is contained in:
@@ -537,6 +537,60 @@ describe("startTelegramWebhook", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("returns after grammY timeout reply while webhook work continues", async () => {
|
||||
let finishWork: (() => void) | undefined;
|
||||
let workFinished = false;
|
||||
webhookCallbackSpy.mockImplementationOnce(
|
||||
() =>
|
||||
vi.fn(
|
||||
async (
|
||||
update: unknown,
|
||||
reply: (json: string) => Promise<void>,
|
||||
_secretHeader: string | undefined,
|
||||
_unauthorized: () => Promise<void>,
|
||||
) => {
|
||||
expect(update).toEqual({ update_id: 2, message: { text: "slow" } });
|
||||
await reply("{}");
|
||||
await new Promise<void>((resolve) => {
|
||||
finishWork = resolve;
|
||||
});
|
||||
workFinished = true;
|
||||
},
|
||||
) as unknown as typeof handlerSpy,
|
||||
);
|
||||
|
||||
await withStartedWebhook(
|
||||
{
|
||||
secret: TELEGRAM_SECRET,
|
||||
path: TELEGRAM_WEBHOOK_PATH,
|
||||
},
|
||||
async ({ port }) => {
|
||||
expect(webhookCallbackSpy).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
"callback",
|
||||
expect.objectContaining({
|
||||
onTimeout: "return",
|
||||
timeoutMilliseconds: 5_000,
|
||||
}),
|
||||
);
|
||||
const response = await postWebhookJson({
|
||||
url: webhookUrl(port, TELEGRAM_WEBHOOK_PATH),
|
||||
payload: JSON.stringify({ update_id: 2, message: { text: "slow" } }),
|
||||
secret: TELEGRAM_SECRET,
|
||||
timeoutMs: 1_000,
|
||||
});
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(await response.text()).toBe("{}");
|
||||
expect(workFinished).toBe(false);
|
||||
|
||||
finishWork?.();
|
||||
await sleep(WEBHOOK_TEST_YIELD_MS);
|
||||
expect(workFinished).toBe(true);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects unauthenticated requests before reading the request body", async () => {
|
||||
handlerSpy.mockClear();
|
||||
await withStartedWebhook(
|
||||
|
||||
Reference in New Issue
Block a user