From 0a363ec3aacdfc837ae7765f6e6c3c33ad81ffc5 Mon Sep 17 00:00:00 2001 From: lili Date: Wed, 17 Jun 2026 17:04:34 -0700 Subject: [PATCH] =?UTF-8?q?test(admin):=20=E6=8F=90=E7=8E=B0=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8=20trade=20api=20=E5=8D=95=E6=B5=8B(6)=E2=80=94?= =?UTF-8?q?=E2=80=94=E7=AC=AC=E4=BA=8C=E8=B4=A2=E5=8A=A1=E9=97=A8=E5=9B=9E?= =?UTF-8?q?=E5=BD=92=E5=9F=BA=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补 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 --- game-admin/src/api/wanxiang/trade.spec.ts | 62 +++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 game-admin/src/api/wanxiang/trade.spec.ts diff --git a/game-admin/src/api/wanxiang/trade.spec.ts b/game-admin/src/api/wanxiang/trade.spec.ts new file mode 100644 index 00000000..2ebb164d --- /dev/null +++ b/game-admin/src/api/wanxiang/trade.spec.ts @@ -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; post: ReturnType } + +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) + }) +})