This commit is contained in:
2026-08-19 09:14:35 +08:00
parent c188482c24
commit 80cfca5056
36 changed files with 854 additions and 1044 deletions
+22 -1
View File
@@ -2,13 +2,16 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ApiResponseError, http } from '@/shared/api/http'
import {
adjustPublishedInboundFee,
confirmInboundFee,
createFeeActionIdempotencyKey,
createFeeAdjustmentIdempotencyKey,
getLatestInboundFee,
sendInboundFee,
} from './api'
vi.mock('@/shared/api/http', async () => {
const actual = await vi.importActual<typeof import('@/shared/api/http')>('@/shared/api/http')
return { ...actual, http: { get: vi.fn(), put: vi.fn() } }
return { ...actual, http: { get: vi.fn(), post: vi.fn(), put: vi.fn() } }
})
const snapshot = {
@@ -50,6 +53,22 @@ describe('inbound fee API', () => {
)
})
it('confirms and sends a calculated fee with independent idempotency keys', async () => {
vi.mocked(http.post)
.mockResolvedValueOnce({ code: '200', message: 'success', data: { ...snapshot, feeStatus: 'CONFIRMED' } })
.mockResolvedValueOnce({ code: '200', message: 'success', data: snapshot })
await expect(confirmInboundFee('10001', '88', 'fee-confirm-1')).resolves.toMatchObject({ feeStatus: 'CONFIRMED' })
await expect(sendInboundFee('10001', '88', 'fee-send-1')).resolves.toMatchObject({ feeStatus: 'SENT' })
expect(http.post).toHaveBeenNthCalledWith(1, '/platform/v1/inbounds/88/fees/confirm', undefined, {
params: { tenantId: '10001' }, headers: { 'Idempotency-Key': 'fee-confirm-1' },
})
expect(http.post).toHaveBeenNthCalledWith(2, '/platform/v1/inbounds/88/fees/send', undefined, {
params: { tenantId: '10001' }, headers: { 'Idempotency-Key': 'fee-send-1' },
})
})
it('preserves backend conflict metadata for stale-version recovery', async () => {
vi.mocked(http.put).mockResolvedValue({
code: 'A0409', message: '费用已被其他操作员修改,请刷新后重试', data: null,
@@ -73,5 +92,7 @@ describe('inbound fee API', () => {
expect(first).toMatch(/^fee-adjust-/)
expect(first.length).toBeLessThanOrEqual(128)
expect(second).not.toBe(first)
expect(createFeeActionIdempotencyKey('confirm')).toMatch(/^fee-confirm-/)
expect(createFeeActionIdempotencyKey('send')).toMatch(/^fee-send-/)
})
})