fix(overseas): normalize transfer inventory quantities at API boundary

This commit is contained in:
2026-10-04 22:26:36 +08:00
parent 939cc11d7b
commit ea24496b11
7 changed files with 90 additions and 14 deletions
@@ -1,7 +1,8 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import { listWarehouseTransferSources } from './warehouseTransferSources'
import type { WarehouseTransferDetailDto } from './warehouseTransfers'
import { getWarehouseTransfer, type WarehouseTransferDetailDto } from './warehouseTransfers'
import { transferSourceWireFixture } from './warehouseTransferSources.fixture'
vi.mock('@/shared/api/http', async original => ({ ...await original<typeof import('@/shared/api/http')>(), http: { get: vi.fn() } }))
const transfer: WarehouseTransferDetailDto = { id: 'transfer', transferNo: 'WT-1', operatingWarehouseId: 'WH-1', needRelabel: true, packageCount: 1, status: 'APPROVED', items: [], cartons: [], pallets: [], relabelBindings: [{ operationType: 'SKU', customerCartonMark: 'BOX', originalSku: 'OLD', newSku: 'NEW', quantity: 1 }], sourceOrders: [{ lastlegOrderId: 'tail', inboundOrderId: 'IN-ID', inboundCode: 'IN-1' }] }
@@ -11,6 +12,17 @@ const envelope = (data: unknown) => ({ code: '200', data })
const page = (records: unknown[], current = 1, total = records.length) => envelope({ records, page: current, size: 200, total, pages: Math.ceil(total / 200) })
describe('confirmed warehouse transfer source reads', () => {
beforeEach(() => vi.resetAllMocks())
it('normalizes the real original-ticket string quantities before source eligibility and package totals', async () => {
const fixture = transferSourceWireFixture
vi.mocked(http.get).mockResolvedValueOnce(envelope(fixture.transfer)).mockResolvedValueOnce(page([{ id: fixture.balance.id, skuCode: fixture.balance.skuCode }])).mockResolvedValueOnce(envelope(fixture.balance)).mockResolvedValueOnce(envelope(fixture.positions))
const detail = await getWarehouseTransfer(fixture.customerId, fixture.transfer.transferNo)
const result = await listWarehouseTransferSources(fixture.customerId, detail)
expect(result.issues).toEqual([])
expect(result.candidates[0]).toMatchObject({ availablePackages: 0, canSelect: false })
expect(result.candidates[1]).toMatchObject({ availablePackages: 3, canSelect: true })
expect(detail.packageCount).toBe(1)
expect(typeof detail.packageCount).toBe('number')
})
it('reads representative detail and actual positions with customer scope, accepts OCCUPIED available stock at original ABE2', async () => {
vi.mocked(http.get).mockResolvedValueOnce(page([{ id: 'B-1', skuCode: 'OLD' }])).mockResolvedValueOnce(envelope(balance)).mockResolvedValueOnce(envelope([position, { ...position, id: 'P-HOLD', availablePackages: 0, holdPackages: 1 }]))
const result = await listWarehouseTransferSources('C-1', transfer)