fix(acceptance): reuse initialized pallet fixtures
This commit is contained in:
@@ -30,13 +30,6 @@ function validPdf(response) {
|
||||
|
||||
async function reusablePallets(context, warehouseId) {
|
||||
const cacheKey = asId(warehouseId)
|
||||
const override = context.context?.measurementPalletOverride
|
||||
if (asId(override?.warehouseId) === cacheKey && asId(override?.id)
|
||||
&& String(override?.code || '').trim()) {
|
||||
context.assert(MODULE, '使用编排层提供的本轮专用称重托盘', null, true,
|
||||
`warehouseId=${warehouseId}, palletId=${asId(override.id)}`, OPTIONS)
|
||||
return [{ id: asId(override.id), code: String(override.code) }]
|
||||
}
|
||||
const allowAnyExistingPallet = context.context?.allowAnyExistingPallet === true
|
||||
const scopedCacheKey = `${cacheKey}:${allowAnyExistingPallet ? 'any' : 'fixed'}`
|
||||
if (reusablePalletsByWarehouse.has(scopedCacheKey)) return reusablePalletsByWarehouse.get(scopedCacheKey)
|
||||
@@ -64,29 +57,11 @@ async function reusablePallets(context, warehouseId) {
|
||||
const exact = (page?.records || []).find((item) => asId(item?.warehouseId) === cacheKey
|
||||
&& String(item?.palletCode || '') === palletCode && asId(item?.id))
|
||||
context.assert(MODULE, `查询原有称重托盘 ${palletCode}`, response, true,
|
||||
`warehouseId=${warehouseId}, matched=${exact?.palletCode || 'missing'}, fallback=${exact ? 'not-needed' : 'create-marker-owned'}`, OPTIONS)
|
||||
`warehouseId=${warehouseId}, matched=${exact?.palletCode || 'missing'}, fallback=disabled`, OPTIONS)
|
||||
if (!exact) {
|
||||
// A newly selected development warehouse may not have the historical fixture pallets.
|
||||
// Create one marker-owned pallet through the public platform API rather than coupling
|
||||
// measurement acceptance to another warehouse's seed data.
|
||||
const createResponse = await context.request('POST', '/api/platform/v1/pallets?tenantId=0', {
|
||||
warehouseId, palletType: 'STANDARD', capacityCbm: 1.5, weightKg: 25,
|
||||
color: 'ORANGE', remark: `${context.marker}-measurement-fixture`,
|
||||
})
|
||||
const createdId = asId(context.apiSuccess(MODULE, '创建本轮称重托盘', createResponse,
|
||||
`warehouseId=${warehouseId}`, OPTIONS))
|
||||
if (!createdId) return null
|
||||
const detailResponse = await context.request('GET',
|
||||
`/api/platform/v1/pallets/${encodeURIComponent(createdId)}?tenantId=0&warehouseId=${encodeURIComponent(warehouseId)}`)
|
||||
const created = context.apiSuccess(MODULE, '回读本轮称重托盘', detailResponse,
|
||||
`warehouseId=${warehouseId}, palletId=${createdId}`, OPTIONS)
|
||||
const valid = asId(created?.id) === createdId && asId(created?.warehouseId) === cacheKey
|
||||
&& String(created?.palletCode || '').trim()
|
||||
context.assert(MODULE, '新建称重托盘归属当前仓库且编码完整', detailResponse, valid,
|
||||
`warehouseId=${warehouseId}, palletId=${createdId}, palletCode=${created?.palletCode || 'missing'}`, OPTIONS)
|
||||
if (!valid) return null
|
||||
pallets.push({ id: createdId, code: String(created.palletCode) })
|
||||
break
|
||||
context.assert(MODULE, '固定称重托盘主数据完整', response, false,
|
||||
`warehouseId=${warehouseId}, missing=${palletCode}`, OPTIONS)
|
||||
return null
|
||||
}
|
||||
pallets.push({ id: asId(exact.id), code: palletCode })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user