优化
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
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'
|
||||
|
||||
const source = readFileSync(new URL('./create-pending-review-orders.mjs', import.meta.url), 'utf8')
|
||||
|
||||
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, /\/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\)\}/)
|
||||
assert.match(source, /unifiedOrder\?\.summary\?\.mainStatus !== 'PENDING_REVIEW'/)
|
||||
assert.match(source, /mainStatus: unifiedOrder\.summary\.mainStatus/)
|
||||
assert.doesNotMatch(source, /partners\/candidates\?type=SHIPPER/)
|
||||
assert.doesNotMatch(source, /\/api\/platform\/v1\/iam\/tenants/)
|
||||
assert.doesNotMatch(source, /\/approve/)
|
||||
})
|
||||
|
||||
test('supports a bounded fixed order count', () => {
|
||||
assert.equal(validateCount('1'), 1)
|
||||
assert.equal(validateCount('10'), 10)
|
||||
assert.throws(() => validateCount('0'), /between 1 and 100/)
|
||||
assert.throws(() => validateCount('101'), /between 1 and 100/)
|
||||
assert.deepEqual(parseArguments(['--count', '5', '--gateway=http://localhost:9000']), {
|
||||
count: '5', gateway: 'http://localhost:9000',
|
||||
})
|
||||
})
|
||||
|
||||
test('builds an order payload owned by the fixed profile', () => {
|
||||
const payload = buildOrderPayload({
|
||||
marker: 'PENDING-TEST',
|
||||
index: 2,
|
||||
profile: { id: '44', tenantName: '固定测试客户' },
|
||||
master: {
|
||||
receiving: { id: '11', warehouseName: '国内仓' },
|
||||
destination: { id: '22', warehouseName: 'ONT8', warehouseCode: 'ONT8', countryCode: 'US' },
|
||||
channel: { channelCode: 'SEA-US', channelName: '美西海运' },
|
||||
pricingTaxMode: 'TAX_INCLUDED',
|
||||
},
|
||||
productImageFileId: '33',
|
||||
})
|
||||
assert.equal(payload.receivingWarehouseId, '11')
|
||||
assert.equal(payload.destinationWarehouseId, '22')
|
||||
assert.equal(payload.customerId, '44')
|
||||
assert.equal(payload.customerName, '固定测试客户')
|
||||
assert.equal(payload.cargoes.length, 1)
|
||||
assert.equal(payload.cargoes[0].productImageFileId, '33')
|
||||
})
|
||||
Reference in New Issue
Block a user