This commit is contained in:
2026-08-04 12:01:05 +08:00
parent f533024501
commit 3877af0b72
9 changed files with 182 additions and 181 deletions
@@ -74,28 +74,36 @@ test('validates the confirmed minimum submission fields', () => {
assert.deepEqual(validateFirstLegOrderDraft(validDraft()), [])
const invalid = validDraft()
invalid.origin = ''
invalid.receivingWarehouseId = ''
invalid.items[0].grossWeightKg = 0
invalid.items[0].containerType = ''
invalid.items[0].containerCount = 0
const errors = validateFirstLegOrderDraft(invalid)
assert.ok(errors.includes('请填写起运地'))
assert.ok(errors.includes('请选择平台收货仓'))
assert.ok(errors.includes('第 1 条货物毛重必须大于 0'))
assert.ok(errors.includes('第 1 条货物需要填写箱型和柜量'))
})
test('requires enabled-party snapshots and order addresses before submission', () => {
const draft = validDraft()
draft.shipperPartyId = ''
draft.shipperPartySnapshot = null
draft.consigneePartySnapshot.address = ''
test('only requires sender for pickup and receiver for a private destination', () => {
const publicDraft = validDraft()
publicDraft.shipperPartySnapshot = null
publicDraft.consigneePartySnapshot = null
assert.deepEqual(validateFirstLegOrderDraft(publicDraft), [])
const errors = validateFirstLegOrderDraft(draft)
assert.ok(errors.includes('请选择发货单位'))
assert.ok(errors.includes('请填写本单收货地址'))
const pickupDraft = validDraft()
pickupDraft.pickupMethod = 'PICKUP'
pickupDraft.shipperPartySnapshot = null
assert.ok(validateFirstLegOrderDraft(pickupDraft).includes('请填写提货联系人'))
const privateDraft = validDraft()
privateDraft.destinationType = 'PRIVATE'
privateDraft.destinationWarehouseId = ''
privateDraft.amazonWarehouseCode = ''
privateDraft.shipmentId = ''
privateDraft.referenceNo = ''
privateDraft.consigneePartySnapshot = null
assert.ok(validateFirstLegOrderDraft(privateDraft).includes('请填写收件人姓名'))
})
test('requires FBA reference, warehouse, shipment, SKU and UPC fields', () => {
+13 -9
View File
@@ -62,7 +62,6 @@ export function createEmptyCargoItem(id = `cargo-${Date.now()}`): FirstLegCargoI
export function validateFirstLegOrderDraft(draft: FirstLegOrderDraft) {
const errors: string[] = []
if (!draft.origin.trim()) errors.push('请填写起运地')
if (!draft.destination.trim()) errors.push('请填写目的地')
if (!/^[A-Za-z]{2}$/.test(draft.destinationCountryCode.trim())) errors.push('请输入两位英文字母的目的国代码')
if (!draft.destinationWarehouseName.trim()) errors.push('请填写目的仓名称')
@@ -70,14 +69,19 @@ export function validateFirstLegOrderDraft(draft: FirstLegOrderDraft) {
if (draft.destinationType === 'PRIVATE' && draft.destinationWarehouseId) errors.push('私人地址不能引用平台公共仓库')
if (!draft.channelCode.trim() || !draft.channelName.trim()) errors.push('请填写渠道编码和渠道名称')
if (!draft.receivingWarehouseId) errors.push('请选择平台收货仓')
if (!draft.shipperPartyId || !draft.shipperPartySnapshot || !draft.shipper.trim()) errors.push('请选择发货单位')
if (draft.shipperPartySnapshot && !draft.shipperPartySnapshot.contactName.trim()) errors.push('请填写发货联系人')
if (draft.shipperPartySnapshot && !draft.shipperPartySnapshot.phone.trim()) errors.push('请填写发货联系电话')
if (draft.shipperPartySnapshot && !draft.shipperPartySnapshot.address.trim()) errors.push('请填写本单发货地址')
if (!draft.consigneePartyId || !draft.consigneePartySnapshot || !draft.consignee.trim()) errors.push('请选择收货单位')
if (draft.consigneePartySnapshot && !draft.consigneePartySnapshot.contactName.trim()) errors.push('请填写收货联系人')
if (draft.consigneePartySnapshot && !draft.consigneePartySnapshot.phone.trim()) errors.push('请填写收货联系电话')
if (draft.consigneePartySnapshot && !draft.consigneePartySnapshot.address.trim()) errors.push('请填写本单收货地址')
if (draft.pickupMethod === 'PICKUP') {
if (!draft.shipperPartySnapshot?.contactName.trim()) errors.push('请填写提货联系人')
if (!draft.shipperPartySnapshot?.phone.trim()) errors.push('请填写提货联系电话')
if (!draft.shipperPartySnapshot?.city.trim()) errors.push('请填写提货城市')
if (!draft.shipperPartySnapshot?.address.trim()) errors.push('请填写提货地址')
}
if (draft.destinationType === 'PRIVATE') {
if (!draft.consigneePartySnapshot?.name.trim()) errors.push('请填写私人地址名称')
if (!draft.consigneePartySnapshot?.contactName.trim()) errors.push('请填写收件人姓名')
if (!draft.consigneePartySnapshot?.phone.trim()) errors.push('请填写收件人电话')
if (!draft.consigneePartySnapshot?.city.trim()) errors.push('请填写收件城市')
if (!draft.consigneePartySnapshot?.address.trim()) errors.push('请填写收件详细地址')
}
if (draft.items.length === 0) errors.push('请至少添加一条货物明细')
if (draft.destinationType === 'FBA') {