36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { afterEach, expect, test, vi } from "vitest";
|
|
import { setAccessToken } from "@/shared/api/request";
|
|
import { listAppUsers } from "./api";
|
|
|
|
afterEach(() => {
|
|
setAccessToken("");
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
test("listAppUsers sends country region and time filters", async () => {
|
|
vi.stubGlobal(
|
|
"fetch",
|
|
vi.fn(
|
|
async () => new Response(JSON.stringify({ code: 0, data: { items: [], page: 1, pageSize: 50, total: 0 } })),
|
|
),
|
|
);
|
|
|
|
const result = await listAppUsers({
|
|
country: "PH",
|
|
end_ms: 2000,
|
|
page: 1,
|
|
page_size: 50,
|
|
region_id: 3,
|
|
start_ms: 1000,
|
|
});
|
|
const [url, init] = vi.mocked(fetch).mock.calls[0];
|
|
|
|
expect(result.items).toEqual([]);
|
|
expect(String(url)).toContain("/api/v1/app/users?");
|
|
expect(String(url)).toContain("country=PH");
|
|
expect(String(url)).toContain("region_id=3");
|
|
expect(String(url)).toContain("start_ms=1000");
|
|
expect(String(url)).toContain("end_ms=2000");
|
|
expect(init?.method).toBe("GET");
|
|
});
|