40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
import { afterEach, expect, test, vi } from "vitest";
|
|
import { setAccessToken } from "@/shared/api/request";
|
|
import { createCoinAdjustment, listCoinAdjustments, lookupCoinAdjustmentTarget } from "./api";
|
|
|
|
afterEach(() => {
|
|
setAccessToken("");
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
test("coin adjustment APIs use generated admin paths", async () => {
|
|
vi.stubGlobal(
|
|
"fetch",
|
|
vi.fn(
|
|
async () => new Response(JSON.stringify({ code: 0, data: { items: [], page: 1, pageSize: 20, total: 0 } })),
|
|
),
|
|
);
|
|
|
|
await listCoinAdjustments({ page: 1, page_size: 20, user_keyword: "1001" });
|
|
await lookupCoinAdjustmentTarget("1001");
|
|
await createCoinAdjustment({
|
|
amount: 500,
|
|
commandId: "coin-adjustment-test",
|
|
reason: "运营发放",
|
|
targetUserId: "1001",
|
|
});
|
|
|
|
const [listUrl, listInit] = vi.mocked(fetch).mock.calls[0];
|
|
const [lookupUrl, lookupInit] = vi.mocked(fetch).mock.calls[1];
|
|
const [createUrl, createInit] = vi.mocked(fetch).mock.calls[2];
|
|
|
|
expect(String(listUrl)).toContain("/api/v1/admin/operations/coin-adjustments?");
|
|
expect(String(listUrl)).toContain("user_keyword=1001");
|
|
expect(listInit?.method).toBe("GET");
|
|
expect(String(lookupUrl)).toContain("/api/v1/admin/operations/coin-adjustments/target?");
|
|
expect(String(lookupUrl)).toContain("user_id=1001");
|
|
expect(lookupInit?.method).toBe("GET");
|
|
expect(String(createUrl)).toContain("/api/v1/admin/operations/coin-adjustments");
|
|
expect(createInit?.method).toBe("POST");
|
|
});
|