优化
This commit is contained in:
+3
-1
@@ -102,7 +102,7 @@ Client 全量、Client 二期、待审核订单和批量待分柜均复用这套
|
||||
|---|---|---|---|
|
||||
| 平台后台全模块 HTTP 验收 | `scripts/admin-test-env-acceptance.mjs` | 会创建、更新或最终停用测试数据 | `--modules` 默认列表中的平台客户、仓储、订单、入库、分柜、装柜、船期、拖车、报关、财务、通知、统计等模块 |
|
||||
| 客户工作台完整 HTTP 链路验收 | `scripts/client-test-env-acceptance.mjs` | 会创建测试企业、订单、入库、权限和站内消息数据 | 注册/审核、客户隔离、订单、入库计费、文件、财务、客户侧权限,以及我的消息未读/已读/全部已读链路 |
|
||||
| Client 快速下单定向 HTTP 验收 | `scripts/client-quick-order-test-env-acceptance.mjs` | 使用 `MERCHANT_TEST_USERNAME/PASSWORD` 对应客户创建快速下单草稿 | 真实调用 `/api/merchant/v1/orders/first-leg/batch`,覆盖 FBA、海外仓、私人地址、逐行失败、详情归属与幂等重放;只创建草稿,不提交、不审核 |
|
||||
| Client 快速下单定向 HTTP 验收 | `scripts/client-quick-order-test-env-acceptance.mjs` | 使用 `MERCHANT_TEST_USERNAME/PASSWORD` 对应客户创建快速下单草稿 | 真实调用 `/api/merchant/v1/orders/first-leg/batch`,覆盖 FBA、多产品、海外仓、多个私人地址、地址归属失败、渠道失败、重复行、逐行隔离、失败重试、详情归属、幂等重放与冲突;只创建草稿,不提交、不审核 |
|
||||
| 固定客户批量创建待审核订单 | `scripts/create-pending-review-orders.mjs` | 只使用 `MERCHANT_TEST_USERNAME/PASSWORD` 配置的客户账号创建指定数量订单 | 使用 `ADMIN_TEST_GATEWAY`,选择真实可计价仓库/渠道,创建并提交订单,停在待审核,不创建客户、不审核订单 |
|
||||
| Client 二期专项 HTTP 验收 | `scripts/client-phase2-test-env-acceptance.mjs` | 会写入测试环境业务数据 | 二期客户入库、测量、费用和权限专项场景;不是替代 Client 全量入口 |
|
||||
| 人工分柜至 LOADED 分段验收 | `scripts/admin-test-env-acceptance.mjs` 的 `manual-*-fixture/verify` 可选模块;步骤和参数见 `scripts/admin-test-env-modules/README.md` | fixture 通过正式 HTTP 准备本轮数据,verify 只读核验;不进入默认全量 | `WAIT_SPLIT → 人工分柜 → 推送预装 → 订舱关联/计划确认 → PDA 领取与原子 batch → 五类证据/完成 → LOADED` |
|
||||
@@ -119,6 +119,8 @@ Client 全量、Client 二期、待审核订单和批量待分柜均复用这套
|
||||
node --env-file="$env:USERPROFILE\.codex\chongchong-global-test-acceptance.env" scripts/client-quick-order-test-env-acceptance.mjs
|
||||
```
|
||||
|
||||
需要额外随机创建多张草稿做压力回归时增加 `--random-count 20`。随机批次在三种目的仓类型间轮换,具体仓库/地址、每单产品数和箱数随机;逐张回查客户归属、草稿状态、目的类型和产品数量,并对整批执行幂等重放。取值范围 `1-50`,会在基础矩阵之外额外保留对应数量的草稿。
|
||||
|
||||
报告写入 `reports/client-quick-order-test-env-*.json`。脚本不提交、不审核、不取消订单,成功草稿保留为可丢弃测试数据;真实 HTTP 仅在当前轮明确授权测试环境验收后执行。
|
||||
|
||||
## 固定客户待审核订单
|
||||
|
||||
@@ -205,7 +205,8 @@ Assert-Contains $adminAgents '按钮资格以服务端 `canAssign` 为准' 'Admi
|
||||
Assert-Contains $firstlegOpenApi '未传或空数组表示 PENDING_REVIEW、WAIT_MEASURE、WAIT_SPLIT、' '智能装柜四态 OpenAPI'
|
||||
Assert-Contains $firstlegOpenApi '/api/platform/v1/first-leg/smart-loading/plans/{planId}/pending-review-assignments:' '待审核占位 OpenAPI'
|
||||
Assert-Contains $firstlegOpenApi '/api/platform/v1/first-leg/smart-loading/plans/{planId}/unpicked-items:' '未拣整批移除 OpenAPI'
|
||||
Assert-Contains $pendingReviewOrderService 'OrderStatus.SUBMITTED' 'Order 待审核候选状态事实'
|
||||
Assert-Contains $pendingReviewOrderService 'orders.pendingReviewPage' 'Order 待审核候选权威查询'
|
||||
Assert-Contains $pendingReviewOrderService '"PENDING_REVIEW"' 'Order 待审核候选状态映射'
|
||||
Assert-Contains $rootAgents '客户入库结果与头程费用确认' '根客户入库费用确认入口'
|
||||
Assert-Contains $firstlegAgents 'expectedFeeVersion' 'Firstleg 客户费用版本确认'
|
||||
Assert-Contains $clientAgents 'components/InboundBillingPanel.vue' 'Client 入库费用确认入口'
|
||||
|
||||
@@ -6,18 +6,28 @@ const source = await readFile(new URL('./client-quick-order-test-env-acceptance.
|
||||
|
||||
test('quick-order HTTP acceptance uses the same endpoint and skeletal cargo payload as Client', () => {
|
||||
assert.match(source, /\/api\/merchant\/v1\/orders\/first-leg\/batch/)
|
||||
assert.match(source, /cargoName: '', packageType: 'CARTON', packageCount: 2, grossWeightKg: 0, volumeCbm: 0/)
|
||||
assert.match(source, /cargoes: Array\.from\(\{ length: cargoCount \}/)
|
||||
assert.match(source, /cargoName: '', packageType: 'CARTON', packageCount: index \+ 1, grossWeightKg: 0, volumeCbm: 0/)
|
||||
assert.match(source, /destinationType: 'FBA'/)
|
||||
assert.match(source, /destinationType: 'OVERSEAS'/)
|
||||
assert.match(source, /destinationType: 'PRIVATE'/)
|
||||
assert.match(source, /addresses\?addressType=PRIVATE_DESTINATION/)
|
||||
assert.match(source, /privateDestinationAddressId: String\(privateAddress\.id\)/)
|
||||
assert.match(source, /privateDestinationAddressId: String\(address\.id\)/)
|
||||
})
|
||||
|
||||
test('quick-order HTTP acceptance verifies partial failure, detail ownership, and idempotent replay', () => {
|
||||
assert.match(source, /expected succeeded=3/)
|
||||
assert.match(source, /invalid channel row must fail independently/)
|
||||
test('quick-order HTTP acceptance verifies expanded row, cargo, isolation, retry, and idempotency behavior', () => {
|
||||
assert.match(source, /expected succeeded=5/)
|
||||
assert.match(source, /cargo count mismatch/)
|
||||
assert.match(source, /unowned private address must fail closed with A0404/)
|
||||
assert.match(source, /duplicate clientRowId must fail independently with A0409/)
|
||||
assert.match(source, /draft must belong to the authenticated enterprise/)
|
||||
assert.match(source, /same idempotency key replays the same quick-order drafts/)
|
||||
assert.match(source, /idempotent replay returned different order IDs/)
|
||||
assert.match(source, /same row id and idempotency key reject a changed payload/)
|
||||
assert.match(source, /a corrected failed row succeeds under a fresh batch key/)
|
||||
assert.match(source, /--random-count <1-50>/)
|
||||
assert.match(source, /create \$\{randomCount\} randomized quick-order drafts/)
|
||||
assert.match(source, /verify all \$\{randomCount\} randomized drafts/)
|
||||
assert.match(source, /replay all \$\{randomCount\} randomized drafts idempotently/)
|
||||
assert.match(source, /randomInt\(1, 6\)/)
|
||||
})
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { randomUUID } from 'node:crypto'
|
||||
import { randomInt, randomUUID } from 'node:crypto'
|
||||
import { mkdir, writeFile } from 'node:fs/promises'
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
const args = parseArgs(process.argv.slice(2))
|
||||
if (args.help) {
|
||||
console.log('Usage: node scripts/client-quick-order-test-env-acceptance.mjs [--report-dir <path>] [--timeout-ms <ms>]')
|
||||
console.log('Usage: node scripts/client-quick-order-test-env-acceptance.mjs [--report-dir <path>] [--timeout-ms <ms>] [--random-count <1-50>]')
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ const gateway = trimSlash(process.env.ADMIN_TEST_GATEWAY)
|
||||
const username = process.env.MERCHANT_TEST_USERNAME
|
||||
const password = process.env.MERCHANT_TEST_PASSWORD
|
||||
const timeoutMs = Number(args['timeout-ms'] ?? process.env.CLIENT_TEST_TIMEOUT_MS ?? 30_000)
|
||||
const randomCount = Number(args['random-count'] ?? 0)
|
||||
const reportDir = resolve(args['report-dir'] ?? process.env.CLIENT_TEST_REPORT_DIR ?? 'reports')
|
||||
const marker = `${compactTimestamp()}-${randomUUID().slice(0, 8)}`
|
||||
const reportPath = resolve(reportDir, `client-quick-order-test-env-${marker}.json`)
|
||||
@@ -23,7 +24,7 @@ const report = {
|
||||
completedAt: null,
|
||||
success: false,
|
||||
fatal: null,
|
||||
resources: { batchKey: null, orderNos: [] },
|
||||
resources: { batchKey: null, randomBatchKey: null, orderNos: [] },
|
||||
steps: [],
|
||||
}
|
||||
|
||||
@@ -35,6 +36,10 @@ if (!Number.isFinite(timeoutMs) || timeoutMs < 1_000) {
|
||||
console.error('--timeout-ms must be at least 1000')
|
||||
process.exit(2)
|
||||
}
|
||||
if (!Number.isInteger(randomCount) || randomCount < 0 || randomCount > 50) {
|
||||
console.error('--random-count must be an integer between 1 and 50')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
let token
|
||||
try {
|
||||
@@ -69,12 +74,13 @@ try {
|
||||
assert(['AUTO', 'LEGACY_MANUAL'].includes(response.data?.mode), `unexpected policy ${response.data?.mode}`)
|
||||
return response.data
|
||||
})
|
||||
const privateAddresses = await step('load customer-owned private destination addresses', async () => {
|
||||
let privateAddresses = []
|
||||
await step('load customer-owned private destination addresses', async () => {
|
||||
const response = await jsonRequest('/api/merchant/v1/orders/first-leg/addresses?addressType=PRIVATE_DESTINATION')
|
||||
requireSuccess(response)
|
||||
const addresses = arrayData(response.data)
|
||||
assert(addresses.length > 0, 'at least one customer-owned private destination address is required')
|
||||
return addresses
|
||||
privateAddresses = arrayData(response.data)
|
||||
assert(privateAddresses.length > 0, 'at least one customer-owned private destination address is required')
|
||||
return { count: privateAddresses.length }
|
||||
})
|
||||
const domestic = await loadWarehouses('DOMESTIC')
|
||||
const fba = await loadWarehouses('FBA')
|
||||
@@ -93,48 +99,70 @@ try {
|
||||
}
|
||||
assert(receiving && channel, 'no domestic warehouse has an active pricing channel')
|
||||
|
||||
const privateAddress = privateAddresses[0]
|
||||
const privateDestination = {
|
||||
destinationType: 'PRIVATE', destinationCountryCode: privateAddress.countryCode,
|
||||
destinationWarehouseName: privateAddress.addressName, privateDestinationAddressId: String(privateAddress.id),
|
||||
}
|
||||
const fbaDestination = (warehouse) => ({
|
||||
destinationType: 'FBA', destinationCountryCode: warehouse.countryCode, destinationWarehouseId: warehouse.id,
|
||||
destinationWarehouseName: warehouse.warehouseName, amazonWarehouseCode: warehouse.warehouseCode,
|
||||
})
|
||||
const overseasDestination = (warehouse) => ({
|
||||
destinationType: 'OVERSEAS', destinationCountryCode: warehouse.countryCode,
|
||||
destinationWarehouseId: warehouse.id, destinationWarehouseName: warehouse.warehouseName,
|
||||
})
|
||||
const privateDestination = (address) => ({
|
||||
destinationType: 'PRIVATE', destinationCountryCode: address.countryCode,
|
||||
destinationWarehouseName: address.addressName, privateDestinationAddressId: String(address.id),
|
||||
})
|
||||
const invalidChannelRowId = `quick-order-invalid-channel-${marker}`
|
||||
const invalidPrivateRowId = `quick-order-invalid-private-${marker}`
|
||||
const rows = [
|
||||
{ clientRowId: `quick-order-fba-${marker}`, draft: quickDraft(profile.tenantName, policy, receiving, channel, {
|
||||
destinationType: 'FBA', destinationCountryCode: fba[0].countryCode, destinationWarehouseId: fba[0].id,
|
||||
destinationWarehouseName: fba[0].warehouseName, amazonWarehouseCode: fba[0].warehouseCode,
|
||||
}, 'FBA') },
|
||||
{ clientRowId: `quick-order-overseas-${marker}`, draft: quickDraft(profile.tenantName, policy, receiving, channel, {
|
||||
destinationType: 'OVERSEAS', destinationCountryCode: overseas[0].countryCode,
|
||||
destinationWarehouseId: overseas[0].id, destinationWarehouseName: overseas[0].warehouseName,
|
||||
}, 'OVERSEAS') },
|
||||
{ clientRowId: `quick-order-private-${marker}`, draft: quickDraft(profile.tenantName, policy, receiving, channel,
|
||||
privateDestination, 'PRIVATE') },
|
||||
{ clientRowId: `quick-order-invalid-channel-${marker}`, draft: {
|
||||
...quickDraft(profile.tenantName, policy, receiving, channel, {
|
||||
destinationType: 'FBA', destinationCountryCode: fba[0].countryCode, destinationWarehouseId: fba[0].id,
|
||||
destinationWarehouseName: fba[0].warehouseName, amazonWarehouseCode: fba[0].warehouseCode,
|
||||
}, 'INVALID'), channelCode: `INVALID-${marker}`, channelName: '不存在的渠道',
|
||||
{ clientRowId: `quick-order-fba-${marker}`, draft: quickDraft(profile.tenantName, policy, receiving, channel,
|
||||
fbaDestination(fba[0]), 'FBA') },
|
||||
{ clientRowId: `quick-order-fba-multi-cargo-${marker}`, draft: quickDraft(profile.tenantName, policy, receiving, channel,
|
||||
fbaDestination(fba[1] ?? fba[0]), 'FBA-MULTI', 3) },
|
||||
{ clientRowId: `quick-order-overseas-${marker}`, draft: quickDraft(profile.tenantName, policy, receiving, channel,
|
||||
overseasDestination(overseas[1] ?? overseas[0]), 'OVERSEAS') },
|
||||
{ clientRowId: `quick-order-private-a-${marker}`, draft: quickDraft(profile.tenantName, policy, receiving, channel,
|
||||
privateDestination(privateAddresses[0]), 'PRIVATE-A') },
|
||||
{ clientRowId: `quick-order-private-b-${marker}`, draft: quickDraft(profile.tenantName, policy, receiving, channel,
|
||||
privateDestination(privateAddresses[1] ?? privateAddresses[0]), 'PRIVATE-B') },
|
||||
{ clientRowId: invalidChannelRowId, draft: {
|
||||
...quickDraft(profile.tenantName, policy, receiving, channel, fbaDestination(fba[0]), 'INVALID'),
|
||||
channelCode: `INVALID-${marker}`, channelName: '不存在的渠道',
|
||||
} },
|
||||
{ clientRowId: invalidPrivateRowId, draft: quickDraft(profile.tenantName, policy, receiving, channel, {
|
||||
destinationType: 'PRIVATE', destinationCountryCode: 'US', destinationWarehouseName: '越权私人仓',
|
||||
privateDestinationAddressId: '9223372036854775807',
|
||||
}, 'INVALID-PRIVATE') },
|
||||
{ clientRowId: `quick-order-fba-${marker}`, draft: quickDraft(profile.tenantName, policy, receiving, channel,
|
||||
fbaDestination(fba[0]), 'DUPLICATE') },
|
||||
]
|
||||
const expectedCargoCounts = new Map(rows.slice(0, 5).map((item) => [item.clientRowId, item.draft.cargoes.length]))
|
||||
const expectedDestinationTypes = new Map(rows.slice(0, 5).map((item) => [item.clientRowId, item.draft.destinationType]))
|
||||
|
||||
const batchKey = `quick-order-http-${randomUUID()}`
|
||||
report.resources.batchKey = batchKey
|
||||
const created = await step('create FBA, overseas and private quick-order drafts with one invalid row', async () => {
|
||||
const created = await step('create five varied quick-order drafts while isolating three invalid rows', async () => {
|
||||
const response = await jsonRequest('/api/merchant/v1/orders/first-leg/batch', {
|
||||
method: 'POST', body: rows, headers: { 'Idempotency-Key': batchKey },
|
||||
})
|
||||
requireSuccess(response)
|
||||
assert(response.data?.total === 4, `expected total=4, got ${response.data?.total}`)
|
||||
assert(response.data?.total === 8, `expected total=8, got ${response.data?.total}`)
|
||||
const rowEvidence = arrayData(response.data?.items).map((item) => ({
|
||||
clientRowId: item.clientRowId, success: item.success, orderId: item.orderId, orderNo: item.orderNo,
|
||||
errorCode: item.errorCode, errorMessage: item.errorMessage,
|
||||
}))
|
||||
assert(response.data?.succeeded === 3,
|
||||
`expected succeeded=3, got ${response.data?.succeeded}; rows=${JSON.stringify(rowEvidence)}`)
|
||||
assert(response.data?.failed === 1,
|
||||
`expected failed=1, got ${response.data?.failed}; rows=${JSON.stringify(rowEvidence)}`)
|
||||
const failed = response.data.items.find((item) => item.clientRowId === rows[3].clientRowId)
|
||||
assert(failed && !failed.success && failed.errorCode, 'invalid channel row must fail independently')
|
||||
assert(response.data?.succeeded === 5,
|
||||
`expected succeeded=5, got ${response.data?.succeeded}; rows=${JSON.stringify(rowEvidence)}`)
|
||||
assert(response.data?.failed === 3,
|
||||
`expected failed=3, got ${response.data?.failed}; rows=${JSON.stringify(rowEvidence)}`)
|
||||
const invalidChannel = response.data.items.find((item) => item.clientRowId === invalidChannelRowId)
|
||||
const invalidPrivate = response.data.items.find((item) => item.clientRowId === invalidPrivateRowId)
|
||||
const duplicate = response.data.items[7]
|
||||
assert(invalidChannel && !invalidChannel.success && invalidChannel.errorCode === 'A0409',
|
||||
'invalid channel row must fail independently with A0409')
|
||||
assert(invalidPrivate && !invalidPrivate.success && invalidPrivate.errorCode === 'A0404',
|
||||
`unowned private address must fail closed with A0404; actual=${JSON.stringify(invalidPrivate)}`)
|
||||
assert(duplicate && !duplicate.success && duplicate.errorCode === 'A0409',
|
||||
'duplicate clientRowId must fail independently with A0409')
|
||||
return { ...response.data, items: rowEvidence }
|
||||
})
|
||||
|
||||
@@ -147,8 +175,13 @@ try {
|
||||
requireSuccess(response)
|
||||
assert(response.data?.order?.status === 'DRAFT', `expected DRAFT, got ${response.data?.order?.status}`)
|
||||
assert(response.data?.order?.customerName === profile.tenantName, 'draft must belong to the authenticated enterprise')
|
||||
assert(response.data?.order?.destinationType === expectedDestinationTypes.get(item.clientRowId),
|
||||
`destination type mismatch for ${item.clientRowId}`)
|
||||
assert(arrayData(response.data?.cargoes).length === expectedCargoCounts.get(item.clientRowId),
|
||||
`cargo count mismatch for ${item.clientRowId}`)
|
||||
report.resources.orderNos.push(item.orderNo)
|
||||
return { orderNo: item.orderNo, status: response.data.order.status, customerName: response.data.order.customerName }
|
||||
return { orderNo: item.orderNo, status: response.data.order.status,
|
||||
destinationType: response.data.order.destinationType, cargoCount: response.data.cargoes.length }
|
||||
})
|
||||
}
|
||||
|
||||
@@ -163,6 +196,107 @@ try {
|
||||
return { replayedOrderNos: response.data.items.filter((item) => item.success).map((item) => item.orderNo) }
|
||||
})
|
||||
|
||||
await step('same row id and idempotency key reject a changed payload without overwriting the draft', async () => {
|
||||
const changed = structuredClone(rows[0])
|
||||
changed.draft.cargoes[0].packageCount = 99
|
||||
const response = await jsonRequest('/api/merchant/v1/orders/first-leg/batch', {
|
||||
method: 'POST', body: [changed], headers: { 'Idempotency-Key': batchKey },
|
||||
})
|
||||
requireSuccess(response)
|
||||
assert(response.data?.succeeded === 0 && response.data?.failed === 1,
|
||||
'changed payload with the same idempotency key must fail')
|
||||
assert(response.data?.items?.[0]?.errorCode === 'A0409',
|
||||
`expected idempotency conflict A0409, got ${response.data?.items?.[0]?.errorCode}`)
|
||||
return { errorCode: response.data.items[0].errorCode, errorMessage: response.data.items[0].errorMessage }
|
||||
})
|
||||
|
||||
await step('a corrected failed row succeeds under a fresh batch key', async () => {
|
||||
const corrected = {
|
||||
clientRowId: invalidChannelRowId,
|
||||
draft: quickDraft(profile.tenantName, policy, receiving, channel, fbaDestination(fba[0]), 'RETRY'),
|
||||
}
|
||||
const response = await jsonRequest('/api/merchant/v1/orders/first-leg/batch', {
|
||||
method: 'POST', body: [corrected], headers: { 'Idempotency-Key': `quick-order-retry-${randomUUID()}` },
|
||||
})
|
||||
requireSuccess(response)
|
||||
const item = response.data?.items?.[0]
|
||||
assert(response.data?.succeeded === 1 && item?.success && item?.orderId != null,
|
||||
`corrected row did not succeed: ${JSON.stringify(response.data)}`)
|
||||
const detail = await jsonRequest(`/api/merchant/v1/orders/first-leg/${item.orderId}`)
|
||||
requireSuccess(detail)
|
||||
assert(detail.data?.order?.status === 'DRAFT', 'corrected row must remain a draft')
|
||||
assert(detail.data?.order?.customerName === profile.tenantName,
|
||||
'corrected draft must belong to the authenticated enterprise')
|
||||
report.resources.orderNos.push(item.orderNo)
|
||||
return { orderNo: item.orderNo, status: detail.data.order.status }
|
||||
})
|
||||
|
||||
if (randomCount > 0) {
|
||||
const destinationBuilders = [
|
||||
() => fbaDestination(fba[randomInt(fba.length)]),
|
||||
() => overseasDestination(overseas[randomInt(overseas.length)]),
|
||||
() => privateDestination(privateAddresses[randomInt(privateAddresses.length)]),
|
||||
]
|
||||
const randomRows = Array.from({ length: randomCount }, (_, index) => {
|
||||
const destination = destinationBuilders[index % destinationBuilders.length]()
|
||||
const cargoCount = randomInt(1, 6)
|
||||
const draft = quickDraft(profile.tenantName, policy, receiving, channel, destination,
|
||||
`RANDOM-${index + 1}`, cargoCount)
|
||||
draft.cargoes.forEach((cargo) => {
|
||||
cargo.packageCount = randomInt(1, 31)
|
||||
cargo.totalQuantity = cargo.packageCount * randomInt(1, 11)
|
||||
cargo.unitsPerPackage = Math.max(1, Math.floor(cargo.totalQuantity / cargo.packageCount))
|
||||
})
|
||||
return { clientRowId: `quick-order-random-${index + 1}-${marker}`, draft }
|
||||
})
|
||||
const randomBatchKey = `quick-order-random-http-${randomUUID()}`
|
||||
report.resources.randomBatchKey = randomBatchKey
|
||||
const randomCreated = await step(`create ${randomCount} randomized quick-order drafts`, async () => {
|
||||
const response = await jsonRequest('/api/merchant/v1/orders/first-leg/batch', {
|
||||
method: 'POST', body: randomRows, headers: { 'Idempotency-Key': randomBatchKey },
|
||||
})
|
||||
requireSuccess(response)
|
||||
assert(response.data?.total === randomCount, `expected random total=${randomCount}, got ${response.data?.total}`)
|
||||
assert(response.data?.succeeded === randomCount && response.data?.failed === 0,
|
||||
`random batch failures: ${JSON.stringify(response.data?.items?.filter((item) => !item.success))}`)
|
||||
return response.data.items.map((item, index) => ({
|
||||
clientRowId: item.clientRowId, orderId: item.orderId, orderNo: item.orderNo,
|
||||
destinationType: randomRows[index].draft.destinationType,
|
||||
cargoCount: randomRows[index].draft.cargoes.length,
|
||||
}))
|
||||
})
|
||||
|
||||
await step(`verify all ${randomCount} randomized drafts`, async () => {
|
||||
const evidence = []
|
||||
for (const item of randomCreated) {
|
||||
const response = await jsonRequest(`/api/merchant/v1/orders/first-leg/${item.orderId}`)
|
||||
requireSuccess(response)
|
||||
assert(response.data?.order?.status === 'DRAFT', `random draft ${item.orderNo} is not DRAFT`)
|
||||
assert(response.data?.order?.customerName === profile.tenantName,
|
||||
`random draft ${item.orderNo} is outside the authenticated enterprise`)
|
||||
assert(response.data?.order?.destinationType === item.destinationType,
|
||||
`random draft ${item.orderNo} destination type mismatch`)
|
||||
assert(arrayData(response.data?.cargoes).length === item.cargoCount,
|
||||
`random draft ${item.orderNo} cargo count mismatch`)
|
||||
report.resources.orderNos.push(item.orderNo)
|
||||
evidence.push({ orderNo: item.orderNo, destinationType: item.destinationType, cargoCount: item.cargoCount })
|
||||
}
|
||||
return evidence
|
||||
})
|
||||
|
||||
await step(`replay all ${randomCount} randomized drafts idempotently`, async () => {
|
||||
const response = await jsonRequest('/api/merchant/v1/orders/first-leg/batch', {
|
||||
method: 'POST', body: randomRows, headers: { 'Idempotency-Key': randomBatchKey },
|
||||
})
|
||||
requireSuccess(response)
|
||||
const originalIds = randomCreated.map((item) => String(item.orderId))
|
||||
const replayIds = response.data?.items?.map((item) => String(item.orderId))
|
||||
assert(JSON.stringify(replayIds) === JSON.stringify(originalIds),
|
||||
'randomized idempotent replay returned different order IDs')
|
||||
return { replayed: replayIds.length }
|
||||
})
|
||||
}
|
||||
|
||||
report.success = report.steps.every((item) => item.passed)
|
||||
} catch (error) {
|
||||
report.fatal = sanitizeError(error)
|
||||
@@ -176,7 +310,7 @@ try {
|
||||
|
||||
process.exitCode = report.success ? 0 : 1
|
||||
|
||||
function quickDraft(customerName, policy, receiving, channel, destination, suffix) {
|
||||
function quickDraft(customerName, policy, receiving, channel, destination, suffix, cargoCount = 1) {
|
||||
const inboundCode = policy.mode === 'LEGACY_MANUAL' ? `QO${compactTimestamp()}${suffix.slice(0, 3)}` : undefined
|
||||
return {
|
||||
customerName,
|
||||
@@ -185,11 +319,11 @@ function quickDraft(customerName, policy, receiving, channel, destination, suffi
|
||||
channelCode: channel.channelCode, channelName: channel.channelName,
|
||||
pricingTaxMode: channel.pricingTaxModes[0], taxMode: 'BUY_DECLARATION', containerMode: 'FULL_CONTAINER',
|
||||
customsInspection: null, inboundCode, ...destination,
|
||||
cargoes: [{
|
||||
cargoName: '', packageType: 'CARTON', packageCount: 2, grossWeightKg: 0, volumeCbm: 0,
|
||||
currency: 'USD', dangerousGoods: false, woodenProduct: false, skuNo: `SKU-${suffix}-${marker}`,
|
||||
totalQuantity: 2, unitsPerPackage: 1,
|
||||
}],
|
||||
cargoes: Array.from({ length: cargoCount }, (_, index) => ({
|
||||
cargoName: '', packageType: 'CARTON', packageCount: index + 1, grossWeightKg: 0, volumeCbm: 0,
|
||||
currency: 'USD', dangerousGoods: false, woodenProduct: false, skuNo: `SKU-${suffix}-${index + 1}-${marker}`,
|
||||
totalQuantity: index + 1, unitsPerPackage: 1,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user