feat: add inbound hold controls
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { http } from '@/shared/api/http'
|
||||
import { downloadInboundCartonLabels, getPlatformInbound, listPlatformInbounds } from './api'
|
||||
import { downloadInboundCartonLabels, getPlatformInbound, getPlatformInboundHold, holdPlatformInbound, listPlatformInbounds, releasePlatformInbound } from './api'
|
||||
|
||||
vi.mock('@/shared/api/http', () => ({
|
||||
ApiResponseError: class ApiResponseError extends Error {
|
||||
@@ -116,4 +116,34 @@ describe('platform inbound query API', () => {
|
||||
message: '箱号映射不完整', code: 'A0422',
|
||||
})
|
||||
})
|
||||
|
||||
it('loads and normalizes the tenant-scoped hold state and immutable history', async () => {
|
||||
vi.mocked(http.get).mockResolvedValue({ data: {
|
||||
inboundId: 19001, tenantId: 10002, holdFlag: true, currentHoldReason: ' 待核对货款 ', version: '4',
|
||||
canHold: false, canRelease: true, actionBlockReason: null,
|
||||
history: [{ id: 88001, action: 'HOLD', reason: ' 待核对货款 ', evidenceFileId: 99001, operatorName: ' 财务A ', operatedAt: '2026-09-07T10:00:00' }],
|
||||
} })
|
||||
|
||||
await expect(getPlatformInboundHold('10002', '19001')).resolves.toEqual({
|
||||
inboundId: '19001', tenantId: '10002', holdFlag: true, currentHoldReason: '待核对货款', version: 4,
|
||||
canHold: false, canRelease: true, actionBlockReason: null,
|
||||
history: [{ id: '88001', action: 'HOLD', reason: '待核对货款', evidenceFileId: '99001', operatorName: '财务A', operatedAt: '2026-09-07T10:00:00' }],
|
||||
})
|
||||
expect(http.get).toHaveBeenCalledWith('/platform/inbounds/19001/hold', { params: { tenantId: '10002' } })
|
||||
})
|
||||
|
||||
it('posts hold and release commands with versions, reasons and independent idempotency keys', async () => {
|
||||
const result = { data: { inboundId: '19001', tenantId: '10002', holdFlag: true, currentHoldReason: '待核对货款', version: 4, canHold: false, canRelease: true, actionBlockReason: null, history: [] } }
|
||||
vi.mocked(http.post).mockResolvedValue(result)
|
||||
|
||||
await holdPlatformInbound('10002', '19001', { expectedVersion: 3, reason: '待核对货款' }, 'hold-key')
|
||||
expect(http.post).toHaveBeenNthCalledWith(1, '/platform/inbounds/19001/hold', { expectedVersion: 3, reason: '待核对货款' }, {
|
||||
params: { tenantId: '10002' }, headers: { 'Idempotency-Key': 'hold-key' },
|
||||
})
|
||||
|
||||
await releasePlatformInbound('10002', '19001', { expectedVersion: 4, reason: '货款已核对' }, 'release-key')
|
||||
expect(http.post).toHaveBeenNthCalledWith(2, '/platform/inbounds/19001/hold/release', { expectedVersion: 4, reason: '货款已核对' }, {
|
||||
params: { tenantId: '10002' }, headers: { 'Idempotency-Key': 'release-key' },
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user