2026-08-04 21:01:39 +08:00
|
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
|
import { http } from '@/shared/api/http'
|
|
|
|
|
|
import { getInboundMeasurement, saveInboundMeasurementDraft, submitInboundMeasurement } from './api'
|
|
|
|
|
|
import type { SaveInboundMeasurementDraftRequest } from './types'
|
|
|
|
|
|
|
|
|
|
|
|
vi.mock('@/shared/api/http', () => ({
|
|
|
|
|
|
http: { get: vi.fn(), put: vi.fn(), post: vi.fn() },
|
|
|
|
|
|
unwrapApiResponse: <T>(response: { data: T }) => response.data,
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
const draft: SaveInboundMeasurementDraftRequest = {
|
|
|
|
|
|
measurementId: '9001',
|
|
|
|
|
|
version: 2,
|
|
|
|
|
|
originalDocumentNo: 'DOC-01',
|
|
|
|
|
|
originalGrossWeightKg: 120,
|
|
|
|
|
|
originalVolumeCbm: 1.2,
|
|
|
|
|
|
actualGoodsName: '蓝牙音箱',
|
|
|
|
|
|
items: [{
|
2026-08-07 16:17:45 +08:00
|
|
|
|
boxCode: 'RK202608040001#10-1',
|
2026-08-04 21:01:39 +08:00
|
|
|
|
itemNo: '001',
|
|
|
|
|
|
boxSpecification: '50×40×30cm',
|
|
|
|
|
|
packageCount: 10,
|
|
|
|
|
|
lengthCm: 50,
|
|
|
|
|
|
widthCm: 40,
|
|
|
|
|
|
heightCm: 30,
|
|
|
|
|
|
unitWeightKg: 12,
|
|
|
|
|
|
intelligentImageFileId: '88001',
|
2026-08-07 16:17:45 +08:00
|
|
|
|
machineNo: 'MJ20210327',
|
|
|
|
|
|
measuredAt: '2026-08-04T10:30:00+08:00',
|
2026-08-04 21:01:39 +08:00
|
|
|
|
overLimitWarning: null,
|
|
|
|
|
|
outerLengthCm: null,
|
|
|
|
|
|
outerWidthCm: null,
|
|
|
|
|
|
outerHeightCm: null,
|
|
|
|
|
|
remark: null,
|
|
|
|
|
|
}],
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
describe('inbound measurement API', () => {
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
|
vi.mocked(http.get).mockReset()
|
|
|
|
|
|
vi.mocked(http.put).mockReset()
|
|
|
|
|
|
vi.mocked(http.post).mockReset()
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('maps the selected customer to the backend tenant compatibility parameter', async () => {
|
|
|
|
|
|
const detail = { inboundId: '7001', items: [], weightResults: [] }
|
|
|
|
|
|
vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: detail })
|
|
|
|
|
|
|
|
|
|
|
|
await expect(getInboundMeasurement('10001', '7001')).resolves.toEqual(detail)
|
|
|
|
|
|
expect(http.get).toHaveBeenCalledWith('/platform/v1/first-leg/inbounds/7001/measurement', {
|
|
|
|
|
|
params: { tenantId: '10001' },
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('saves a versioned draft without inventing an idempotency header', async () => {
|
|
|
|
|
|
const saved = { measurementId: '9001', version: 3, status: 'DRAFT' }
|
|
|
|
|
|
vi.mocked(http.put).mockResolvedValue({ code: '200', message: 'success', data: saved })
|
|
|
|
|
|
|
|
|
|
|
|
await expect(saveInboundMeasurementDraft('10001', '7001', draft)).resolves.toEqual(saved)
|
|
|
|
|
|
expect(http.put).toHaveBeenCalledWith(
|
|
|
|
|
|
'/platform/v1/first-leg/inbounds/7001/measurement/draft',
|
|
|
|
|
|
draft,
|
|
|
|
|
|
{ params: { tenantId: '10001' } },
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('submits the server measurement id and optimistic-lock version', async () => {
|
|
|
|
|
|
const submitted = { measurementId: '9001', version: 3, processStatus: 'MEASURE_PENDING' }
|
|
|
|
|
|
vi.mocked(http.post).mockResolvedValue({ code: '200', message: 'success', data: submitted })
|
|
|
|
|
|
|
|
|
|
|
|
await expect(submitInboundMeasurement('10001', '7001', { measurementId: '9001', version: 3 })).resolves.toEqual(submitted)
|
|
|
|
|
|
expect(http.post).toHaveBeenCalledWith(
|
|
|
|
|
|
'/platform/v1/first-leg/inbounds/7001/measurement/submit',
|
|
|
|
|
|
{ measurementId: '9001', version: 3 },
|
|
|
|
|
|
{ params: { tenantId: '10001' } },
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|