This commit is contained in:
2026-08-10 15:36:53 +08:00
parent 5d97c7517a
commit f6556c57b5
54 changed files with 4107 additions and 170 deletions
@@ -0,0 +1,68 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import {
changePlatformFeeItemStatus,
createPlatformFeeItem,
deletePlatformFeeItem,
getPlatformFeeItem,
listPlatformFeeItems,
updatePlatformFeeItem,
type SavePlatformFeeItemRequest,
} from './platformFeeItems'
vi.mock('@/shared/api/http', () => ({
http: { get: vi.fn(), post: vi.fn(), put: vi.fn(), patch: vi.fn(), delete: vi.fn() },
unwrapApiResponse: <T>(response: { data: T }) => response.data,
}))
const payload: SavePlatformFeeItemRequest = {
category: '仓储成本',
tradeScope: 'INTERNATIONAL',
feeTypeName: '仓库租赁费',
pickupPayable: false,
pickupReceivable: false,
warehousePayable: true,
warehouseReceivable: true,
allocationFee: true,
description: null,
}
describe('platform fee item API', () => {
beforeEach(() => vi.clearAllMocks())
it('sends normalized public list filters without customer context', async () => {
vi.mocked(http.get).mockResolvedValue({
code: '200', message: 'success', data: { records: [], page: '2', size: '20', total: '21', pages: '2' },
})
await expect(listPlatformFeeItems({
category: ' 仓储成本 ', tradeScope: 'INTERNATIONAL',
keyword: ' 租赁 ', status: 'ACTIVE', page: 2, size: 20,
})).resolves.toMatchObject({ page: 2, size: 20, total: 21, pages: 2 })
expect(http.get).toHaveBeenCalledWith('/platform/v1/fee-items', { params: {
category: '仓储成本', tradeScope: 'INTERNATIONAL',
keyword: '租赁', status: 'ACTIVE', page: 2, size: 20,
} })
})
it('uses public detail and mutation contracts', async () => {
vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: { id: '11' } })
vi.mocked(http.post).mockResolvedValue({ code: '200', message: 'success', data: { id: '11' } })
vi.mocked(http.put).mockResolvedValue({ code: '200', message: 'success', data: { id: '11' } })
vi.mocked(http.patch).mockResolvedValue({ code: '200', message: 'success', data: null })
vi.mocked(http.delete).mockResolvedValue({ code: '200', message: 'success', data: null })
await getPlatformFeeItem('11')
await createPlatformFeeItem(payload)
await updatePlatformFeeItem('11', payload)
await changePlatformFeeItemStatus('11', 'DISABLED')
await deletePlatformFeeItem('11')
expect(http.get).toHaveBeenCalledWith('/platform/v1/fee-items/11')
expect(http.post).toHaveBeenCalledWith('/platform/v1/fee-items', payload)
expect(http.put).toHaveBeenCalledWith('/platform/v1/fee-items/11', payload)
expect(http.patch).toHaveBeenCalledWith('/platform/v1/fee-items/11/status', { status: 'DISABLED' })
expect(http.delete).toHaveBeenCalledWith('/platform/v1/fee-items/11')
})
})
@@ -0,0 +1,119 @@
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
export type FeeItemTradeScope = 'DOMESTIC' | 'INTERNATIONAL'
export type FeeItemStatus = 'ACTIVE' | 'DISABLED'
export interface PlatformFeeItemResource {
id: number | string
category: string
tradeScope: FeeItemTradeScope
feeCode: string | null
feeTypeName: string
pickupPayable: boolean
pickupReceivable: boolean
warehousePayable: boolean
warehouseReceivable: boolean
allocationFee: boolean
description: string | null
status: FeeItemStatus
createdByName?: string | null
updatedByName?: string | null
createdAt?: string | null
updatedAt?: string | null
}
export interface SavePlatformFeeItemRequest {
category: string
tradeScope: FeeItemTradeScope
feeTypeName: string
pickupPayable: boolean
pickupReceivable: boolean
warehousePayable: boolean
warehouseReceivable: boolean
allocationFee: boolean
description: string | null
}
export interface PlatformFeeItemQuery {
category?: string
tradeScope?: FeeItemTradeScope | ''
keyword?: string
status?: FeeItemStatus | ''
page: number
size: number
}
export interface PlatformFeeItemPage {
records: PlatformFeeItemResource[]
page: number
size: number
total: number
pages: number
}
const basePath = '/platform/v1/fee-items'
export async function listPlatformFeeItems(query: PlatformFeeItemQuery) {
const response = await http.get<ApiEnvelope<PlatformFeeItemPage>, ApiEnvelope<PlatformFeeItemPage>>(basePath, {
params: {
category: query.category?.trim() || undefined,
tradeScope: query.tradeScope || undefined,
keyword: query.keyword?.trim() || undefined,
status: query.status || undefined,
page: query.page,
size: query.size,
},
})
const result = unwrapApiResponse(response)
return {
...result,
records: result.records || [],
page: Number(result.page),
size: Number(result.size),
total: Number(result.total),
pages: Number(result.pages),
}
}
export async function getPlatformFeeItem(id: number | string) {
const response = await http.get<ApiEnvelope<PlatformFeeItemResource>, ApiEnvelope<PlatformFeeItemResource>>(
`${basePath}/${id}`,
)
return unwrapApiResponse(response)
}
export async function createPlatformFeeItem(payload: SavePlatformFeeItemRequest) {
const response = await http.post<ApiEnvelope<PlatformFeeItemResource>, ApiEnvelope<PlatformFeeItemResource>>(
basePath,
payload,
)
return unwrapApiResponse(response)
}
export async function updatePlatformFeeItem(id: number | string, payload: SavePlatformFeeItemRequest) {
const response = await http.put<ApiEnvelope<PlatformFeeItemResource>, ApiEnvelope<PlatformFeeItemResource>>(
`${basePath}/${id}`,
payload,
)
return unwrapApiResponse(response)
}
export async function changePlatformFeeItemStatus(id: number | string, status: FeeItemStatus) {
const response = await http.patch<ApiEnvelope<null>, ApiEnvelope<null>>(
`${basePath}/${id}/status`,
{ status },
)
return unwrapApiResponse(response)
}
export async function deletePlatformFeeItem(id: number | string) {
const response = await http.delete<ApiEnvelope<null>, ApiEnvelope<null>>(
`${basePath}/${id}`,
)
return unwrapApiResponse(response)
}