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:
parent
349cd8292c
commit
0a363ec3aa
62
game-admin/src/api/wanxiang/trade.spec.ts
Normal file
62
game-admin/src/api/wanxiang/trade.spec.ts
Normal 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)
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user