This commit is contained in:
2026-09-02 14:45:34 +08:00
parent 9ea4ccb9b1
commit 19a6af1c6d
6 changed files with 32 additions and 17 deletions
@@ -43,7 +43,7 @@ async function loginMerchant(context) {
const password = account?.password || process.env.MERCHANT_TEST_PASSWORD || ''
if (!username || !password) throw new Error('缺少客户登录凭据')
const response = await context.request('POST', '/api/auth/login', {
username, password,
loginId: username, password,
}, '')
const token = success(response) ? response.body?.data?.accessToken : null
if (!token) throw new Error(`本轮客户登录失败: requestId=${response?.requestId || 'missing'}, traceId=${response?.traceId || 'missing'}`)
@@ -134,6 +134,16 @@ function routes(context, merchantToken) {
export async function prepare(context) {
const outerMarker = context.marker
const isolatedResourceKeys = ['phase3Loading', 'phase3LoadingCompletedProducer', 'orchestrationFixtures']
const isolatedResourceSnapshot = new Map(isolatedResourceKeys.map((name) => [name, {
present: Object.hasOwn(context.createdResources, name), value: context.createdResources[name],
}]))
const restoreIsolatedResources = () => {
for (const [name, snapshot] of isolatedResourceSnapshot) {
if (snapshot.present) context.createdResources[name] = snapshot.value
else delete context.createdResources[name]
}
}
const restore = await context.preparePhase3LoadingFixture('-CUSTOMS-MIXED', false, {
primary: 'BUY_DECLARATION', incremental: 'TAX_REFUND',
})
@@ -154,6 +164,7 @@ export async function prepare(context) {
if (!source?.loadingPlanId || !source?.containerBookingId || source?.finalStatus !== 'LOADED') {
context.marker = outerMarker
restore()
restoreIsolatedResources()
throw new Error(`混合柜未进入LOADED: planId=${id(source?.loadingPlanId) || 'missing'}, status=${source?.finalStatus || 'missing'}`)
}
const platform = await context.request('GET', `${PLATFORM}/${encodeURIComponent(id(source.loadingPlanId))}`)
@@ -169,6 +180,7 @@ export async function prepare(context) {
if (!buy.length || !refund.length) {
context.marker = outerMarker
restore()
restoreIsolatedResources()
throw new Error(`正式装柜API未形成混合柜: buy=${buy.length}, tax=${refund.length}`)
}
const merchantToken = await loginMerchant(context)
@@ -208,5 +220,6 @@ export async function prepare(context) {
delete context.context.phase3ContainerCustomsRoutes
context.marker = outerMarker
restore()
restoreIsolatedResources()
}
}