This commit is contained in:
2026-08-12 16:31:46 +08:00
parent c15d21b986
commit d8bbfe05f3
40 changed files with 1541 additions and 248 deletions
@@ -0,0 +1,30 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import {
adjustInboundFeeDetail, createInboundFeeDetail, deleteInboundFeeDetail, listInboundFeeDetails,
reviewInboundFeeDetail, updateInboundFeeDetail, voidInboundFeeDetail, type SaveInboundFeeDetailRequest,
} from './inboundFeeDetails'
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(), post: vi.fn(), put: vi.fn(), delete: vi.fn() } }
})
describe('inbound fee-detail API', () => {
beforeEach(() => vi.clearAllMocks())
it('maps the complete write contract and optimistic version', async () => {
const payload: SaveInboundFeeDetailRequest = { feeItemId: '31', direction: 'PAYABLE', businessDate: '2026-08-12', unitPrice: 12.5, currency: 'CNY', amount: 125, settlementIncluded: true, partnerId: '41', partnerName: '测试供应商', remark: '验收' }
vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: [] })
vi.mocked(http.post).mockResolvedValue({ code: '200', message: 'success', data: null })
vi.mocked(http.put).mockResolvedValue({ code: '200', message: 'success', data: payload })
vi.mocked(http.delete).mockResolvedValue({ code: '200', message: 'success', data: null })
await listInboundFeeDetails('100', '88'); await createInboundFeeDetail('100', '88', payload)
await updateInboundFeeDetail('100', '88', '11', payload); await reviewInboundFeeDetail('100', '88', '11', 'approve')
await reviewInboundFeeDetail('100', '88', '11', 'reject', '金额有误'); await adjustInboundFeeDetail('100', '88', '11', 3, payload)
await voidInboundFeeDetail('100', '88', '11', 3); await deleteInboundFeeDetail('100', '88', '11')
expect(http.get).toHaveBeenCalledWith('/platform/v1/inbounds/88/fee-details', { params: { accountId: '100' } })
expect(http.post).toHaveBeenCalledWith('/platform/v1/inbounds/88/fee-details/11/adjust', payload, { params: { accountId: '100', expectedSourceVersion: 3 } })
expect(http.post).toHaveBeenCalledWith('/platform/v1/inbounds/88/fee-details/11/void', { expectedSourceVersion: 3 }, { params: { accountId: '100' } })
expect(http.delete).toHaveBeenCalledWith('/platform/v1/inbounds/88/fee-details/11', { params: { accountId: '100' } })
})
})
@@ -0,0 +1,105 @@
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
export type InboundFeeDirection = 'RECEIVABLE' | 'PAYABLE'
export type InboundFeeReviewStatus = 'PENDING' | 'APPROVED' | 'REJECTED'
export interface InboundFeeDetail {
id: string | number
inboundId: string | number
feeItemId: string | number
sourceType: string
sourceFeeVersion: number
inboundCode: string | null
direction: InboundFeeDirection
partnerId: string | number | null
partnerName: string | null
businessDate: string
customerName: string | null
feeTypeNameSnapshot: string
unitPrice: number
currency: string
amount: number
remark: string | null
reviewStatus: InboundFeeReviewStatus
reviewReason: string | null
reviewerName: string | null
reviewedAt: string | null
publicationStatus: string
settlementIncluded: boolean
}
export interface SaveInboundFeeDetailRequest {
feeItemId: string | number
direction: InboundFeeDirection
businessDate: string
unitPrice: number
currency: string
amount: number
settlementIncluded: boolean
partnerId: string | number | null
partnerName: string | null
remark: string | null
}
export interface InboundFeeItemOption {
id: string | number
feeTypeName: string
warehousePayable: boolean
warehouseReceivable: boolean
}
export interface InboundFeePartnerOption { id: string | number; partnerName: string }
function basePath(inboundId: string) { return `/platform/v1/inbounds/${encodeURIComponent(inboundId)}/fee-details` }
const config = (accountId: string) => ({ params: { accountId } })
export async function listInboundFeeDetails(accountId: string, inboundId: string) {
const response = await http.get<unknown, ApiEnvelope<InboundFeeDetail[]>>(basePath(inboundId), config(accountId))
return unwrapApiResponse(response) || []
}
export async function createInboundFeeDetail(accountId: string, inboundId: string, payload: SaveInboundFeeDetailRequest) {
return unwrapApiResponse(await http.post<unknown, ApiEnvelope<InboundFeeDetail>>(basePath(inboundId), payload, config(accountId)))
}
export async function updateInboundFeeDetail(accountId: string, inboundId: string, detailId: string, payload: SaveInboundFeeDetailRequest) {
return unwrapApiResponse(await http.put<unknown, ApiEnvelope<InboundFeeDetail>>(`${basePath(inboundId)}/${encodeURIComponent(detailId)}`, payload, config(accountId)))
}
export async function deleteInboundFeeDetail(accountId: string, inboundId: string, detailId: string) {
return unwrapApiResponse(await http.delete<unknown, ApiEnvelope<null>>(`${basePath(inboundId)}/${encodeURIComponent(detailId)}`, config(accountId)))
}
export async function reviewInboundFeeDetail(accountId: string, inboundId: string, detailId: string, action: 'approve' | 'reject', reason?: string) {
return unwrapApiResponse(await http.post<unknown, ApiEnvelope<null>>(
`${basePath(inboundId)}/${encodeURIComponent(detailId)}/${action}`,
action === 'reject' ? { reason } : undefined, config(accountId),
))
}
export async function adjustInboundFeeDetail(accountId: string, inboundId: string, detailId: string, expectedSourceVersion: number, payload: SaveInboundFeeDetailRequest) {
return unwrapApiResponse(await http.post<unknown, ApiEnvelope<InboundFeeDetail>>(
`${basePath(inboundId)}/${encodeURIComponent(detailId)}/adjust`, payload,
{ params: { accountId, expectedSourceVersion } },
))
}
export async function voidInboundFeeDetail(accountId: string, inboundId: string, detailId: string, expectedSourceVersion: number) {
return unwrapApiResponse(await http.post<unknown, ApiEnvelope<null>>(
`${basePath(inboundId)}/${encodeURIComponent(detailId)}/void`, { expectedSourceVersion }, config(accountId),
))
}
export async function listInboundFeeItemOptions() {
const response = await http.get<unknown, ApiEnvelope<{ records: InboundFeeItemOption[] }>>(
'/platform/v1/fee-items', { params: { status: 'ACTIVE', page: 1, size: 200 } },
)
return unwrapApiResponse(response).records || []
}
export async function listInboundFeePartnerOptions() {
const response = await http.get<unknown, ApiEnvelope<{ records: InboundFeePartnerOption[] }>>(
'/platform/v1/partners', { params: { status: 'ACTIVE', page: 1, size: 200 } },
)
return unwrapApiResponse(response).records || []
}