mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-08 08:42:54 +00:00
27 lines
1003 B
TypeScript
27 lines
1003 B
TypeScript
import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { requestMatrixJson, type MatrixQaFetchLike } from "./request.js";
|
|
|
|
describe("requestMatrixJson", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("caps oversized request timeouts before creating the abort signal", async () => {
|
|
const signal = AbortSignal.abort();
|
|
const timeoutSpy = vi.spyOn(AbortSignal, "timeout").mockReturnValue(signal);
|
|
const fetchImpl = vi.fn<MatrixQaFetchLike>(async () => Response.json({ ok: true }));
|
|
|
|
await requestMatrixJson({
|
|
baseUrl: "https://matrix.example.test",
|
|
endpoint: "/_matrix/client/v3/account/whoami",
|
|
fetchImpl,
|
|
method: "GET",
|
|
timeoutMs: MAX_TIMER_TIMEOUT_MS + 1_000_000,
|
|
});
|
|
|
|
expect(timeoutSpy).toHaveBeenCalledWith(MAX_TIMER_TIMEOUT_MS);
|
|
expect(fetchImpl).toHaveBeenCalledWith(expect.any(URL), expect.objectContaining({ signal }));
|
|
});
|
|
});
|