Files
baiyue-firstleg/scripts/client-address-isolation-test-env.test.mjs
T

28 lines
2.2 KiB
JavaScript
Raw Normal View History

import test from 'node:test'
import assert from 'node:assert/strict'
import { addressDraft, assertAddressRejected, execute } from './client-address-isolation-test-env.mjs'
test('negative probe plan does not require credentials or execute HTTP', async () => {
assert.equal((await execute(['--plan'], [], {})).plan, true)
})
test('each payload probes exactly one foreign address field', () => {
const args = [{ id: 'foreign' }, { id: 'domestic', warehouseName: '国内仓' }, { channelCode: 'SEA', channelName: '海运' }, { id: 'fba', warehouseCode: 'FBA-A', warehouseName: '目的仓' }]
const pickup = addressDraft('PICKUP', ...args), destination = addressDraft('PRIVATE_DESTINATION', ...args)
assert.equal(pickup.senderAddressId, 'foreign'); assert.equal(pickup.privateDestinationAddressId, undefined)
assert.equal(pickup.destinationType, 'FBA'); assert.equal(pickup.destinationWarehouseId, 'fba')
assert.equal(destination.privateDestinationAddressId, 'foreign'); assert.equal(destination.senderAddressId, undefined)
assert.equal(destination.destinationType, 'PRIVATE'); assert.equal(destination.pickupMethod, 'SELF_TRUCK')
})
test('accepts only the precise address-boundary rejection, never unrelated validation or success', () => {
const single = { http: 200, body: { code: 'A0404', message: '客户地址不存在或已停用', data: null } }
const item = { success: false, orderId: null, errorCode: 'A0404', errorMessage: '客户地址不存在或已停用' }
const batch = { http: 200, body: { code: '200', data: { total: 1, succeeded: 0, failed: 1, items: [item] } } }
assert.doesNotThrow(() => assertAddressRejected(single))
assert.doesNotThrow(() => assertAddressRejected(batch, true))
for (const code of ['200', 'A0422', 'A0403']) assert.throws(() => assertAddressRejected({ ...single, body: { ...single.body, code } }))
assert.throws(() => assertAddressRejected({ ...single, body: { ...single.body, message: '仓库不存在' } }))
for (const change of [{ success: true, orderId: 'created' }, { errorCode: 'A0422' }, { errorMessage: '字段不能为空' }]) {
assert.throws(() => assertAddressRejected({ ...batch, body: { code: '200', data: { ...batch.body.data, items: [{ ...item, ...change }] } } }, true))
}
})