Files
baiyue-firstleg/scripts/admin-test-env-modules/ocean-booking-channel-contract.test.mjs
T
2026-08-18 16:39:39 +08:00

49 lines
2.9 KiB
JavaScript

import assert from 'node:assert/strict'
import { readFileSync, readdirSync } from 'node:fs'
import test from 'node:test'
const adminPageUrl = new URL('../../../apps/admin-web/src/modules/ocean-bookings/pages/OceanBookingDetailView.vue', import.meta.url)
const adminTestUrl = new URL('../../../apps/admin-web/src/modules/ocean-bookings/pages/OceanBookingDetailView.test.ts', import.meta.url)
const adminApiUrl = new URL('../../../apps/admin-web/src/modules/ocean-bookings/api/platformOceanBookings.ts', import.meta.url)
const openapiUrl = new URL('../../firstleg/src/main/resources/openapi/', import.meta.url)
function source(url) { return readFileSync(url, 'utf8') }
test('Admin ocean booking selects a warehouse-scoped logistics channel instead of accepting free text', () => {
const page = source(adminPageUrl)
const api = source(adminApiUrl)
const pageTest = source(adminTestUrl)
assert.doesNotMatch(page, /<el-input[^>]*v-model="form\.data\.channelCode"/)
assert.doesNotMatch(page, /<el-input[^>]*v-model="form\.data\.channelName"/)
assert.match(page, /<el-form-item[^>]*label="物流渠道"[^>]*>[\s\S]*?<el-select[^>]*:model-value="form\.data\.channelCode"[^>]*@update:model-value="selectChannel\(/)
assert.match(`${page}\n${api}`, /originWarehouseId/)
assert.match(api, /basePath\s*=\s*['"]\/platform\/v1\/ocean-bookings['"][\s\S]*\$\{basePath\}\/channels/)
assert.doesNotMatch(api, /price-books[\s\S]*for \(const version of versions\)/)
assert.match(page, /shippingCompanyId/)
assert.match(page, /channelCode/)
assert.doesNotMatch(pageTest, /expect\(source\)\.toContain\(['"]v-model="form\.data\.channel(?:Code|Name)"['"]\)/)
assert.match(pageTest, /listWarehouseLogisticsChannels|channelCode/)
})
test('backend OpenAPI freezes a platform channel query scoped by originWarehouseId', () => {
const documents = readdirSync(openapiUrl)
.filter((name) => name.endsWith('.yaml'))
.map((name) => source(new URL(name, openapiUrl)))
const platformChannelContract = documents.find((value) =>
/\/api\/platform\/v1\/ocean-bookings\/channels/.test(value) && /originWarehouseId/.test(value)
&& /current ACTIVE price book/.test(value))
assert.ok(platformChannelContract,
'BLOCKED_CONTRACT: platform logistics-channel query by originWarehouseId is not frozen in OpenAPI')
})
test('released requirement association locks the selected channel onto the simulation', () => {
const fixture = source(new URL('./phase3-container-loading.mjs', import.meta.url))
assert.match(fixture, /ocean-booking-link/)
assert.match(fixture, /订舱放舱为 RELEASED 且不预生成真实货柜/)
assert.match(fixture, /oceanBookingId: bookingId, requirementId: id\(requirement\.id\), containerNo: realContainerNo/)
assert.match(fixture, /containerDetail\?\.channelCode === channelCode/)
assert.match(fixture, /selectPlatformChannelIsolationPair/)
assert.doesNotMatch(fixture, /\$\{channelCode\}-OTHER|foreignChannelCode/)
})