67 lines
4.1 KiB
JavaScript
67 lines
4.1 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { readFileSync } from 'node:fs'
|
|
import test from 'node:test'
|
|
import { readInitialization, table, seedRows } from '../sql-baseline-contract-helpers.mjs'
|
|
|
|
const overseas = readInitialization('OVERSEAS')
|
|
const cn = readInitialization()
|
|
const read = relative => readFileSync(new URL(`../../${relative}`, import.meta.url), 'utf8')
|
|
|
|
test('pool has a unique publication per trip and full durable command identity, no second capacity balance', () => {
|
|
const offer = table(overseas, 'baiyue_lastleg', 'll_fleet_capacity_offer')
|
|
assert.match(offer, /UNIQUE KEY\s+\w+\(trip_id\)/i)
|
|
assert.match(offer, /UNIQUE KEY\s+\w+\(offer_no\)/i)
|
|
assert.match(offer, /published_fingerprint CHAR\(64\) NULL/i)
|
|
assert.doesNotMatch(offer, /remaining_pallet|available_pallet|reserved_pallet/i)
|
|
const command = table(overseas, 'baiyue_lastleg', 'll_fleet_capacity_offer_command')
|
|
assert.match(command, /UNIQUE KEY\s+\w+\(trip_id,operator_id,action,scope_no,idempotency_key\)/i)
|
|
assert.match(command, /request_hash CHAR\(64\) NOT NULL/i)
|
|
assert.match(command, /result_json JSON NOT NULL/i)
|
|
})
|
|
|
|
test('one booking maps to exactly one commercial order and one actual incoming source', () => {
|
|
const link = table(overseas, 'baiyue_lastleg', 'll_fleet_pool_order_link')
|
|
for (const columns of ['booking_id', 'booking_no', 'business_type,business_order_id', 'incoming_no', 'lastleg_order_id']) {
|
|
assert.match(link, new RegExp(`UNIQUE KEY\\s+\\w+\\(${columns}\\)`, 'i'))
|
|
}
|
|
assert.match(link, /incoming_no VARCHAR\(64\) NULL/i)
|
|
assert.match(link, /lastleg_order_id BIGINT NULL/i)
|
|
assert.match(link, /actual_pallet_count INT NULL/i)
|
|
assert.match(link, /actual_pallet_spaces INT NULL/i)
|
|
assert.doesNotMatch(link, /(?:agreed_amount|receivable_amount|paid_amount)\s+DECIMAL/i)
|
|
const booking = table(overseas, 'baiyue_lastleg', 'll_fleet_external_booking')
|
|
assert.match(booking, /sales_owner_user_id VARCHAR\(64\) NULL/i)
|
|
assert.match(booking, /expected_pallet_count INT NULL/i)
|
|
})
|
|
|
|
test('module and unified fresh baselines contain the exact same new table definitions', () => {
|
|
const module = read('lastleg-service/src/main/resources/db/lastleg.sql')
|
|
for (const name of ['ll_fleet_capacity_offer', 'll_fleet_capacity_offer_command', 'll_fleet_pool_order_link']) {
|
|
const definition = table(overseas, 'baiyue_lastleg', name)
|
|
assert.ok(module.includes(definition), `${name}: module and unified contract drift`)
|
|
}
|
|
const sql = read('deploy/sql/migrations/overseas/baiyue_lastleg/V10__fleet_capacity_pool.sql')
|
|
assert.doesNotMatch(sql.replace(/^--.*$/gm, ''), /\b(?:DROP|TRUNCATE|DELETE|UPDATE|REPLACE)\b/i)
|
|
assert.match(sql, /ADD COLUMN expected_pallet_count INT NULL/i)
|
|
assert.match(sql, /ADD CONSTRAINT fk_fleet_booking_offer/i)
|
|
})
|
|
|
|
test('customer identity joins use the same explicit collation as existing fulfillment orders', () => {
|
|
for (const name of ['ll_fleet_external_booking', 'll_fleet_pool_order_link']) {
|
|
assert.match(table(overseas, 'baiyue_lastleg', name), /customer_id VARCHAR\(128\) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL/i)
|
|
}
|
|
const sql = read('deploy/sql/migrations/overseas/baiyue_lastleg/V11__align_capacity_pool_collation.sql')
|
|
assert.equal((sql.match(/MODIFY COLUMN customer_id/g) || []).length, 2)
|
|
assert.doesNotMatch(sql.replace(/^--.*$/gm, ''), /\b(?:DROP|TRUNCATE|DELETE|UPDATE|REPLACE)\b/i)
|
|
})
|
|
|
|
test('pool permissions are independent of trip details and default only to the platform administrator', () => {
|
|
const permissions = seedRows(cn, 'iam_permission').filter(row => String(row.permission_code).startsWith('platform:fleet:capacity-offer:'))
|
|
assert.equal(permissions.length, 5)
|
|
assert.deepEqual(permissions.map(row => row.permission_code.split(':').at(-1)).sort(), ['inquiry-cancel','inquiry-create','inquiry-edit','list','manage'])
|
|
const ids = new Set(permissions.map(row => String(row.id)))
|
|
const grants = seedRows(cn, 'iam_role_permission').filter(row => ids.has(String(row.permission_id)))
|
|
assert.equal(grants.length, 5)
|
|
assert.ok(grants.every(row => String(row.role_id) === '4000001' && String(row.tenant_id) === '0'))
|
|
})
|