test(acceptance): align current gateway contracts
This commit is contained in:
@@ -41,6 +41,12 @@ async function overseasMutation(context, method, name, path, body) {
|
||||
context.addStep(MODULE, name, response, passed, trace(response), OPTIONS)
|
||||
return { response, data: passed ? response.body?.data : null }
|
||||
}
|
||||
async function domesticMutation(context, method, name, path, body) {
|
||||
const response = await context.request(method, path, body)
|
||||
const passed = response?.http === 200 && String(response?.body?.code) === '200'
|
||||
context.addStep(MODULE, name, response, passed, trace(response), OPTIONS)
|
||||
return { response, data: passed ? response.body?.data : null }
|
||||
}
|
||||
async function overseasCsv(context, name, path) {
|
||||
const response = await context.requestOverseasBinary('GET', path)
|
||||
context.addStep(MODULE, name, response,
|
||||
@@ -309,9 +315,9 @@ async function verifyRelabelLifecycle(context, customerId, warehouseId) {
|
||||
async function createWarehouseFixture(context, customerId) {
|
||||
const suffix = String(context.marker || '').replace(/[^A-Za-z0-9]/g, '').slice(-20).toUpperCase()
|
||||
const payload = {
|
||||
customerId, warehouseCode: `P4W-${suffix}`.slice(0, 50), warehouseName: `${context.marker} 海外仓`,
|
||||
tenantId: 0, warehouseCode: `P4W-${suffix}`.slice(0, 50), warehouseName: `${context.marker} 海外仓`,
|
||||
warehouseType: 'OVERSEAS', countryCode: 'US', timezone: 'America/Los_Angeles',
|
||||
contactName: 'Phase4 QA', contactPhone: '+1-213-555-0188', contactEmail: null,
|
||||
contactName: 'Phase4 QA', contactPhone: '12135550188', contactEmail: null,
|
||||
status: 'ACTIVE', remark: `${context.marker}-warehouse-fixture`,
|
||||
address: { addressType: 'WAREHOUSE', countryCode: 'US', stateProvince: 'California', city: 'Los Angeles',
|
||||
district: 'Commerce', postalCode: '90040', addressLine1: '501 Phase Four Warehouse Avenue',
|
||||
@@ -319,22 +325,22 @@ async function createWarehouseFixture(context, customerId) {
|
||||
capabilities: [{ capabilityCode: 'STORAGE', capabilityName: 'Storage', enabled: true,
|
||||
cutoffTime: null, description: `${context.marker} acceptance` }],
|
||||
}
|
||||
const created = await overseasMutation(context, 'POST', '创建本轮客户海外仓', '/api/platform/v1/warehouse-admin', payload)
|
||||
const created = await domesticMutation(context, 'POST', '创建本轮客户海外仓', '/api/platform/v1/warehouse-admin', payload)
|
||||
const warehouseId = id(created.data)
|
||||
context.assert(MODULE, '客户海外仓创建返回长ID', created.response, longId(warehouseId),
|
||||
`warehouseId=${warehouseId || 'missing'}, customerId=${customerId}; ${trace(created.response)}`, OPTIONS)
|
||||
if (!warehouseId) return null
|
||||
const detail = await overseasGet(context, '查询本轮客户海外仓详情', query(`/api/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}`, { customerId }))
|
||||
context.assert(MODULE, '本轮客户海外仓归属和状态正确', detail.response,
|
||||
const detail = await domesticGet(context, '查询本轮公共海外仓详情', query(`/api/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}`, { tenantId: 0 }))
|
||||
context.assert(MODULE, '本轮公共海外仓类型和状态正确', detail.response,
|
||||
id(detail.data?.warehouse?.id || detail.data?.id) === warehouseId
|
||||
&& id(detail.data?.warehouse?.customerId || detail.data?.customerId) === customerId
|
||||
&& (detail.data?.warehouse?.warehouseType || detail.data?.warehouseType) === 'OVERSEAS'
|
||||
&& (detail.data?.warehouse?.status || detail.data?.status) === 'ACTIVE',
|
||||
`warehouseId=${warehouseId}, customerId=${id(detail.data?.warehouse?.customerId || detail.data?.customerId) || 'missing'}; ${trace(detail.response)}`, OPTIONS)
|
||||
`warehouseId=${warehouseId}, warehouseType=${detail.data?.warehouse?.warehouseType || detail.data?.warehouseType || 'missing'}; ${trace(detail.response)}`, OPTIONS)
|
||||
return { id: warehouseId, customerId, warehouseCode: payload.warehouseCode, warehouseName: payload.warehouseName, status: 'ACTIVE' }
|
||||
}
|
||||
|
||||
async function retireWarehouseFixture(context, customerId, warehouseId) {
|
||||
const retired = await context.requestOverseas('PATCH', query(`/api/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/status`, { customerId, status: 'INACTIVE' }))
|
||||
const retired = await context.request('PATCH', query(`/api/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/status`, { tenantId: 0, status: 'INACTIVE' }))
|
||||
context.addStep(MODULE, '本轮客户海外仓已停用收口', retired,
|
||||
retired?.http === 200 && String(retired?.body?.code) === '200', trace(retired), OPTIONS)
|
||||
}
|
||||
@@ -400,23 +406,21 @@ async function verifyPalletLifecycle(context, warehouseId) {
|
||||
}
|
||||
|
||||
async function findWarehouse(context, tenants, preferredCustomerId) {
|
||||
const candidates = [...new Set([preferredCustomerId, ...tenants.map((item) => id(item?.id)).filter(longId)])]
|
||||
let lastResponse = null
|
||||
for (const customerId of candidates) {
|
||||
const result = await overseasGet(context, `查询客户${customerId}可用海外仓`, query('/api/platform/v1/warehouse-admin', { customerId, page: 1, size: 100, status: 'ACTIVE' }))
|
||||
assertPage(context, `客户${customerId}可用海外仓`, result)
|
||||
lastResponse = result.response
|
||||
const warehouse = records(result.data).find((item) => longId(item?.id) && item?.status === 'ACTIVE')
|
||||
if (warehouse) {
|
||||
context.assert(MODULE, '海外仓关键字段正确', result.response,
|
||||
nonBlank(warehouse.warehouseCode) && nonBlank(warehouse.warehouseName),
|
||||
`warehouseId=${id(warehouse.id)}, code=${warehouse.warehouseCode || 'missing'}; ${trace(result.response)}`, OPTIONS)
|
||||
const detail = await overseasGet(context, '查询海外仓详情', query(`/api/platform/v1/warehouse-admin/${encodeURIComponent(id(warehouse.id))}`, { customerId }))
|
||||
context.assert(MODULE, '海外仓详情对应列表记录', detail.response,
|
||||
id(detail.data?.warehouse?.id || detail.data?.id) === id(warehouse.id),
|
||||
`listId=${id(warehouse.id)}, detailId=${id(detail.data?.warehouse?.id || detail.data?.id) || 'missing'}; ${trace(detail.response)}`, OPTIONS)
|
||||
return warehouse
|
||||
}
|
||||
const result = await domesticGet(context, '查询可用公共海外仓', query('/api/platform/v1/warehouse-admin', {
|
||||
tenantId: 0, warehouseType: 'OVERSEAS', page: 1, size: 100, status: 'ACTIVE',
|
||||
}))
|
||||
assertPage(context, '可用公共海外仓', result)
|
||||
const warehouse = records(result.data).find((item) => longId(item?.id)
|
||||
&& item?.status === 'ACTIVE' && item?.warehouseType === 'OVERSEAS')
|
||||
if (warehouse) {
|
||||
context.assert(MODULE, '海外仓关键字段正确', result.response,
|
||||
nonBlank(warehouse.warehouseCode) && nonBlank(warehouse.warehouseName),
|
||||
`warehouseId=${id(warehouse.id)}, code=${warehouse.warehouseCode || 'missing'}; ${trace(result.response)}`, OPTIONS)
|
||||
const detail = await domesticGet(context, '查询海外仓详情', query(`/api/platform/v1/warehouse-admin/${encodeURIComponent(id(warehouse.id))}`, { tenantId: 0 }))
|
||||
context.assert(MODULE, '海外仓详情对应列表记录', detail.response,
|
||||
id(detail.data?.warehouse?.id || detail.data?.id) === id(warehouse.id),
|
||||
`listId=${id(warehouse.id)}, detailId=${id(detail.data?.warehouse?.id || detail.data?.id) || 'missing'}; ${trace(detail.response)}`, OPTIONS)
|
||||
return warehouse
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user