69 lines
3.2 KiB
JavaScript
69 lines
3.2 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import fs from 'node:fs'
|
|
import test from 'node:test'
|
|
|
|
import { selectCustomsFlow } from './phase3-customs.mjs'
|
|
import { buildFinalizeResource } from './phase3-loading-finalize.mjs'
|
|
|
|
test('pairs customs source fixture with the matching loading container', () => {
|
|
const resources = {
|
|
orchestrationFixtures: {
|
|
inboundMeasurement: { tenantId: 10001, orderId: 101, inboundId: 201 },
|
|
phase3Container: { tenantId: 10001, orderId: 102, inboundId: 202 },
|
|
},
|
|
phase3Loading: { tenantId: 10001, inboundId: 201, containerBookingId: 301 },
|
|
phase3ContainerLoading: { tenantId: 10001, inboundId: 202, containerBookingId: 302 },
|
|
}
|
|
const selected = selectCustomsFlow(resources)
|
|
assert.equal(selected.fixture.orderId, 101)
|
|
assert.equal(selected.container.containerBookingId, 301)
|
|
})
|
|
|
|
test('falls back to the matching container fixture without crossing source identities', () => {
|
|
const resources = {
|
|
orchestrationFixtures: { phase3Container: { tenantId: 10001, orderId: 102, inboundId: 202 } },
|
|
phase3Loading: { tenantId: 10001, inboundId: 201, containerBookingId: 301 },
|
|
phase3ContainerLoading: { tenantId: 10001, inboundId: 202, containerBookingId: 302 },
|
|
}
|
|
const selected = selectCustomsFlow(resources)
|
|
assert.equal(selected.fixture.orderId, 102)
|
|
assert.equal(selected.container.containerBookingId, 302)
|
|
})
|
|
|
|
test('records LOADING and a cleanup reason when finalize returns S0500', () => {
|
|
const result = buildFinalizeResource(
|
|
{ inboundStatus: 'LOADING', inboundVersion: 5, finalStatus: 'COMPLETED' },
|
|
{ summary: { processStatus: 'LOADING', version: 5 } },
|
|
{ http: 200, body: { code: 'S0500' } },
|
|
)
|
|
assert.equal(result.finalStatus, 'LOADING')
|
|
assert.equal(result.finalizeSucceeded, false)
|
|
assert.match(result.notCleanedReason, /S0500/)
|
|
})
|
|
|
|
test('records LOADED and clears the reason only after a real LOADED reread', () => {
|
|
const result = buildFinalizeResource(
|
|
{ inboundStatus: 'LOADING', inboundVersion: 5, finalStatus: 'COMPLETED' },
|
|
{ summary: { processStatus: 'LOADED', version: 6 } },
|
|
{ http: 200, body: { code: '200' } },
|
|
)
|
|
assert.equal(result.finalStatus, 'LOADED')
|
|
assert.equal(result.finalizeSucceeded, true)
|
|
assert.equal(result.notCleanedReason, null)
|
|
})
|
|
|
|
test('keeps push and claim state transitions in the verified order', () => {
|
|
const containerScript = fs.readFileSync(new URL('./phase3-container-loading.mjs', import.meta.url), 'utf8')
|
|
const loadingScript = fs.readFileSync(new URL('./phase3-loading.mjs', import.meta.url), 'utf8')
|
|
|
|
assert.match(containerScript, /planStatus === 'WAIT_LOADING'/)
|
|
assert.match(containerScript, /pushed\?\.status === 'EDITING'/)
|
|
assert.match(containerScript, /claimedPlan\?\.status === 'LOADING'/)
|
|
assert.ok(containerScript.indexOf("pushed?.status === 'EDITING'") < containerScript.indexOf("claimedPlan?.status === 'LOADING'"))
|
|
|
|
assert.match(loadingScript, /pushedLoadingPlan\?\.status === 'EDITING'/)
|
|
assert.match(loadingScript, /claimedPlan\?\.status === 'LOADING'/)
|
|
assert.ok(loadingScript.indexOf("pushedLoadingPlan?.status === 'EDITING'") < loadingScript.indexOf("claimedPlan?.status === 'LOADING'"))
|
|
assert.ok(loadingScript.indexOf("claimedPlan?.status === 'LOADING'") < loadingScript.indexOf("const confirming ="))
|
|
})
|