Files
admin-web/src/modules/overseas-master-data/api/dispatchCapacityDemands.test.ts
T

16 lines
1.4 KiB
TypeScript

import { beforeEach, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import { listDispatchCapacityDemands } from './dispatchCapacityDemands'
vi.mock('@/shared/api/http', () => ({ http: { get: vi.fn() }, unwrapApiResponse: (value: { data: unknown }) => value.data }))
beforeEach(() => vi.clearAllMocks())
it('reads only dispatch demand summaries and preserves unknown quantities distinctly from zero', async () => {
vi.mocked(http.get).mockResolvedValue({ data: { page: '1', size: '20', total: '1', pages: '1', records: [{ dispatchNo: 'PC-1', vehiclePalletSpaces: '30', scheduledPalletCount: '0', remainingPalletSpaces: null, remainingWeightKg: null, remainingVolumeCbm: null, capacityKnown: false }] } })
const value=await listDispatchCapacityDemands({page:1,size:20,origin:'测试仓'})
expect(http.get).toHaveBeenCalledExactlyOnceWith('/platform/v1/last-leg/dispatches/capacity-demands',{params:{page:1,size:20,origin:'测试仓'}})
expect(value).toMatchObject({total:1,records:[{dispatchNo:'PC-1',vehiclePalletSpaces:30,scheduledPalletCount:0,remainingPalletSpaces:null}]})
})
it.each(['invalid', -1, true])('rejects invalid capacity quantities %s', async remainingPalletSpaces => {
vi.mocked(http.get).mockResolvedValue({data:{page:1,size:20,total:1,pages:1,records:[{remainingPalletSpaces}]}})
await expect(listDispatchCapacityDemands({page:1,size:20})).rejects.toThrow('数量无效')
})