test(admin): 提现审核 trade api 单测(6)——第二财务门回归基线

补 game-admin 另一关键门(财务:提现 通过/驳回):
- src/api/wanxiang/trade.spec.ts(6 测):mock 兜底不打真接口;真实模式 GET /trade/withdraw/page + POST /trade/withdraw/audit url/method/data 贴 frozen trade.yaml;**决策码 1通过/2驳回 钉死契约 WithdrawAuditReqVO.decision**(财务误判=资损)
- 无新依赖(复用已立 vitest 基建)

验证:`npm test` 13/13 绿(review 7 + trade 6)。game-admin 两关键门(审核台 link②/提现财务门)均有决策映射回归测。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
lili 2026-06-17 17:04:34 -07:00
parent 349cd8292c
commit 0a363ec3aa

View File

@ -0,0 +1,62 @@
/**
* trade.spec.ts · api (财务门:提现 /)
* : mock ; url/method/data frozen trade.yaml;
* 1/2 WithdrawAuditReqVO.decision(=,) `npm test`
*/
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
vi.mock('@/config/axios', () => ({ default: { get: vi.fn(), post: vi.fn() } }))
import request from '@/config/axios'
import { getWithdrawPage, auditWithdraw, WithdrawAuditDecisionEnum } from './trade'
const req = request as unknown as { get: ReturnType<typeof vi.fn>; post: ReturnType<typeof vi.fn> }
describe('wanxiang/trade 提现审核 api财务门', () => {
beforeEach(() => vi.clearAllMocks())
afterEach(() => vi.unstubAllEnvs())
describe('mock 兜底(VITE_APP_WANXIANG_MOCK=true)', () => {
beforeEach(() => vi.stubEnv('VITE_APP_WANXIANG_MOCK', 'true'))
it('getWithdrawPage → 本地 mock 分页{list,total},不打真实接口', async () => {
const r = await getWithdrawPage({ pageNo: 1, pageSize: 10 })
expect(r.total).toBeGreaterThan(0)
expect(Array.isArray(r.list)).toBe(true)
expect(req.get).not.toHaveBeenCalled()
})
it('auditWithdraw → mock 返 true,不打真实接口', async () => {
const r = await auditWithdraw({ id: 1, decision: WithdrawAuditDecisionEnum.PASS })
expect(r).toBe(true)
expect(req.post).not.toHaveBeenCalled()
})
})
describe('真实模式(VITE_APP_WANXIANG_MOCK!=true)', () => {
beforeEach(() => vi.stubEnv('VITE_APP_WANXIANG_MOCK', 'false'))
it('getWithdrawPage → GET /trade/withdraw/page + params', async () => {
req.get.mockResolvedValue({ list: [], total: 0 })
await getWithdrawPage({ pageNo: 1, pageSize: 10, status: 0 })
expect(req.get).toHaveBeenCalledWith({ url: '/trade/withdraw/page', params: { pageNo: 1, pageSize: 10, status: 0 } })
})
it('auditWithdraw(通过) → POST /trade/withdraw/audit {decision:1}', async () => {
req.post.mockResolvedValue(true)
await auditWithdraw({ id: 7001, decision: WithdrawAuditDecisionEnum.PASS })
expect(req.post).toHaveBeenCalledWith({ url: '/trade/withdraw/audit', data: { id: 7001, decision: 1 } })
})
it('auditWithdraw(驳回) → POST {decision:2} + rejectReason', async () => {
req.post.mockResolvedValue(true)
await auditWithdraw({ id: 7002, decision: WithdrawAuditDecisionEnum.REJECT, rejectReason: '账户信息不符' })
expect(req.post).toHaveBeenCalledWith({ url: '/trade/withdraw/audit', data: { id: 7002, decision: 2, rejectReason: '账户信息不符' } })
})
})
it('提现决策枚举钉死契约 WithdrawAuditReqVO.decision(1通过/2驳回)', () => {
expect(WithdrawAuditDecisionEnum.PASS).toBe(1)
expect(WithdrawAuditDecisionEnum.REJECT).toBe(2)
})
})