Commit d03d6ac3 by 张立顺

test: add order lifecycle environment preflight

1 parent cf45b2a0
...@@ -20,8 +20,9 @@ ...@@ -20,8 +20,9 @@
"test:equity": "node --experimental-detect-module --test packageEquity/tests/**/*.test.mjs", "test:equity": "node --experimental-detect-module --test packageEquity/tests/**/*.test.mjs",
"test:dynamicForm": "node --test packageDynamicForm/tests/**/*.test.mjs", "test:dynamicForm": "node --test packageDynamicForm/tests/**/*.test.mjs",
"test:createOrder": "node --experimental-detect-module --test tabWorkOrder/pages/createOrder/tests/**/*.test.mjs", "test:createOrder": "node --experimental-detect-module --test tabWorkOrder/pages/createOrder/tests/**/*.test.mjs",
"test:orderLifecycle": "node --experimental-detect-module --test tests/order-lifecycle/*.test.mjs", "test:orderLifecycle": "node --experimental-detect-module --test tests/order-lifecycle/*.test.mjs tests/order-lifecycle/e2e/*.test.mjs",
"test:orderLifecycle:contract": "node --experimental-detect-module --test tests/order-lifecycle/apiContracts.test.mjs", "test:orderLifecycle:contract": "node --experimental-detect-module --test tests/order-lifecycle/apiContracts.test.mjs",
"test:orderLifecycle:preflight": "node scripts/order-lifecycle-preflight.mjs",
"test:quotation": "node --experimental-detect-module --test packageEquity/tests/quotation*.test.mjs packageEquity/tests/ruleFn.test.mjs", "test:quotation": "node --experimental-detect-module --test packageEquity/tests/quotation*.test.mjs packageEquity/tests/ruleFn.test.mjs",
"test:components": "node --test tests/popupBehavior.test.mjs tests/calendarMonthMode.test.mjs tests/componentsImageUrl.test.mjs tests/technicianSelect.helpers.test.mjs tests/sideSelectDataSource.test.mjs tests/storePickerConfirm.test.mjs", "test:components": "node --test tests/popupBehavior.test.mjs tests/calendarMonthMode.test.mjs tests/componentsImageUrl.test.mjs tests/technicianSelect.helpers.test.mjs tests/sideSelectDataSource.test.mjs tests/storePickerConfirm.test.mjs",
"gen:component-index": "node scripts/gen-component-page-index.mjs" "gen:component-index": "node scripts/gen-component-page-index.mjs"
......
import { loginAndSelectContext } from '../tests/order-lifecycle/e2e/authContext.mjs'
import { runPreflight } from '../tests/order-lifecycle/e2e/preflight.mjs'
import { loadE2EConfig } from '../tests/order-lifecycle/e2e/testConfig.mjs'
import { loadProjectRopCredentials } from '../tests/order-lifecycle/support/projectRopCredentials.mjs'
import { createRopClient } from '../tests/order-lifecycle/support/ropClient.mjs'
const summarize = report => ({
ok: report.ok,
context: report.context,
resources: {
employee: Boolean(report.resources.employee),
ordinaryGoods: report.resources.ordinaryGoods.length,
packageGoods: Boolean(report.resources.packageGoods),
multiSpecGoods: Boolean(report.resources.multiSpecGoods),
technician: Boolean(report.resources.technician),
serviceItem: Boolean(report.resources.serviceItem),
inventory: report.resources.inventory?.mode ?? null,
constructionPictureUrl: Boolean(report.resources.constructionPictureUrl)
},
missing: report.missing,
diagnostics: report.diagnostics
})
try {
const config = loadE2EConfig(process.env)
const credentials = await loadProjectRopCredentials()
const client = createRopClient({ baseUrl: config.baseUrl, credentials })
const context = await loginAndSelectContext(client, config)
const report = await runPreflight(client, context, {
baseSceneCode: config.baseSceneCode,
constructionImageUrl: config.constructionImageUrl
})
console.log(JSON.stringify(summarize(report), null, 2))
process.exitCode = report.ok ? 0 : 2
} catch (error) {
console.error(
JSON.stringify(
{
ok: false,
error: error instanceof Error ? error.message : 'Unknown preflight failure'
},
null,
2
)
)
process.exitCode = 1
}
const METHODS = {
login: 'dj.api.smartcarlife.sms.login',
listAccounts: 'dj.api.smartcarlife.workWechat.listSelectAccount',
selectAccount: 'dj.api.smartcarlife.workWechat.selectAccountLogin',
listStores: 'dj.api.scenemerchantref.query4SRefByYqShopByLogin',
selectScene: 'dj.api.smartcarlife.selectMerchantScene'
}
const isSuccess = response => response?.code === 0 || response?.code === '0'
const requireSuccess = (method, response) => {
if (!isSuccess(response)) {
const code = response?.code ?? 'missing'
throw new Error(`ROP business call failed: ${method} (code ${code})`)
}
return response.data
}
const listFrom = value => {
if (Array.isArray(value)) return value
if (!value || typeof value !== 'object') return []
for (const key of ['list', 'records', 'rows', 'dataList', 'pageData']) {
if (Array.isArray(value[key])) return value[key]
}
return []
}
const displayName = item =>
String(
item?.merchantName ?? item?.yqMerchantName ?? item?.shopMerchantName ?? ''
).trim()
const stableId = item =>
String(item?.uuid ?? item?.merchantId ?? item?.shopMerchantId ?? item?.id ?? '')
const selectExact = (items, expectedName, label) => {
const candidates = listFrom(items)
const matches = candidates.filter(item => displayName(item) === expectedName)
if (matches.length === 1) return matches[0]
const names = [...new Set(candidates.map(displayName).filter(Boolean))].sort(
(left, right) => left.localeCompare(right, 'zh-CN')
)
if (matches.length === 0) {
throw new Error(
`No exact ${label} match for "${expectedName}". Candidates: ${
names.join(', ') || '(none)'
}`
)
}
const ids = matches.map(stableId).sort().join(', ')
throw new Error(`Duplicate exact ${label} matches for "${expectedName}": ${ids}`)
}
const createContext = ({ sessionId, park, store, user, scene, sceneType }) => {
const context = {
park: { id: park.merchantId, name: displayName(park), accountId: park.uuid },
store: { id: store.merchantId, name: displayName(store) },
user,
scene,
sceneType
}
Object.defineProperty(context, 'sessionId', {
value: sessionId,
enumerable: false,
writable: false,
configurable: false
})
return context
}
export async function loginAndSelectContext(client, config) {
const loginResponse = await client.post(METHODS.login, {
mobile: config.mobile,
code: config.code,
source: 'MINIAPP',
productCode: 'PC00c2'
})
const loginData = requireSuccess(METHODS.login, loginResponse)
let sessionId = loginData?.sessionId
if (!sessionId) {
throw new Error(`ROP response missing session for ${METHODS.login}`)
}
const accountResponse = await client.post(METHODS.listAccounts, { sessionId })
const accountData = requireSuccess(METHODS.listAccounts, accountResponse)
const accountList =
listFrom(accountData?.loginUserInfoList).length > 0
? accountData.loginUserInfoList
: loginData?.loginUserInfoList
const park = selectExact(accountList, config.yqName, 'park account')
if (!park.uuid) {
throw new Error(`Exact park account is missing uuid: ${config.yqName}`)
}
const selectedAccountResponse = await client.post(METHODS.selectAccount, {
id: park.uuid,
sessionId
})
const selectedAccountData = requireSuccess(
METHODS.selectAccount,
selectedAccountResponse
)
sessionId = selectedAccountData?.sessionId || sessionId
const user = listFrom(selectedAccountData?.loginUserInfoList)[0] || park
const storeResponse = await client.post(METHODS.listStores, {
merchantId: park.merchantId,
staffUUID: user.uuid || park.uuid,
sessionId
})
const storeData = requireSuccess(METHODS.listStores, storeResponse)
const store = selectExact(storeData, config.storeName, 'store')
const sceneResponse = await client.post(METHODS.selectScene, {
merchantId: store.merchantId,
merchantName: displayName(store),
sceneType: config.sceneType,
sessionId
})
const scene = requireSuccess(METHODS.selectScene, sceneResponse)
return createContext({
sessionId,
park,
store,
user,
scene,
sceneType: config.sceneType
})
}
export { METHODS, listFrom, selectExact }
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { loginAndSelectContext } from './authContext.mjs'
import { loadE2EConfig } from './testConfig.mjs'
const BASE_URL = 'http://dj.test.glsx.com.cn/rop-dj-car-boutique'
const validEnv = () => ({
RUN_ORDER_E2E: '1',
ORDER_E2E_BASE_URL: BASE_URL,
ORDER_E2E_MOBILE: 'runtime-mobile',
ORDER_E2E_CODE: 'runtime-code',
ORDER_E2E_YQ_NAME: '目标园区',
ORDER_E2E_STORE_NAME: '目标门店'
})
const createFakeClient = ({ parks, stores, failMethod } = {}) => {
const calls = []
const parkList =
parks ??
[
{ uuid: 'park-partial', merchantId: 10, merchantName: '目标园区分店' },
{ uuid: 'park-exact', merchantId: 11, merchantName: '目标园区' }
]
const storeList =
stores ??
[
{ merchantId: 21, merchantName: '目标门店分店', yqMerchantId: 11 },
{ merchantId: 22, merchantName: '目标门店', yqMerchantId: 11 }
]
return {
calls,
async post(method, payload = {}) {
calls.push({ method, payload })
if (method === failMethod) {
return { code: -1, message: 'session-private', data: null }
}
if (method === 'dj.api.smartcarlife.sms.login') {
return {
code: 0,
data: { sessionId: 'session-private', loginUserInfoList: parkList }
}
}
if (method === 'dj.api.smartcarlife.workWechat.listSelectAccount') {
return {
code: 0,
data: { sessionId: 'session-private', loginUserInfoList: parkList }
}
}
if (method === 'dj.api.smartcarlife.workWechat.selectAccountLogin') {
const selected = parkList.find(item => item.uuid === payload.id)
return {
code: 0,
data: {
sessionId: 'session-private-after-account',
loginUserInfoList: [selected]
}
}
}
if (method === 'dj.api.scenemerchantref.query4SRefByYqShopByLogin') {
return { code: 0, data: storeList }
}
if (method === 'dj.api.smartcarlife.selectMerchantScene') {
return { code: 0, data: { loginRoleOnSelectMerchant: 4 } }
}
throw new Error(`Unexpected fake method: ${method}`)
}
}
}
describe('order lifecycle runtime configuration', () => {
it('IT-OL-CONTEXT-001: only non-sensitive scene and payment values default', () => {
const config = loadE2EConfig(validEnv())
assert.equal(config.sceneType, 1)
assert.equal(config.payType, 2)
assert.equal(config.mobile, 'runtime-mobile')
assert.equal(config.code, 'runtime-code')
assert.equal(config.yqName, '目标园区')
assert.equal(config.storeName, '目标门店')
})
it('IT-OL-CONTEXT-002: missing sensitive runtime values fail by variable name', () => {
const env = validEnv()
delete env.ORDER_E2E_MOBILE
delete env.ORDER_E2E_CODE
assert.throws(() => loadE2EConfig(env), error => {
assert.match(error.message, /ORDER_E2E_MOBILE/)
assert.match(error.message, /ORDER_E2E_CODE/)
assert.doesNotMatch(error.message, /runtime-mobile|runtime-code/)
return true
})
})
})
describe('login and exact context selection', () => {
it('IT-OL-CONTEXT-003: exact names win over partial names', async () => {
const client = createFakeClient()
const context = await loginAndSelectContext(client, loadE2EConfig(validEnv()))
assert.equal(context.park.id, 11)
assert.equal(context.park.name, '目标园区')
assert.equal(context.store.id, 22)
assert.equal(context.store.name, '目标门店')
assert.equal(context.sceneType, 1)
})
it('IT-OL-CONTEXT-004: account selection occurs before store lookup', async () => {
const client = createFakeClient()
await loginAndSelectContext(client, loadE2EConfig(validEnv()))
const methods = client.calls.map(item => item.method)
assert.ok(
methods.indexOf('dj.api.smartcarlife.workWechat.selectAccountLogin') <
methods.indexOf('dj.api.scenemerchantref.query4SRefByYqShopByLogin')
)
const selectAccount = client.calls.find(item =>
item.method.endsWith('selectAccountLogin')
)
assert.deepEqual(selectAccount.payload, {
id: 'park-exact',
sessionId: 'session-private'
})
})
it('IT-OL-CONTEXT-005: scene selection uses the exact store and premium scene', async () => {
const client = createFakeClient()
await loginAndSelectContext(client, loadE2EConfig(validEnv()))
const sceneCall = client.calls.find(item =>
item.method.endsWith('selectMerchantScene')
)
assert.deepEqual(sceneCall.payload, {
merchantId: 22,
merchantName: '目标门店',
sceneType: 1,
sessionId: 'session-private-after-account'
})
})
it('IT-OL-CONTEXT-006: no exact match reports sorted candidates', async () => {
const client = createFakeClient()
const config = { ...loadE2EConfig(validEnv()), yqName: '不存在园区' }
await assert.rejects(loginAndSelectContext(client, config), error => {
assert.match(error.message, /不存在园区/)
assert.ok(
error.message.indexOf('目标园区') < error.message.indexOf('目标园区分店')
)
assert.doesNotMatch(error.message, /session-private/)
return true
})
})
it('IT-OL-CONTEXT-007: duplicate exact names report candidate ids', async () => {
const client = createFakeClient({
parks: [
{ uuid: 'duplicate-a', merchantId: 31, merchantName: '目标园区' },
{ uuid: 'duplicate-b', merchantId: 32, merchantName: '目标园区' }
]
})
await assert.rejects(
loginAndSelectContext(client, loadE2EConfig(validEnv())),
/duplicate-a.*duplicate-b/
)
})
it('IT-OL-CONTEXT-008: business errors never include session data', async () => {
const client = createFakeClient({
failMethod: 'dj.api.smartcarlife.workWechat.listSelectAccount'
})
await assert.rejects(
loginAndSelectContext(client, loadE2EConfig(validEnv())),
error => {
assert.match(error.message, /listSelectAccount/)
assert.doesNotMatch(error.message, /session-private/)
return true
}
)
})
it('IT-OL-CONTEXT-009: session is non-enumerable in returned context', async () => {
const client = createFakeClient()
const context = await loginAndSelectContext(client, loadE2EConfig(validEnv()))
assert.equal(context.sessionId, 'session-private-after-account')
assert.doesNotMatch(JSON.stringify(context), /session-private/)
assert.ok(!Object.keys(context).includes('sessionId'))
})
})
export const PREFLIGHT_METHODS = {
employees: 'dj.api.smartcarlife.employee.getByMerchantId',
goods: 'dj.api.smartcarlife.selectOrderGoods.list',
technicians: 'dj.api.smartcarlife.roleTechnician.list.effective',
serviceItems: 'dj.api.carboutique.construction.item.group.list',
filmRolls: 'dj.api.smarcarlife.stock.filmroll.list'
}
const isSuccess = response => response?.code === 0 || response?.code === '0'
const listFrom = value => {
if (Array.isArray(value)) return value
if (!value || typeof value !== 'object') return []
for (const key of ['list', 'records', 'rows', 'dataList', 'pageData']) {
if (Array.isArray(value[key])) return value[key]
}
return []
}
const normalizeStaff = staff => {
if (!staff) return null
const id = staff.userId ?? staff.bussinessId ?? staff.id
if (id === undefined || id === null || id === '') return null
return {
id,
uuid: staff.uuid,
name: staff.name ?? staff.employeeName ?? staff.staffName,
merchantId: staff.merchantId
}
}
const normalizeTechnician = technician => {
if (!technician) return null
const id = technician.userId ?? technician.technicianId ?? technician.id
if (id === undefined || id === null || id === '') return null
return {
id,
uuid: technician.uuid,
name:
technician.name ?? technician.technicianName ?? technician.employeeName
}
}
const normalizeServiceItem = groups => {
for (const group of listFrom(groups)) {
for (const item of listFrom(group.serviceItemList ?? group.detailList)) {
if (item?.id !== undefined && item?.id !== null) {
return {
id: item.id,
name: item.serviceItemName ?? item.itemName ?? item.name,
categoryName: group.categoryName,
groupName: group.itemName
}
}
}
}
return null
}
const findImageUrl = value => {
if (!value || typeof value !== 'object') return null
for (const [key, item] of Object.entries(value)) {
if (
typeof item === 'string' &&
/^https?:\/\//i.test(item) &&
/image|picture|photo|url|logo|cover/i.test(key)
) {
return item
}
}
for (const item of Object.values(value)) {
if (item && typeof item === 'object') {
const found = findImageUrl(item)
if (found) return found
}
}
return null
}
const missingItem = (resource, method, neededField) => ({
resource,
method,
neededField
})
export async function runPreflight(client, context, options = {}) {
const diagnostics = []
const missing = []
const query = async (resource, method, payload) => {
const response = await client.post(method, payload)
if (!isSuccess(response)) {
diagnostics.push({
resource,
method,
ok: false,
code: response?.code ?? 'missing'
})
return null
}
const data = response.data
diagnostics.push({
resource,
method,
ok: true,
count: listFrom(data).length
})
return data
}
const common = { sessionId: context.sessionId }
const employeeData = await query('employee', PREFLIGHT_METHODS.employees, {
merchantId: context.store.id,
sceneList: [context.sceneType],
...common
})
const employeeList = listFrom(employeeData)
const selectedEmployee =
employeeList.find(item => item.uuid && item.uuid === context.user?.uuid) ??
employeeList[0]
const employee = normalizeStaff(selectedEmployee)
if (!employee) {
missing.push(
missingItem('employee', PREFLIGHT_METHODS.employees, 'sellerUserId/employee.id')
)
}
const catalog = listFrom(
await query('goodsCatalog', PREFLIGHT_METHODS.goods, {
merchantId: context.store.id,
sceneType: context.sceneType,
baseSceneCode: options.baseSceneCode ?? '',
...common
})
)
const ordinaryGoods = catalog.filter(item => {
const goods = item?.goods
const price = goods?.sellPrice ?? goods?.upgradePrice
return (
Number(item?.goodsFlag) === 1 &&
goods?.merchantGoodsId !== undefined &&
Number.isFinite(Number(price))
)
})
if (ordinaryGoods.length < 2) {
missing.push(
missingItem(
'ordinaryGoods',
PREFLIGHT_METHODS.goods,
'2 x merchantGoodsId/sellPrice'
)
)
}
const multiSpecGoods =
catalog.find(item => Number(item?.goodsFlag) === 2) ?? null
const packageGoods = catalog.find(item => Number(item?.goodsFlag) === 3) ?? null
const technicianData = await query(
'technician',
PREFLIGHT_METHODS.technicians,
{ yqMerchantId: context.park.id, ...common }
)
const technician = normalizeTechnician(listFrom(technicianData)[0])
if (!technician) {
missing.push(
missingItem('technician', PREFLIGHT_METHODS.technicians, 'mainTechnicianList[].id')
)
}
const serviceData = await query(
'serviceItem',
PREFLIGHT_METHODS.serviceItems,
{ subOrderCodeList: [], ...common }
)
const serviceItem = normalizeServiceItem(serviceData)
if (!serviceItem) {
missing.push(
missingItem('serviceItem', PREFLIGHT_METHODS.serviceItems, 'serviceItemList[].id')
)
}
let inventory = null
const firstOrdinary = ordinaryGoods[0]?.goods
if (firstOrdinary?.upgradeGoodsId !== undefined) {
const filmRolls = listFrom(
await query('inventory', PREFLIGHT_METHODS.filmRolls, {
yqMerchantId: context.park.id,
merchantId: context.store.id,
upgradeGoodsId: firstOrdinary.upgradeGoodsId,
...common
})
)
inventory = filmRolls.length
? { mode: 'film-roll', value: filmRolls[0], goods: firstOrdinary }
: { mode: 'manual', goods: firstOrdinary }
}
if (!inventory) {
missing.push(
missingItem(
'inventory',
PREFLIGHT_METHODS.filmRolls,
'upgradeGoodsId or hand-entered outbound candidate'
)
)
}
const constructionPictureUrl =
options.constructionImageUrl || findImageUrl(catalog)
if (!constructionPictureUrl) {
missing.push(
missingItem(
'constructionPictureUrl',
PREFLIGHT_METHODS.goods,
'pictureList[].url'
)
)
}
return {
ok: missing.length === 0,
context: {
park: context.park,
store: context.store,
sceneType: context.sceneType
},
resources: {
employee,
seller: employee,
ordinaryGoods,
packageGoods,
multiSpecGoods,
technician,
serviceItem,
inventory,
constructionPictureUrl
},
missing,
diagnostics
}
}
export { findImageUrl, listFrom }
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { PREFLIGHT_METHODS, runPreflight } from './preflight.mjs'
const context = {
park: { id: 11, name: '目标园区' },
store: { id: 22, name: '目标门店' },
user: { uuid: 'staff-1', name: '测试员工' },
sceneType: 1
}
Object.defineProperty(context, 'sessionId', {
value: 'session-private',
enumerable: false
})
const goods = [
{
goodsFlag: 1,
goods: {
merchantGoodsId: 101,
upgradeGoodsId: 1001,
goodsName: '普通商品一',
sellPrice: 100,
imageUrl: 'https://image.test/goods-1.png'
}
},
{
goodsFlag: 1,
goods: {
merchantGoodsId: 102,
upgradeGoodsId: 1002,
goodsName: '普通商品二',
sellPrice: 200
}
},
{ goodsFlag: 2, multipleSpecificationsGoods: { merchantGoodsId: 103 } },
{ goodsFlag: 3, packageGoods: { packageGoodsId: 104, goodsList: [] } }
]
const createClient = (overrides = {}) => ({
calls: [],
async post(method, payload) {
this.calls.push({ method, payload })
if (overrides[method]) return overrides[method]
if (method === PREFLIGHT_METHODS.employees) {
return {
code: 0,
data: [{ uuid: 'staff-1', userId: 501, name: '测试员工', merchantId: 11 }]
}
}
if (method === PREFLIGHT_METHODS.goods) return { code: 0, data: goods }
if (method === PREFLIGHT_METHODS.technicians) {
return { code: 0, data: [{ uuid: 'tech-1', userId: 601, name: '测试技师' }] }
}
if (method === PREFLIGHT_METHODS.serviceItems) {
return {
code: 0,
data: [
{
categoryName: '装饰',
itemName: '安装',
serviceItemList: [{ id: 701, serviceItemName: '精品安装' }]
}
]
}
}
if (method === PREFLIGHT_METHODS.filmRolls) {
return { code: 0, data: ['ROLL-TEST-1'] }
}
throw new Error(`Unexpected fake method: ${method}`)
}
})
describe('order lifecycle capability preflight', () => {
it('IT-OL-PREFLIGHT-001: ready report exposes required resources and optional catalog types', async () => {
const client = createClient()
const report = await runPreflight(client, context)
assert.equal(report.ok, true)
assert.deepEqual(report.missing, [])
assert.equal(report.resources.ordinaryGoods.length, 2)
assert.equal(report.resources.packageGoods.goodsFlag, 3)
assert.equal(report.resources.multiSpecGoods.goodsFlag, 2)
assert.equal(report.resources.employee.id, 501)
assert.equal(report.resources.technician.id, 601)
assert.equal(report.resources.serviceItem.id, 701)
assert.equal(report.resources.inventory.mode, 'film-roll')
assert.equal(
report.resources.constructionPictureUrl,
'https://image.test/goods-1.png'
)
})
it('IT-OL-PREFLIGHT-002: missing requirements name query method and next field', async () => {
const client = createClient({
[PREFLIGHT_METHODS.goods]: { code: 0, data: [] },
[PREFLIGHT_METHODS.technicians]: { code: 0, data: [] },
[PREFLIGHT_METHODS.serviceItems]: { code: 0, data: [] }
})
const report = await runPreflight(client, context)
assert.equal(report.ok, false)
assert.ok(report.missing.some(item => item.resource === 'ordinaryGoods'))
assert.ok(report.missing.some(item => item.resource === 'technician'))
assert.ok(report.missing.some(item => item.resource === 'serviceItem'))
for (const item of report.missing) {
assert.ok(item.method)
assert.ok(item.neededField)
}
})
it('IT-OL-PREFLIGHT-003: package and multi-spec goods are optional diagnostics', async () => {
const client = createClient({
[PREFLIGHT_METHODS.goods]: { code: 0, data: goods.slice(0, 2) }
})
const report = await runPreflight(client, context)
assert.equal(report.ok, true)
assert.equal(report.resources.packageGoods, null)
assert.equal(report.resources.multiSpecGoods, null)
assert.ok(!report.missing.some(item => item.resource === 'packageGoods'))
assert.ok(!report.missing.some(item => item.resource === 'multiSpecGoods'))
})
it('IT-OL-PREFLIGHT-004: business query failure is diagnostic and contains no session', async () => {
const client = createClient({
[PREFLIGHT_METHODS.employees]: {
code: -1,
message: 'session-private',
data: null
}
})
const report = await runPreflight(client, context)
assert.equal(report.ok, false)
assert.ok(report.missing.some(item => item.resource === 'employee'))
assert.ok(report.diagnostics.some(item => item.code === -1))
assert.doesNotMatch(JSON.stringify(report), /session-private/)
})
})
import { assertAllowedE2EEnvironment } from '../support/environmentGuard.mjs'
const REQUIRED_VARIABLES = [
'RUN_ORDER_E2E',
'ORDER_E2E_BASE_URL',
'ORDER_E2E_MOBILE',
'ORDER_E2E_CODE',
'ORDER_E2E_YQ_NAME',
'ORDER_E2E_STORE_NAME'
]
export function loadE2EConfig(env = process.env) {
const missing = REQUIRED_VARIABLES.filter(name => !String(env[name] ?? '').trim())
if (missing.length) {
throw new Error(`Missing required E2E environment variables: ${missing.join(', ')}`)
}
const baseUrl = assertAllowedE2EEnvironment({
baseUrl: env.ORDER_E2E_BASE_URL,
enabled: env.RUN_ORDER_E2E === '1'
}).toString()
return Object.freeze({
enabled: true,
baseUrl,
mobile: env.ORDER_E2E_MOBILE,
code: env.ORDER_E2E_CODE,
yqName: env.ORDER_E2E_YQ_NAME.trim(),
storeName: env.ORDER_E2E_STORE_NAME.trim(),
baseSceneCode: String(env.ORDER_E2E_BASE_SCENE_CODE ?? '').trim(),
constructionImageUrl: String(
env.ORDER_E2E_CONSTRUCTION_IMAGE_URL ?? ''
).trim(),
sceneType: 1,
payType: 2
})
}
export { REQUIRED_VARIABLES }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!