68 lines
4.1 KiB
JavaScript
68 lines
4.1 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { readFileSync } from 'node:fs'
|
|
import { dirname, resolve } from 'node:path'
|
|
import test from 'node:test'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
import { requestedOrderDestinationType } from './orders.mjs'
|
|
import { collectPhase4InboundProducerFixture } from './phase3-loading-finalize.mjs'
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
const read = (name) => readFileSync(resolve(here, name), 'utf8')
|
|
|
|
test('order fixture defaults to FBA and accepts only the explicit OVERSEAS variant', () => {
|
|
assert.equal(requestedOrderDestinationType({ context: {} }), 'FBA')
|
|
assert.equal(requestedOrderDestinationType({ context: { orderDestinationType: 'overseas' } }), 'OVERSEAS')
|
|
assert.equal(requestedOrderDestinationType({ context: { orderDestinationType: 'PRIVATE' } }), 'FBA')
|
|
const orders = read('orders.mjs')
|
|
assert.match(orders, /warehouseType=\$\{encodeURIComponent\(destinationType\)\}/)
|
|
assert.match(orders, /destinationType: master\.destinationType/)
|
|
assert.match(orders, /destinationType,\s*\n\s*\}\)/)
|
|
assert.doesNotMatch(orders, /const fbaResponse =/)
|
|
})
|
|
|
|
test('producer collector requires one FBA, one OVERSEAS and a third distinct container', () => {
|
|
const common = { marker: 'RUN-1', eventType: 'FIRST_LEG_LOADING_PLAN_COMPLETED', sourceStatus: 'LOADED' }
|
|
const fba = { ...common, eventKey: 'FBA-EVENT', destinationType: 'FBA', containerNo: 'FBA-001' }
|
|
const overseasPrimary = { ...common, eventKey: 'OS-EVENT-1', destinationType: 'OVERSEAS', containerNo: 'OS-001' }
|
|
const secondary = { ...common, eventKey: 'FBA-EVENT-2', destinationType: 'FBA', containerNo: 'FBA-002' }
|
|
const one = collectPhase4InboundProducerFixture(null, fba)
|
|
const two = collectPhase4InboundProducerFixture(one, overseasPrimary)
|
|
const ready = collectPhase4InboundProducerFixture(two, secondary)
|
|
assert.equal(one.readiness.readyForPhase4Pda, false)
|
|
assert.equal(two.readiness.readyForPhase4Pda, false)
|
|
assert.equal(ready.readiness.readyForPhase4Pda, true)
|
|
assert.equal(ready.readiness.fbaContainerCount, 2)
|
|
assert.equal(ready.readiness.overseasContainerCount, 1)
|
|
assert.equal(ready.readiness.distinctContainerCount, 3)
|
|
assert.equal(ready.byDestinationType.FBA[1].eventKey, 'FBA-EVENT-2')
|
|
})
|
|
|
|
test('same event key is idempotently replaced and another marker starts a new matrix', () => {
|
|
const first = collectPhase4InboundProducerFixture(null,
|
|
{ marker: 'RUN-1', eventKey: 'EVENT-1', destinationType: 'FBA', containerNo: 'FBA-001' })
|
|
const replay = collectPhase4InboundProducerFixture(first,
|
|
{ marker: 'RUN-1', eventKey: 'EVENT-1', destinationType: 'FBA', containerNo: 'FBA-001' })
|
|
assert.equal(replay.containers.length, 1)
|
|
const nextRun = collectPhase4InboundProducerFixture(replay,
|
|
{ marker: 'RUN-2', eventKey: 'EVENT-2', destinationType: 'OVERSEAS', containerNo: 'OS-002' })
|
|
assert.equal(nextRun.containers.length, 1)
|
|
assert.equal(nextRun.marker, 'RUN-2')
|
|
assert.deepEqual(nextRun.requiredEntryOrchestration, [
|
|
'FBA: orders -> inbound-measurement -> phase3-loading -> phase3-customs -> phase3-loading-finalize',
|
|
'OVERSEAS-PRIMARY: orders -> inbound-measurement -> phase3-loading -> phase3-customs -> phase3-loading-finalize',
|
|
'SECONDARY(FBA|OVERSEAS): orders -> inbound-measurement -> phase3-loading -> phase3-customs -> phase3-loading-finalize',
|
|
])
|
|
})
|
|
|
|
test('measurement and loading pass destination identity into the LOADED producer key', () => {
|
|
const measurement = read('inbound-measurement.mjs')
|
|
const loading = read('phase3-loading.mjs')
|
|
const finalize = read('phase3-loading-finalize.mjs')
|
|
assert.match(measurement, /destinationType: context\.createdResources\?\.orders\?\.destinationType/)
|
|
assert.match(loading, /destinationType: initial\?\.summary\?\.destinationType \|\| source\?\.destinationType/)
|
|
assert.match(finalize, /destinationType: fixture\.destinationType \|\| null/)
|
|
assert.match(finalize, /resourceKey: `\$\{context\.marker\}:\$\{fixture\.destinationType \|\| 'UNKNOWN'\}:\$\{fixture\.containerNo \|\| containerBookingId\}`/)
|
|
assert.match(finalize, /phase4InboundProducerFixtures = collectPhase4InboundProducerFixture/)
|
|
})
|