Files
baiyue-firstleg/scripts/inbound-hold-unified-sql-contract.test.mjs
T

34 lines
2.1 KiB
JavaScript

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
const unified = readFileSync(new URL('../deploy/sql/头程数据库统一增量-MySQL8.sql', import.meta.url), 'utf8')
const firstleg = readFileSync(new URL('../firstleg/src/main/resources/db/phase2-inbound-schema.sql', import.meta.url), 'utf8')
const iam = readFileSync(new URL('../iam/src/main/resources/db/inbound-hold-permission.sql', import.meta.url), 'utf8')
test('统一增量与 Firstleg 扣货快照和不可变历史结构一致', () => {
for (const source of [unified, firstleg]) {
assert.match(source, /current_hold_reason VARCHAR\(1000\) NULL COMMENT '当前扣货理由快照'/)
assert.match(source, /CREATE TABLE IF NOT EXISTS fl_inbound_hold_record/)
assert.match(source, /hold_action VARCHAR\(16\) NOT NULL COMMENT '动作:HOLD或RELEASE'/)
assert.match(source, /reason VARCHAR\(1000\) NOT NULL/)
assert.match(source, /evidence_file_id BIGINT UNSIGNED NULL/)
assert.match(source, /KEY idx_hold_inbound_time \(tenant_id, inbound_id, operated_at\)/)
}
assert.match(unified, /MODIFY COLUMN current_hold_reason VARCHAR\(1000\) NULL/)
})
test('统一增量与 IAM 模块冻结同一独立扣货权限且只默认授予平台管理员', () => {
for (const source of [unified, iam]) {
assert.match(source, /\(5102032, 0, 'PLATFORM', 'BUTTON', 5102030, 'platform:firstleg:inbound:hold'/)
assert.match(source, /role\.role_code='PLATFORM_ADMIN'/)
assert.match(source, /permission\.permission_code='platform:firstleg:inbound:hold'/)
assert.match(source, /入库单扣货权限初始化失败:权限ID、编码或类型冲突/)
assert.match(source, /入库单扣货权限初始化失败:权限资源不完整/)
assert.match(source, /入库单扣货权限初始化失败:平台超级管理员授权不完整/)
}
const migration = unified.slice(unified.indexOf('CREATE PROCEDURE migrate_inbound_hold_permission()'),
unified.indexOf('DROP PROCEDURE IF EXISTS assert_wallet_event_schema'))
assert.doesNotMatch(migration, /role_code='(?:ORDER_OPERATOR|WAREHOUSE_OPERATOR|WAREHOUSE_TALLY|PLATFORM_CUSTOM_ADMIN)'/)
})