import assert from 'node:assert/strict' import test from 'node:test' import { buildFreightHeaderPayload, buildSettlePayload, freightAmountText, validateFreightHeader } from './sf-express-freight.ts' test('sf express hides amount and requires waybill', () => { assert.equal( validateFreightHeader({ transportMode: 'sfkd', freightAmount: null, waybillNo: ' SF1 ' }), '' ) assert.match( validateFreightHeader({ transportMode: 'sfkd', freightAmount: null, waybillNo: ' ' }), /请填写顺丰单号/ ) assert.deepEqual( buildFreightHeaderPayload({ transportMode: 'sfkd', freightAmount: 8, waybillNo: ' SF1 ' }), { transportMode: 'sfkd', waybillNo: 'SF1', freightAmount: null } ) assert.equal(freightAmountText('sfkd', null), '月结') assert.equal(freightAmountText('sfkd', 8), '8.00') }) test('other transport still requires amount', () => { assert.match( validateFreightHeader({ transportMode: 'zxc', freightAmount: null, waybillNo: '' }), /请填写运费/ ) assert.equal( buildFreightHeaderPayload({ transportMode: 'zxc', freightAmount: 12.3, waybillNo: 'SF1' }) .freightAmount, 12.3 ) assert.equal( buildFreightHeaderPayload({ transportMode: 'zxc', freightAmount: 12.3, waybillNo: 'SF1' }) .waybillNo, '' ) }) test('blank settle omits amount and batch settle never sends amount', () => { assert.deepEqual(buildSettlePayload(['a'], ' '), { ids: ['a'] }) assert.deepEqual(buildSettlePayload(['a'], '6.5'), { ids: ['a'], freightAmount: 6.5 }) assert.deepEqual(buildSettlePayload(['a', 'b'], '6.5'), { ids: ['a', 'b'] }) })