Files
baiyue-firstleg/scripts/admin-test-env-modules/container-specification-fixture-contract.test.mjs
T

48 lines
1.8 KiB
JavaScript
Raw Normal View History

2026-08-17 13:24:48 +08:00
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { test } from 'node:test'
const productionFixtures = [
'manual-state-loading-pda.mjs',
'ocean-booking-fixture.mjs',
'ocean-bookings.mjs',
'phase3-carrier-schedule-queries.mjs',
'phase3-container-loading.mjs',
'phase3-loading.mjs',
'phase3-order-splitting.mjs',
'phase3-port-schedules.mjs',
]
function source(name) {
return readFileSync(new URL(name, import.meta.url), 'utf8')
}
test('HTTP fixtures use the canonical primary and mismatch container specifications', () => {
const primarySources = productionFixtures.map(source).join('\n')
const containerFlow = source('phase3-container-loading.mjs')
2026-09-15 10:37:34 +08:00
assert.match(primarySources, /containerType: '40HQ'[\s\S]*?capacityCbm: 68[\s\S]*?maxWeightKg: 19500/)
assert.match(containerFlow, /containerType: '40GP'[\s\S]*?capacityCbm: 58[\s\S]*?maxWeightKg: 19500/)
2026-08-17 13:24:48 +08:00
})
test('HTTP fixtures do not reintroduce retired aliases or arbitrary specifications', () => {
for (const name of productionFixtures) {
const fixture = source(name)
2026-09-15 10:37:34 +08:00
assert.doesNotMatch(fixture, /20GP|40HC|40NR|45HC/, name)
assert.doesNotMatch(fixture, /capacityCbm:\s*(?:100|76|67|33|28)(?:\D|$)/, name)
2026-08-17 13:24:48 +08:00
assert.doesNotMatch(fixture, /maxWeightKg:\s*(?:100000|22000)(?:\D|$)/, name)
}
})
test('the frozen catalog is complete and unambiguous', () => {
// Keep every future fixture producer constrained to the same product catalog as Admin and Firstleg.
const catalog = Object.freeze({
2026-09-15 10:37:34 +08:00
'40GP': Object.freeze({ capacityCbm: 58, maxWeightKg: 19500 }),
'40HQ': Object.freeze({ capacityCbm: 68, maxWeightKg: 19500 }),
'45HQ': Object.freeze({ capacityCbm: 86, maxWeightKg: 19500 }),
2026-08-17 13:24:48 +08:00
})
2026-09-15 10:37:34 +08:00
assert.deepEqual(Object.keys(catalog), ['40GP', '40HQ', '45HQ'])
assert.equal(new Set(Object.keys(catalog)).size, 3)
2026-08-17 13:24:48 +08:00
})