1f20198f23
The function performed client-side filtering on top of listOrders but was never called by any page. listPlayersByShop is kept as-is since the backend has no dedicated shop players endpoint.
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { createPaidOrder } from "@/lib/api/orders"
|
|
import { describe, expect, it, vi } from "vitest"
|
|
|
|
describe("lib/api/orders", () => {
|
|
it("returns { decision: { ok:false, error:{code,msg} } } when unauthenticated", async () => {
|
|
vi.stubGlobal(
|
|
"fetch",
|
|
vi.fn(
|
|
async () =>
|
|
new Response(JSON.stringify({ code: 401, msg: "请先登录" }), {
|
|
status: 401,
|
|
headers: { "Content-Type": "application/json" },
|
|
}),
|
|
),
|
|
)
|
|
|
|
try {
|
|
const res = await createPaidOrder({
|
|
playerId: "1005",
|
|
serviceId: "5001",
|
|
quantity: 1,
|
|
})
|
|
|
|
expect(fetch).toHaveBeenCalledWith(
|
|
expect.any(String),
|
|
expect.objectContaining({
|
|
body: JSON.stringify({ playerId: 1005, serviceId: 5001, quantity: 1 }),
|
|
}),
|
|
)
|
|
|
|
expect(res).toEqual({
|
|
decision: {
|
|
ok: false,
|
|
error: { code: 401, msg: "请先登录" },
|
|
},
|
|
})
|
|
} finally {
|
|
vi.unstubAllGlobals()
|
|
}
|
|
})
|
|
})
|