优化
This commit is contained in:
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import test from 'node:test'
|
||||
|
||||
import { buildOrderPayload, parseArguments, validateCount } from './create-pending-review-orders.mjs'
|
||||
import { PRODUCT_CATALOG, buildOrderPayload, diversifyRoutes, parseArguments, validateCount } from './create-pending-review-orders.mjs'
|
||||
|
||||
const source = readFileSync(new URL('./create-pending-review-orders.mjs', import.meta.url), 'utf8')
|
||||
|
||||
@@ -10,6 +10,13 @@ test('uses the fixed merchant account and stops at pending review', () => {
|
||||
assert.ok(source.includes("USERNAME: '17512095155'"), 'fixed username is missing')
|
||||
assert.ok(/PASSWORD:\s*'[^']*'/.test(source), 'CONFIG.PASSWORD is missing')
|
||||
assert.ok(/COUNT:\s*\d+/.test(source), 'CONFIG.COUNT is missing')
|
||||
assert.match(source, /COUNT:\s*50/)
|
||||
assert.match(source, /randomInt\(1, 31\)/)
|
||||
assert.match(source, /loadPricedRoutes/)
|
||||
assert.match(source, /destinationWarehouseCode/)
|
||||
assert.match(source, /channelCode/)
|
||||
assert.match(source, /pricingTaxMode/)
|
||||
assert.equal(PRODUCT_CATALOG.length, 8)
|
||||
assert.match(source, /\/api\/merchant\/v1\/orders\/first-leg\/\$\{encodeURIComponent\(orderId\)\}\/submit/)
|
||||
assert.match(source, /detail\?\.order\?\.status !== 'SUBMITTED'/)
|
||||
assert.match(source, /\/api\/merchant\/v1\/orders\/\$\{encodeURIComponent\(orderId\)\}/)
|
||||
@@ -41,6 +48,8 @@ test('builds an order payload owned by the fixed profile', () => {
|
||||
channel: { channelCode: 'SEA-US', channelName: '美西海运' },
|
||||
pricingTaxMode: 'TAX_INCLUDED',
|
||||
},
|
||||
product: PRODUCT_CATALOG[0],
|
||||
packageCount: 7,
|
||||
productImageFileId: '33',
|
||||
})
|
||||
assert.equal(payload.receivingWarehouseId, '11')
|
||||
@@ -49,4 +58,25 @@ test('builds an order payload owned by the fixed profile', () => {
|
||||
assert.equal(payload.customerName, '固定测试客户')
|
||||
assert.equal(payload.cargoes.length, 1)
|
||||
assert.equal(payload.cargoes[0].productImageFileId, '33')
|
||||
assert.equal(payload.cargoes[0].cargoName, PRODUCT_CATALOG[0].cargoName)
|
||||
assert.equal(payload.cargoes[0].packageCount, 7)
|
||||
assert.equal(payload.cargoes[0].totalQuantity, PRODUCT_CATALOG[0].unitsPerPackage * 7)
|
||||
assert.equal(payload.cargoes[0].grossWeightKg, Number((PRODUCT_CATALOG[0].cartonGrossWeightKg * 7).toFixed(3)))
|
||||
assert.equal(payload.cargoes[0].declaredValue, PRODUCT_CATALOG[0].unitDeclaredValue * PRODUCT_CATALOG[0].unitsPerPackage * 7)
|
||||
})
|
||||
|
||||
test('interleaves different logistics combinations before repeating one', () => {
|
||||
const route = (receivingId, channelCode, pricingTaxMode, destinationCode) => ({
|
||||
receiving: { id: receivingId }, channel: { channelCode }, pricingTaxMode,
|
||||
destination: { warehouseCode: destinationCode },
|
||||
})
|
||||
const diversified = diversifyRoutes([
|
||||
route('1', 'SEA-A', 'TAX_INCLUDED', 'A1'),
|
||||
route('1', 'SEA-A', 'TAX_INCLUDED', 'A2'),
|
||||
route('1', 'SEA-B', 'TAX_EXCLUDED', 'B1'),
|
||||
route('1', 'SEA-B', 'TAX_EXCLUDED', 'B2'),
|
||||
])
|
||||
const firstKey = `${diversified[0].channel.channelCode}|${diversified[0].pricingTaxMode}`
|
||||
const secondKey = `${diversified[1].channel.channelCode}|${diversified[1].pricingTaxMode}`
|
||||
assert.notEqual(firstKey, secondKey)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user