Files
baiyue-firstleg/scripts/admin-test-env-modules/phase4-canonical-warehouse-rbac-contract.test.mjs
T
2026-10-21 15:10:44 +08:00

75 lines
3.7 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
const acceptance = readFileSync(new URL('./phase3-warehouse-rbac.mjs', import.meta.url), 'utf8')
const iamSql = readFileSync(new URL('../../iam/src/main/resources/db/lastleg-permissions.sql', import.meta.url), 'utf8')
const phase5Sql = readFileSync(new URL('../../iam/src/main/resources/db/phase5-delivery-permissions.sql', import.meta.url), 'utf8')
const unifiedSql = readFileSync(new URL('../../deploy/sql/头程数据库统一增量-MySQL8.sql', import.meta.url), 'utf8')
const listCodes = [
'platform:overseas-warehouse:last-mile-order:list',
'platform:overseas-warehouse:inbound-order:list',
'platform:overseas-warehouse:relabel-order:list',
'platform:overseas-warehouse:inventory:list',
'platform:overseas-warehouse:warehouse:list',
'platform:overseas-warehouse:location:list',
'platform:overseas-warehouse:pallet:list',
'platform:overseas-business:purchase:list',
'platform:overseas-business:truck:list',
'platform:overseas-business:looseboard:list',
]
test('warehouse operator and tally use the exact phase-four and phase-five permission sets', () => {
for (const code of listCodes) {
assert.match(acceptance, new RegExp(code.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')))
assert.match(iamSql, new RegExp(`'WAREHOUSE_OPERATOR','${code}'`))
assert.match(iamSql, new RegExp(`'WAREHOUSE_TALLY','${code}'`))
}
assert.match(acceptance, /operatorCodes\.size === 34/)
assert.match(acceptance, /tallyCodes\.size === 27/)
assert.match(acceptance, /PHASE4_WRITE_SUFFIXES/)
assert.match(iamSql, /assert_phase4_warehouse_role_minimum/)
assert.match(iamSql, /permission_code REGEXP ':\(create\|edit\|status\|export\|adjust\|delete\|review\)\$'/)
})
test('warehouse roles include the exact phase-five fulfillment responsibilities', () => {
assert.match(acceptance, /PHASE5_OPERATOR_CODES/)
assert.match(acceptance, /PHASE5_TALLY_CODES/)
for (const code of [
'platform:overseas-warehouse:dispatch:list',
'platform:overseas-warehouse:dispatch:edit',
'platform:overseas-warehouse:dispatch:cancel',
'platform:overseas-warehouse:dispatch:transfer-delivery',
'platform:overseas-warehouse:outbound:list',
'platform:overseas-warehouse:outbound:create',
'platform:overseas-warehouse:outbound:cancel',
'platform:overseas-warehouse:delivery:list',
'platform:overseas-warehouse:exception-order:list',
'platform:overseas-warehouse:exception-order:create',
'platform:overseas-warehouse:exception-order:process',
'platform:overseas-warehouse:delivery:return',
'platform:overseas-warehouse:delivery:status',
'platform:overseas-warehouse:delivery:documents',
'platform:overseas-warehouse:customer-visit:list',
'platform:overseas-warehouse:customer-visit:edit'
]) {
assert.match(phase5Sql, new RegExp(code.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')))
}
})
test('domestic and overseas PDA operators use isolated authorities', () => {
assert.match(acceptance, /domesticPdaCodes\.size === 2/)
assert.match(acceptance, /overseasPdaCodes\.size === 1/)
assert.match(acceptance, /overseasPdaCodes\.has\('lastleg:pda:operate'\)/)
assert.match(iamSql, /role\.role_code='OVERSEAS_WAREHOUSE_PDA_OPERATOR'/)
assert.match(iamSql, /permission\.permission_code='lastleg:pda:operate'/)
})
test('unified baseline creates the phase-four role matrix in the IAM schema', () => {
assert.match(unifiedSql, /USE baiyue_iam;/)
assert.match(unifiedSql, /'OVERSEAS_WAREHOUSE_PDA_OPERATOR'/)
assert.match(unifiedSql, /'lastleg:pda:operate'/)
assert.doesNotMatch(unifiedSql, /tmp_phase4_warehouse_role_permission|assert_phase4_warehouse_role_minimum/)
})