Files
baiyue-firstleg/scripts/admin-test-env-modules/phase3-carrier-schedule-queries.test.mjs
T

58 lines
2.9 KiB
JavaScript

import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'
import { currentOutboundFixture, ownsCarrierQuery } from './phase3-carrier-schedule-queries.mjs'
const here = path.dirname(fileURLToPath(import.meta.url))
const source = fs.readFileSync(path.join(here, 'phase3-carrier-schedule-queries.mjs'), 'utf8')
function context(marker = 'RUN') {
return { marker, createdResources: {
phase3Loading: { marker, tenantId: '10001', oceanBookingId: '20001', containerBookingId: '30001', containerNo: 'TSTU1234567' },
phase3OutboundDispatch: { marker, tenantId: '10001', containerBookingId: '30001', confirmedStatus: 'WAITING_FOR_LOADING' },
} }
}
test('outbound fixture requires exact current marker and matching loading/outbound container', () => {
assert.deepEqual(currentOutboundFixture(context()), {
marker: 'RUN', customerId: '10001', oceanBookingId: '20001', containerBookingId: '30001', trackingNo: 'TSTU1234567',
})
const old = context(); old.createdResources.phase3OutboundDispatch.marker = 'OLD'
assert.equal(currentOutboundFixture(old), null)
const mismatch = context(); mismatch.createdResources.phase3OutboundDispatch.containerBookingId = 'OTHER'
assert.equal(currentOutboundFixture(mismatch), null)
})
test('carrier query ownership requires explicit outbound-confirm marker registration', () => {
assert.equal(ownsCarrierQuery({ queryId: '1', marker: 'RUN', ownedByModule: true,
triggerSource: 'OUTBOUND_CONFIRM' }, 'RUN'), true)
assert.equal(ownsCarrierQuery({ queryId: '1', marker: 'RUN', ownedByModule: true,
triggerSource: 'MANUAL' }, 'RUN'), false)
assert.equal(ownsCarrierQuery({ queryId: '1', marker: 'OLD', ownedByModule: true,
triggerSource: 'OUTBOUND_CONFIRM' }, 'RUN'), false)
})
test('phase3 script only discovers the current outbound task and blocks missing prerequisites', () => {
assert.match(source, /phase3Loading/)
assert.match(source, /phase3OutboundDispatch/)
assert.match(source, /缺少本轮phase3出仓fixture,禁止借历史Query验收/)
assert.match(source, /deploymentBlocker:\s*true/)
assert.match(source, /triggerSource === 'OUTBOUND_CONFIRM'/)
assert.match(source, /DEPARTED_WAREHOUSE/)
assert.match(source, /providerEventId/)
assert.match(source, /\^\\d\{16,/)
assert.doesNotMatch(source, /request\(context,\s*'POST',\s*BASE/)
assert.doesNotMatch(source, /manual-nodes|manual-results|BILL_OF_LADING/)
assert.doesNotMatch(source, /records\[0\]/)
})
test('carrier capability assertion freezes five automated providers and COSCO only gap', () => {
assert.match(source, /\['MATSON', 'SML', 'ZIM', 'EMC', 'HEDE'\]/)
assert.match(source, /AUTOMATED_CARRIERS\.every[\s\S]*automated === true[\s\S]*coverageGap === false/)
assert.match(source, /byCode\.get\('COSCO'\)\?\.automated === false/)
assert.match(source, /OFFICIAL_API_CREDENTIALS_REQUIRED/)
})