8862887baa
新增充值订单查询、通用用户详情、钱包冻结与部分退款操作 接入微信V3退款申请、回调、主动查单、交易账单对账与安全诊断 新增退款占用、权益追回、异常欠账和消费限制事务 补齐Native支付SSE自动收口及退款编号与部分退款校验 同步SpacetimeDB schema、生成绑定、测试与项目文档
92 lines
2.6 KiB
TypeScript
92 lines
2.6 KiB
TypeScript
import {afterEach, expect, test, vi} from 'vitest';
|
|
|
|
import {
|
|
executeAdminRechargeRefund,
|
|
getAdminUserDetail,
|
|
listAdminRechargeOrders,
|
|
} from './adminApiClient';
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
test('充值订单查询按后台契约序列化筛选参数', async () => {
|
|
const fetchMock = vi.fn().mockResolvedValue(
|
|
new Response(JSON.stringify({entries: []}), {
|
|
status: 200,
|
|
headers: {'content-type': 'application/json'},
|
|
}),
|
|
);
|
|
vi.stubGlobal('fetch', fetchMock);
|
|
|
|
await listAdminRechargeOrders('token-1', {
|
|
orderId: 'order 1',
|
|
userId: 'user-1',
|
|
providerTransactionId: 'wx-1',
|
|
paymentChannel: 'wechat_native',
|
|
status: 'paid',
|
|
createdAfter: '2026-07-01T00:00:00.000Z',
|
|
createdBefore: '2026-07-13T23:59:00.000Z',
|
|
limit: 50,
|
|
});
|
|
|
|
const requestUrl = String(fetchMock.mock.calls[0]?.[0]);
|
|
const parsed = new URL(requestUrl, 'http://admin.local');
|
|
expect(parsed.pathname).toBe('/admin/api/profile/recharge-orders');
|
|
expect(Object.fromEntries(parsed.searchParams)).toEqual({
|
|
orderId: 'order 1',
|
|
providerTransactionId: 'wx-1',
|
|
userId: 'user-1',
|
|
paymentChannel: 'wechat_native',
|
|
status: 'paid',
|
|
createdAfter: '2026-07-01T00:00:00.000Z',
|
|
createdBefore: '2026-07-13T23:59:00.000Z',
|
|
limit: '50',
|
|
});
|
|
});
|
|
|
|
test('用户详情只发送实际提供的用户定位字段', async () => {
|
|
const fetchMock = vi.fn().mockResolvedValue(
|
|
new Response(JSON.stringify({userId: 'user-1'}), {status: 200}),
|
|
);
|
|
vi.stubGlobal('fetch', fetchMock);
|
|
|
|
await getAdminUserDetail('token-1', {publicUserCode: 'TN1001'});
|
|
|
|
const requestUrl = String(fetchMock.mock.calls[0]?.[0]);
|
|
const parsed = new URL(requestUrl, 'http://admin.local');
|
|
expect(parsed.pathname).toBe('/admin/api/profile/users/detail');
|
|
expect(Object.fromEntries(parsed.searchParams)).toEqual({
|
|
publicUserCode: 'TN1001',
|
|
});
|
|
});
|
|
|
|
test('退款执行使用独立 execute 管理员路由', async () => {
|
|
const fetchMock = vi.fn().mockResolvedValue(
|
|
new Response(JSON.stringify({outRefundNo: 'refund-1'}), {status: 200}),
|
|
);
|
|
vi.stubGlobal('fetch', fetchMock);
|
|
|
|
await executeAdminRechargeRefund('token-1', {
|
|
orderId: 'order-1',
|
|
refundAmountCents: 300,
|
|
requestId: 'request-1',
|
|
reason: '用户申请',
|
|
});
|
|
|
|
expect(String(fetchMock.mock.calls[0]?.[0])).toBe(
|
|
'/admin/api/profile/recharge-refunds/execute',
|
|
);
|
|
expect(fetchMock.mock.calls[0]?.[1]).toEqual(
|
|
expect.objectContaining({
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
orderId: 'order-1',
|
|
refundAmountCents: 300,
|
|
requestId: 'request-1',
|
|
reason: '用户申请',
|
|
}),
|
|
}),
|
|
);
|
|
});
|