优化
This commit is contained in:
@@ -16,6 +16,7 @@ function query(values = {}) { const p = new URLSearchParams(); for (const [k,v]
|
||||
function payload(marker, overrides = {}) { return { name:`供应商验收-${marker}`,category:'BOOKING',carrierCodes:['MATSON','COSCO'],region:'宁波',legalRepresentative:'验收法人',contactName:'验收联系人',phone:'13800000000',email:'supplier-acceptance@example.com',address:'验收地址',businessLicenseNo:`ACPT${marker}`.slice(0,64),licenseFileId:null,status:'ACTIVE',settlementPeriod:'MONTHLY_30',remark:marker,...overrides } }
|
||||
|
||||
export async function run(context) {
|
||||
if (context.options?.fixedCustomerId) return runExistingSuppliers(context)
|
||||
const marker=context.marker.replace(/[^0-9A-Za-z]/g,'').slice(-20)
|
||||
const listResponse=await context.request('GET',query({tenantId:0,category:'BOOKING',page:1,size:20}))
|
||||
const list=context.apiSuccess(MODULE,'列表分页与订舱筛选',listResponse,'category=BOOKING',OPTIONS)
|
||||
@@ -67,3 +68,40 @@ export async function run(context) {
|
||||
context.createdResources.suppliers={marker:context.marker,supplierId,finalStatus:inactive?'INACTIVE':'UNKNOWN',retained:true}
|
||||
}
|
||||
}
|
||||
|
||||
/** 固定资源模式只读现有主档,生命周期缺口仍单独保留。 */
|
||||
async function runExistingSuppliers(context) {
|
||||
context.addCoverageGap(MODULE, 'fixed-resource-lifecycle', '供应商新增、编辑、停用生命周期',
|
||||
'固定资源模式仅验收现有供应商列表、筛选、统计、详情和作用域拒绝,不修改公共主档',
|
||||
'not-implemented', { blocking: false })
|
||||
const statsResponse = await context.request('GET', `${BASE}/stats?tenantId=0`)
|
||||
const stats = context.apiSuccess(MODULE, '查询四类供应商统计', statsResponse, '', OPTIONS)
|
||||
const nonNegativeInteger = value => value !== null && value !== undefined && value !== ''
|
||||
&& Number.isSafeInteger(Number(value)) && Number(value) >= 0
|
||||
context.assert(MODULE, '统计字段完整', statsResponse,
|
||||
['booking', 'customs', 'trucking', 'certificate'].every(key => nonNegativeInteger(stats?.[key])), '', OPTIONS)
|
||||
for (const category of ['BOOKING', 'CUSTOMS', 'TRUCKING', 'CERTIFICATE']) {
|
||||
const response = await context.request('GET', query({ tenantId: 0, category, status: 'ACTIVE', page: 1, size: 20 }))
|
||||
const page = context.apiSuccess(MODULE, `查询已有${category}供应商`, response, '', OPTIONS)
|
||||
const rows = records(page)
|
||||
context.assert(MODULE, `${category}分页和启用类别筛选正确`, response,
|
||||
Array.isArray(page?.records) && Number(page.page) === 1 && Number(page.size) === 20
|
||||
&& nonNegativeInteger(page.total) && Number(page.pages) === Math.ceil(Number(page.total) / 20)
|
||||
&& rows.length === Math.min(20, Number(page.total))
|
||||
&& rows.every(row => id(row.id) && row.category === category && row.status === 'ACTIVE'), '', OPTIONS)
|
||||
if (!rows.length) {
|
||||
context.addCoverageGap(MODULE, `existing-${category}`, `${category}供应商详情`,
|
||||
'没有启用的既有样本;未创建供应商,详情未验收', 'prerequisite', { blocking: false })
|
||||
continue
|
||||
}
|
||||
const supplierId = id(rows[0].id)
|
||||
if (!supplierId) continue
|
||||
const detailResponse = await context.request('GET', `${BASE}/${encodeURIComponent(supplierId)}?tenantId=0`)
|
||||
const detail = context.apiSuccess(MODULE, `回查已有${category}供应商详情`, detailResponse, '', OPTIONS)
|
||||
context.assert(MODULE, `${category}详情身份、类别及平台归属一致`, detailResponse,
|
||||
id(detail?.id) === supplierId && id(detail?.tenantId) === '0' && detail?.category === category
|
||||
&& detail?.status === 'ACTIVE' && !Object.hasOwn(detail || {}, 'scope'), '', OPTIONS)
|
||||
}
|
||||
const denied = await context.request('GET', query({ tenantId: 1, page: 1, size: 20 }))
|
||||
context.assert(MODULE, 'tenantId非0被拒绝', denied, code(denied, 'A0400') && traced(denied), '', OPTIONS)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user