fix(test): resolve loading customer credentials per run
This commit is contained in:
@@ -7,12 +7,19 @@ import { createHash } from 'node:crypto'
|
||||
|
||||
const MODULE = 'phase3-loading'
|
||||
const OPTIONS = { scenario: 'phase3-split-preload-loading', deploymentBlocker: true }
|
||||
const MERCHANT_USERNAME = process.env.MERCHANT_TEST_USERNAME || ''
|
||||
const MERCHANT_PASSWORD = process.env.MERCHANT_TEST_PASSWORD || ''
|
||||
const MATSON_SUPPLIER_NAME = 'MATSON 开发联调船司'
|
||||
const LATE_CONTAINER_GATE_ONLY = process.env.LATE_CONTAINER_GATE_ONLY === '1'
|
||||
|
||||
function id(value) { return value == null ? '' : String(value) }
|
||||
export function loadingMerchantCredentials(context, environment = process.env) {
|
||||
const fixture = context.context?.merchantQualificationFixture
|
||||
const options = context.options || {}
|
||||
const selected = fixture || (options.merchantUsername || options.merchantPassword
|
||||
? { username: options.merchantUsername, password: options.merchantPassword }
|
||||
: { username: environment.MERCHANT_TEST_USERNAME, password: environment.MERCHANT_TEST_PASSWORD })
|
||||
if (!selected.username || !selected.password) throw new Error('装柜验收当前运行缺少完整客户登录凭据')
|
||||
return { username: selected.username, password: selected.password }
|
||||
}
|
||||
export function loadingBookingCustomerFields(scope = 'CUSTOMER', customerId, customerName) {
|
||||
if (scope === 'PLATFORM') return {}
|
||||
if (scope !== 'CUSTOMER') throw new Error('三期订舱范围必须明确为 CUSTOMER 或 PLATFORM')
|
||||
@@ -184,6 +191,7 @@ function taskItemsSignature(task) {
|
||||
}
|
||||
|
||||
export async function run(context) {
|
||||
const merchantCredentials = loadingMerchantCredentials(context)
|
||||
const source = fixture(context)
|
||||
const tenantId = id(source?.tenantId)
|
||||
const inboundId = id(source?.inboundId)
|
||||
@@ -940,12 +948,12 @@ export async function run(context) {
|
||||
}
|
||||
|
||||
const merchantLogin = await context.request('POST', '/api/auth/login', {
|
||||
loginId: MERCHANT_USERNAME, password: MERCHANT_PASSWORD,
|
||||
loginId: merchantCredentials.username, password: merchantCredentials.password,
|
||||
}, '')
|
||||
const merchantToken = merchantLogin.http === 200 && codeOf(merchantLogin) === '200'
|
||||
? merchantLogin.body?.data?.accessToken : null
|
||||
context.addStep(MODULE, '取得客户侧隔离令牌用于 PDA 批次越权验证', merchantLogin,
|
||||
Boolean(merchantToken), `username=${MERCHANT_USERNAME}`, OPTIONS)
|
||||
Boolean(merchantToken), 'current-run customer credentials', OPTIONS)
|
||||
const customerIsolatedBatch = merchantToken
|
||||
? await request(context, 'POST', batchPath, batchPayload, {
|
||||
Authorization: `Bearer ${merchantToken}`,
|
||||
|
||||
Reference in New Issue
Block a user