stabilize full admin fixture transport and state checks
This commit is contained in:
@@ -21,6 +21,13 @@ function records(value) { return Array.isArray(value?.records) ? value.records :
|
||||
function pageOk(value) { return Array.isArray(value?.records) && Number.isFinite(Number(value?.total)) }
|
||||
function success(response) { return Boolean(response) && response.http === 200 && String(response.body?.code) === '200' }
|
||||
function sleep(milliseconds) { return new Promise((resolve) => setTimeout(resolve, milliseconds)) }
|
||||
async function requestTransportRetry(context, method, path, body, token) {
|
||||
for (let attempt = 1; attempt <= 3; attempt += 1) {
|
||||
const response = await request(context, method, path, body, token)
|
||||
if (response?.http !== 0 || attempt === 3) return response
|
||||
await sleep(500 * attempt)
|
||||
}
|
||||
}
|
||||
function rotate(values, offset) {
|
||||
if (!Array.isArray(values) || values.length < 2) return Array.isArray(values) ? [...values] : []
|
||||
const shift = Math.abs(Number(offset) || 0) % values.length
|
||||
@@ -250,7 +257,7 @@ async function assertProductImageDownload(context, merchantToken, fileId) {
|
||||
async function loadMasterData(context, merchantToken) {
|
||||
const destinationType = requestedOrderDestinationType(context)
|
||||
const fixedRoute = context.context?.waitSplitRoute || {}
|
||||
const domesticResponse = await request(context, 'GET',
|
||||
const domesticResponse = await requestTransportRetry(context, 'GET',
|
||||
'/api/merchant/v1/warehouses?page=1&size=200&status=ACTIVE&warehouseType=DOMESTIC', undefined, merchantToken)
|
||||
const domesticPage = context.apiSuccess(MODULE, 'Client 查询国内收货仓', domesticResponse)
|
||||
context.assert(MODULE, '存在可用国内收货仓', domesticResponse, records(domesticPage).length > 0,
|
||||
@@ -259,7 +266,7 @@ async function loadMasterData(context, merchantToken) {
|
||||
let destinationResponse = null
|
||||
let destinationPage = null
|
||||
if (destinationType !== 'PRIVATE') {
|
||||
destinationResponse = await request(context, 'GET',
|
||||
destinationResponse = await requestTransportRetry(context, 'GET',
|
||||
`/api/merchant/v1/warehouses?page=1&size=200&status=ACTIVE&warehouseType=${encodeURIComponent(destinationType)}`,
|
||||
undefined, merchantToken)
|
||||
destinationPage = context.apiSuccess(MODULE, `Client 查询 ${destinationType} 目的仓`, destinationResponse)
|
||||
@@ -269,7 +276,7 @@ async function loadMasterData(context, merchantToken) {
|
||||
const receivings = records(domesticPage).filter((warehouse) => warehouse?.status === 'ACTIVE')
|
||||
let destinations = eligibleOrderDestinations(records(destinationPage), destinationType)
|
||||
if (Number(destinationPage?.total) > destinations.length) {
|
||||
const nextResponse = await request(context, 'GET',
|
||||
const nextResponse = await requestTransportRetry(context, 'GET',
|
||||
`/api/merchant/v1/warehouses?page=2&size=200&status=ACTIVE&warehouseType=${encodeURIComponent(destinationType)}`,
|
||||
undefined, merchantToken)
|
||||
const nextPage = context.apiSuccess(MODULE, `Client 查询 ${destinationType} 目的仓第二页`, nextResponse)
|
||||
|
||||
Reference in New Issue
Block a user