test: extend eight-business acceptance flows and offline contracts

This commit is contained in:
2026-10-22 15:41:50 +08:00
parent 86889d7e0e
commit 080ca600e6
33 changed files with 1285 additions and 101 deletions
@@ -10,7 +10,7 @@ const cents = value => {
return BigInt(match[1]) * 100n + BigInt((match[2] || '').padEnd(2, '0'))
}
/** Internal scenario; the TEST coordinator owns isolated customer creation, funding, sessions and file upload. */
/** Internal scenario; the coordinator supplies the configured customer, existing balance, session and upload. */
export async function verifyProcurementSample(context, inputs) {
if (!context.marker || typeof context.checkpoint !== 'function' || typeof context.request !== 'function'
|| inputs?.marker !== context.marker || !/^[1-9]\d*$/.test(String(inputs.customerId))
@@ -44,7 +44,13 @@ export async function verifyProcurementSample(context, inputs) {
await check(label, response?.http === 200 && String(response?.body?.code) === expectedCode)
return response.body.data
}
async function read() { detail = await request('GET', path(), undefined, '回查采购聚合详情'); return detail }
async function read() {
detail = await request('GET', path(), undefined, '回查采购聚合详情')
await check('采购聚合仍属于原客户原单且版本有效', detail?.customerView?.order?.orderNo === proof.orderNo
&& detail.customerView.order.customerId === customerId
&& Number.isSafeInteger(detail.customerView.order.version) && detail.customerView.order.version >= 0)
return detail
}
async function command(operation, values = {}, replay = false) {
const body = { version: detail.customerView.order.version, idempotencyKey: key(operation.replaceAll('/', '-')), reason: context.marker, ...values }
await request('POST', path(operation), body, operation)
@@ -76,7 +82,7 @@ export async function verifyProcurementSample(context, inputs) {
proof.orderNo = created?.order?.orderNo; await context.checkpoint()
await check('客户创建响应包含本轮订单', typeof proof.orderNo === 'string' && created.order.customerId === customerId)
const repeated = await request('POST', MERCHANT, create, '客户同键重放', inputs.customerToken)
await check('重放没有新建采购单', repeated.order.orderNo === proof.orderNo)
await check('重放没有新建采购单', repeated?.order?.orderNo === proof.orderNo && repeated.order.customerId === customerId)
await read()
await request('POST', path('review'), { version: detail.customerView.order.version, idempotencyKey: key('review'), decision: 'APPROVE', purchaseWarehouseId: String(inputs.warehouseId), remark: context.marker }, '审核通过并确定收货仓')
await read()
@@ -115,7 +121,9 @@ export async function verifyProcurementSample(context, inputs) {
await command('customer-shipment', { leg: 'DOMESTIC', labelVersion: domesticLabels, cartonIds, shippedAt: at() }, true)
await check('寄客户正常终态及单次交寄', detail.customerView.order.status === 'SHIPPED_TO_CUSTOMER' && detail.transport.shipments.filter(row => row.leg === 'DOMESTIC').length === 1)
const customer = await request('GET', `${MERCHANT}/${encodeURIComponent(proof.orderNo)}`, undefined, '客户最终详情', inputs.customerToken)
await check('客户可见终态且没有平台内部数据', customer.order.status === 'SHIPPED_TO_CUSTOMER' && !['files','purchaseFacts','controls','internalRemark','operations'].some(field => Object.hasOwn(customer,field)))
await check('客户可见终态且没有平台内部数据', customer?.order?.orderNo === proof.orderNo
&& customer.order.customerId === customerId && customer.order.status === 'SHIPPED_TO_CUSTOMER'
&& !['files','purchaseFacts','controls','internalRemark','operations'].some(field => Object.hasOwn(customer,field)))
await wallet('重复交寄不再次扣款', 250n, 0n)
proof.walletBusinessNos = [...new Set(detail.fees.filter(row => row.walletStatus === 'SETTLED').map(row => row.walletBusinessNo))]
await check('每笔成功消费保留权威钱包业务引用', proof.walletBusinessNos.length === 2 && proof.walletBusinessNos.every(value => typeof value === 'string' && value.length > 0))