优化
This commit is contained in:
@@ -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')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user