Files
baiyue-firstleg/scripts/admin-test-env-modules/manual-state-loading-pda-contract.test.mjs
T

74 lines
4.4 KiB
JavaScript

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
const source = readFileSync(new URL('./manual-state-loading-pda.mjs', import.meta.url), 'utf8')
test('retains all clickable container, loading-list and PDA workflow states through public APIs', () => {
for (const status of ['WAIT_LOADING', 'EDITING', 'LOADING', 'COMPLETED',
'UNASSIGNED', 'IN_PROGRESS', 'AWAITING_REVIEW']) assert.match(source, new RegExp(`['"]${status}['"]`))
for (const endpoint of ['/ocean-bookings', '/smart-loading', '/plans/by-booking/', '/inventory-snapshot',
'/batch', '/complete', '/loading-plans', '/loading-lists']) assert.match(source, new RegExp(endpoint))
assert.match(source, /requiredStatuses/)
assert.match(source, /detailPath/)
assert.match(source, /loading-plans\/\$\{fixture\.id\}/)
assert.match(source, /loading-lists\/\$\{listFixture\.id\}/)
assert.match(source, /prepareInbound/)
assert.match(source, /\.\/orders\.mjs/)
assert.match(source, /\.\/inbound-measurement\.mjs/)
assert.match(source, /context\.request\('POST', CONTAINERS/)
assert.match(source, /channelGroupCode:\s*channelGroup\(summary\.channelCode\)/)
assert.match(source, /summary\?\.processStatus === 'WAIT_SPLIT'/)
const pushIndex = source.indexOf('`${SMART}/plans/${plan.id}`')
const transportIndex = source.indexOf('ocean-booking-link')
assert.ok(transportIndex >= 0 && pushIndex > transportIndex)
const unconfirmedTaskIndex = source.indexOf('`${PDA}/tasks?loadingPlanId=${planId}&warehouseId=${source.warehouseId}`', pushIndex)
const confirmIndex = source.indexOf('`${LOADING}/loading-plans/${planId}/confirm`', unconfirmedTaskIndex)
const canonicalTaskIndex = source.indexOf('`${PDA}/tasks?loadingPlanId=${planId}&warehouseId=${source.warehouseId}`', unconfirmedTaskIndex + 1)
assert.ok(unconfirmedTaskIndex > pushIndex && confirmIndex > unconfirmedTaskIndex
&& canonicalTaskIndex > confirmIndex)
assert.doesNotMatch(source, /push-preload/)
assert.match(source, /计划确认前不生成 PDA 任务/)
assert.match(source, /summary\?\.readiness\?\.canConfirm === true/)
assert.match(source, /Object\.freeze\(\{ expectedVersion: confirmableVersion, assigneeId: id\(pdaOperator.userId\) \}\)/)
assert.match(source, /confirmationStatus === 'CONFIRMED'/)
assert.match(source, /readiness\?\.readyForPda === true/)
assert.match(source, /id\(task\?\.id\) !== confirmedTaskId/)
assert.match(source, /计划确认同键同参精确重放/)
assert.doesNotMatch(source, /\/preload\/confirming|\/preload\/confirm\?tenantId=/)
assert.match(source, /linked\?\.cabinetNo !== simulation\.cabinetNo/)
assert.match(source, /iso6346ContainerNumber/)
assert.match(source, /shippingCompanyId: id\(carrier\.id\), shippingCompanyName: carrier\.name/)
assert.match(source, /bookingAgentId: id\(agent\.id\), bookingAgentName: agent\.name/)
assert.match(source, /billOfLadingNo: `BL-\$\{value\}`/)
const batch = source.slice(source.indexOf('async function pickAll'), source.indexOf('async function complete'))
assert.doesNotMatch(batch, /containerNo:/)
})
test('does not mutate historical fixtures or remove retained records', () => {
assert.doesNotMatch(source, /\bDELETE\b/)
assert.doesNotMatch(source, /createdResources\?\.phase3ContainerLoading/)
assert.doesNotMatch(source, /orchestrationFixtures\?\./)
assert.match(source, /fixtureMarker/)
assert.match(source, /context\.marker = originalMarker/)
})
test('fails closed when invoked outside the manual matrix wrapper', () => {
assert.match(source, /if \(!matrix\?\.pages\)/)
assert.match(source, /missing=manualStateMatrix\.pages/)
})
test('reuses the departed-container clearance action verified by the dedicated module', () => {
assert.match(source, /createdResources\?\.phase3ContainerDocuments/)
assert.match(source, /documentIds\?\.DESTINATION_CLEARANCE/)
assert.match(source, /本轮离仓后已完成的目的港清关动作/)
assert.match(source, /GET', `\$\{CONTAINERS\}\/\$\{containerId\}\/clearance`/)
assert.match(source, /completed\?\.documentType === 'DESTINATION_CLEARANCE'/)
assert.match(source, /Boolean\(completed\?\.completedAt\)/)
assert.match(source, /matrix\.pages\.containerLoading\.actions/)
assert.doesNotMatch(source, /CUSTOMS_DECLARATION|loading-customs|customsPath/)
assert.match(source, /tasks\/\$\{taskId\}\/evidence/)
assert.doesNotMatch(source, /internal\/file|business-files/)
assert.doesNotMatch(source, /clearance\/document\/upload/)
})