mirror of https://github.com/openclaw/openclaw.git
test: share zalo api request assertion
This commit is contained in:
parent
ba34266e89
commit
4ec0a120df
|
|
@ -1,31 +1,26 @@
|
|||
import { describe, expect, it, vi } from "vitest";
|
||||
import { deleteWebhook, getWebhookInfo, sendChatAction, type ZaloFetch } from "./api.js";
|
||||
|
||||
function createOkFetcher() {
|
||||
return vi.fn<ZaloFetch>(async () => new Response(JSON.stringify({ ok: true, result: {} })));
|
||||
}
|
||||
|
||||
async function expectPostJsonRequest(run: (token: string, fetcher: ZaloFetch) => Promise<unknown>) {
|
||||
const fetcher = createOkFetcher();
|
||||
await run("test-token", fetcher);
|
||||
expect(fetcher).toHaveBeenCalledTimes(1);
|
||||
const [, init] = fetcher.mock.calls[0] ?? [];
|
||||
expect(init?.method).toBe("POST");
|
||||
expect(init?.headers).toEqual({ "Content-Type": "application/json" });
|
||||
}
|
||||
|
||||
describe("Zalo API request methods", () => {
|
||||
it("uses POST for getWebhookInfo", async () => {
|
||||
const fetcher = vi.fn<ZaloFetch>(
|
||||
async () => new Response(JSON.stringify({ ok: true, result: {} })),
|
||||
);
|
||||
|
||||
await getWebhookInfo("test-token", fetcher);
|
||||
|
||||
expect(fetcher).toHaveBeenCalledTimes(1);
|
||||
const [, init] = fetcher.mock.calls[0] ?? [];
|
||||
expect(init?.method).toBe("POST");
|
||||
expect(init?.headers).toEqual({ "Content-Type": "application/json" });
|
||||
await expectPostJsonRequest(getWebhookInfo);
|
||||
});
|
||||
|
||||
it("keeps POST for deleteWebhook", async () => {
|
||||
const fetcher = vi.fn<ZaloFetch>(
|
||||
async () => new Response(JSON.stringify({ ok: true, result: {} })),
|
||||
);
|
||||
|
||||
await deleteWebhook("test-token", fetcher);
|
||||
|
||||
expect(fetcher).toHaveBeenCalledTimes(1);
|
||||
const [, init] = fetcher.mock.calls[0] ?? [];
|
||||
expect(init?.method).toBe("POST");
|
||||
expect(init?.headers).toEqual({ "Content-Type": "application/json" });
|
||||
await expectPostJsonRequest(deleteWebhook);
|
||||
});
|
||||
|
||||
it("aborts sendChatAction when the typing timeout elapses", async () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue