test: tighten zalo api request assertions

This commit is contained in:
Shakker
2026-05-08 19:13:38 +01:00
parent c8d7db55ad
commit b332b7dff7

View File

@@ -18,8 +18,12 @@ async function expectPostJsonRequest(run: (token: string, fetcher: ZaloFetch) =>
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" });
expect(init).toBeDefined();
if (!init) {
throw new Error("expected Zalo request init");
}
expect(init.method).toBe("POST");
expect(init.headers).toEqual({ "Content-Type": "application/json" });
}
describe("Zalo API request methods", () => {
@@ -67,7 +71,15 @@ describe("Zalo API request methods", () => {
await rejected;
const [, init] = fetcher.mock.calls[0] ?? [];
expect(init?.signal?.aborted).toBe(true);
expect(init).toBeDefined();
if (!init) {
throw new Error("expected Zalo chat action request init");
}
expect(init.signal).toBeDefined();
if (!init.signal) {
throw new Error("expected Zalo chat action abort signal");
}
expect(init.signal.aborted).toBe(true);
} finally {
vi.useRealTimers();
}