test(fba): preserve verified fleet and fulfillment acceptance workflows
This commit is contained in:
@@ -12,7 +12,7 @@ const ORDER_TARGETS = [
|
||||
['APPROVED', ['submit', 'approve']],
|
||||
['ACCEPTED', ['submit', 'approve', 'accept']],
|
||||
['PROCESSING', ['submit', 'approve', 'accept', 'start']],
|
||||
['COMPLETED', ['submit', 'approve', 'accept', 'start', 'complete']],
|
||||
['COMPLETED', []],
|
||||
['CANCELLED', ['cancel']],
|
||||
]
|
||||
const INBOUND_FILTER_STATUSES = [
|
||||
@@ -135,6 +135,27 @@ export async function transition(context, token, fixture, orderId, target, actio
|
||||
context.apiSuccess(MODULE, `${target} 样本执行 ${action}`, response)
|
||||
}
|
||||
|
||||
export async function createCompletedOrder(context, runFulfillment = async scope => {
|
||||
const { run } = await import('./phase5-root-fulfillment.mjs')
|
||||
return run(scope)
|
||||
}, prepareCustomer = async scope => {
|
||||
const { run } = await import('./merchant-qualification-fixture.mjs')
|
||||
return run(scope, { publishEnvironment: false })
|
||||
}) {
|
||||
const scope = Object.create(context)
|
||||
scope.marker = `${context.marker}-COMPLETED`
|
||||
scope.context = { ...context.context, f40SignatureOrder: 'ROOT_FIRST' }
|
||||
scope.createdResources = { ...context.createdResources }
|
||||
await prepareCustomer(scope)
|
||||
try { await runFulfillment(scope) }
|
||||
finally { context.createdResources.manualCompletedOrder = scope.createdResources.phase5RootFulfillment }
|
||||
const proof = scope.createdResources.phase5RootFulfillment
|
||||
if (proof?.finalStatus !== 'VERIFIED'
|
||||
|| id(proof.customerId) !== id(scope.context.merchantQualificationFixture?.tenantId)
|
||||
|| !id(proof.rootOrderId)) throw new Error('COMPLETED 样本必须由同客户真实签收及完成Outbox验证产生')
|
||||
return { orderId: id(proof.rootOrderId), tenantId: id(proof.customerId) }
|
||||
}
|
||||
|
||||
async function readOrder(context, fixture, orderId) {
|
||||
const response = await context.request('GET',
|
||||
`/api/platform/v1/orders/first-leg/${query(orderId)}?tenantId=${query(fixture.tenantId)}`)
|
||||
@@ -248,16 +269,18 @@ export async function run(context, matrix = context.createdResources.manualState
|
||||
matrix.pages.unifiedOrders = { requiredStatuses: UNIFIED_FILTER_STATUSES, fixtures: {} }
|
||||
|
||||
for (const [target, actions] of ORDER_TARGETS) {
|
||||
const orderId = await createOrder(context, token, fixture, target)
|
||||
for (const action of actions) await transition(context, token, fixture, orderId, target, action)
|
||||
const { response, detail } = await readOrder(context, fixture, orderId)
|
||||
const completed = target === 'COMPLETED' ? await createCompletedOrder(context) : null
|
||||
const activeFixture = completed ? { ...fixture, tenantId: completed.tenantId } : fixture
|
||||
const orderId = completed?.orderId || await createOrder(context, token, activeFixture, target)
|
||||
for (const action of actions) await transition(context, token, activeFixture, orderId, target, action)
|
||||
const { response, detail } = await readOrder(context, activeFixture, orderId)
|
||||
context.assert(MODULE, `${target} 订单状态样本可从详情打开`, response,
|
||||
id(detail?.order?.id) === orderId && detail?.order?.status === target,
|
||||
`orderId=${orderId}, status=${detail?.order?.status ?? 'missing'}`)
|
||||
result.orders[target] = { orderId, orderNo: detail?.order?.orderNo || null, status: target,
|
||||
result.orders[target] = { orderId, tenantId: activeFixture.tenantId, orderNo: detail?.order?.orderNo || null, status: target,
|
||||
listPath: `/admin/first-leg-orders?status=${target}` }
|
||||
matrix.pages.firstLegOrders.fixtures[target] = {
|
||||
id: orderId, status: target, detailPath: `/orders/${orderId}`,
|
||||
id: orderId, tenantId: activeFixture.tenantId, status: target, detailPath: `/orders/${orderId}`,
|
||||
}
|
||||
|
||||
if (actions.includes('approve')) {
|
||||
@@ -274,7 +297,7 @@ export async function run(context, matrix = context.createdResources.manualState
|
||||
|
||||
for (const [status, sample] of Object.entries(result.orders)) {
|
||||
const response = await context.request('GET',
|
||||
`/api/platform/v1/orders/first-leg?tenantId=${query(fixture.tenantId)}&status=${status}&keyword=${query(sample.orderNo)}&page=1&size=20`)
|
||||
`/api/platform/v1/orders/first-leg?tenantId=${query(sample.tenantId)}&status=${status}&keyword=${query(sample.orderNo)}&page=1&size=20`)
|
||||
const page = context.apiSuccess(MODULE, `${status} 订单可按列表状态筛选`, response)
|
||||
context.assert(MODULE, `${status} 筛选结果包含人工样本`, response,
|
||||
rows(page).some((item) => id(item.id) === sample.orderId), `orderId=${sample.orderId}, total=${page?.total ?? 'n/a'}`)
|
||||
|
||||
Reference in New Issue
Block a user