59 lines
3.0 KiB
JavaScript
59 lines
3.0 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { readFileSync } from 'node:fs'
|
|
import test from 'node:test'
|
|
|
|
import { oceanBookingDraft, resolveOceanBookingMaster } from './ocean-booking-fixture.mjs'
|
|
|
|
test('ocean booking fixture resolves the current inbound customer channel and warehouse', async () => {
|
|
const steps = []
|
|
const context = {
|
|
marker: 'ADMIN-RUN-1',
|
|
createdResources: { orchestrationFixtures: { phase3Container: {
|
|
marker: 'ADMIN-RUN-1', tenantId: '21', inboundId: '31',
|
|
} } },
|
|
request: async () => ({ body: { code: '200', data: { summary: {
|
|
tenantId: 21, customerName: 'IT 测试客户', channelCode: 'SEA-US', channelName: '美西海运',
|
|
warehouseId: 41, warehouseName: '深圳仓',
|
|
} } } }),
|
|
addStep: (...args) => steps.push(args),
|
|
}
|
|
const master = await resolveOceanBookingMaster(context, 'test')
|
|
assert.deepEqual(master, { customerId: '21', customerName: 'IT 测试客户', channelCode: 'SEA-US',
|
|
channelName: '美西海运', warehouseId: '41', warehouseName: '深圳仓' })
|
|
assert.equal(steps.length, 0)
|
|
})
|
|
|
|
test('ocean booking fixture blocks creation instead of inventing missing master data', async () => {
|
|
const steps = []
|
|
const context = { marker: 'ADMIN-RUN-2', createdResources: {}, addStep: (...args) => steps.push(args) }
|
|
assert.equal(await resolveOceanBookingMaster(context, 'test'), null)
|
|
assert.equal(steps.length, 1)
|
|
assert.match(steps[0][4], /missing=customerId,customerName,channelCode,channelName,warehouseId,warehouseName/)
|
|
})
|
|
|
|
test('shared booking draft carries all required DTO fields without release transport data', () => {
|
|
const draft = oceanBookingDraft({ marker: 'ADMIN-RUN-3' }, '3', {
|
|
customerId: '21', customerName: 'IT 测试客户', channelCode: 'SEA-US', channelName: '美西海运',
|
|
warehouseId: '41', warehouseName: '深圳仓',
|
|
})
|
|
for (const key of ['customerId', 'customerName', 'channelCode', 'channelName', 'warehouseId', 'warehouseName']) {
|
|
assert.ok(draft[key], `${key} is required`)
|
|
}
|
|
assert.equal(draft.containerRequirements[0].capacityCbm, 68)
|
|
assert.equal(draft.containerRequirements[0].maxWeightKg, 28000)
|
|
for (const key of ['billOfLadingNo', 'vesselName', 'voyageNo', 'estimatedSailingAt', 'estimatedArrivalAt']) {
|
|
assert.equal(draft[key], undefined, `${key} belongs to release, not draft`)
|
|
}
|
|
})
|
|
|
|
test('all independent ocean booking producers use the shared master-data contract', () => {
|
|
for (const name of ['ocean-bookings.mjs', 'phase3-port-schedules.mjs', 'phase3-carrier-schedule-queries.mjs']) {
|
|
const source = readFileSync(new URL(name, import.meta.url), 'utf8')
|
|
assert.match(source, /resolveOceanBookingMaster\(context, MODULE\)/, name)
|
|
assert.match(source, /oceanBookingDraft\(context, suffix, master/, name)
|
|
}
|
|
const container = readFileSync(new URL('phase3-container-loading.mjs', import.meta.url), 'utf8')
|
|
for (const snippet of ['channelCode: channelCode', 'channelName', 'warehouseId', 'warehouseName',
|
|
'capacityCbm: 100', 'maxWeightKg: 100000']) assert.match(container, new RegExp(snippet), snippet)
|
|
})
|