Files
baiyue-firstleg/scripts/admin-test-env-modules/carrier-partner-fixture.mjs
2026-08-28 09:19:18 +08:00

33 lines
2.0 KiB
JavaScript

export const MATSON_PARTNER_CODE = 'DEV-CARRIER-MATSON'
export const MATSON_PARTNER_NAME = 'MATSON 开发联调船公司'
function id(value) { return value == null ? '' : String(value) }
export async function ensureMatsonCarrierPartner(context, module, options) {
const payload = {
partnerCode: MATSON_PARTNER_CODE, partnerName: MATSON_PARTNER_NAME,
partnerType: 'CARRIER', types: ['CARRIER'], carrierCode: 'MATSON',
contactName: '开发联调', contactPhone: '13800000000',
contactEmail: 'matson-carrier-dev-fixture@example.com', countryCode: 'US',
province: 'California', city: 'Los Angeles', district: 'Los Angeles County',
addressLine: 'Development acceptance fixture', postalCode: '90001',
status: 'ACTIVE', remark: '三四期开发环境HTTP验收稳定船公司夹具',
}
const listResponse = await context.request('GET',
`/api/platform/v1/partners?tenantId=0&page=1&size=200&keyword=${encodeURIComponent(MATSON_PARTNER_CODE)}`)
const page = context.apiSuccess(module, '读取稳定MATSON船公司往来单位', listResponse,
`partnerCode=${MATSON_PARTNER_CODE}`, options)
const existing = (page?.records || []).find((value) => value?.id && value?.partnerCode === MATSON_PARTNER_CODE)
if (existing?.id) {
const updateResponse = await context.request('PUT',
`/api/platform/v1/partners/${encodeURIComponent(id(existing.id))}?tenantId=0`, payload)
context.apiSuccess(module, '收敛稳定MATSON船公司往来单位', updateResponse,
`partnerId=${id(existing.id)}`, options)
return { id: id(existing.id), name: MATSON_PARTNER_NAME, carrierCode: 'MATSON', status: 'ACTIVE' }
}
const createResponse = await context.request('POST', '/api/platform/v1/partners?tenantId=0', payload)
const partnerId = id(context.apiSuccess(module, '创建稳定MATSON船公司往来单位', createResponse,
`partnerCode=${MATSON_PARTNER_CODE}`, options))
return partnerId ? { id: partnerId, name: MATSON_PARTNER_NAME, carrierCode: 'MATSON', status: 'ACTIVE' } : null
}