chore(test): 清理旧迁移测试并统一前端格式

This commit is contained in:
yml2213
2026-11-07 17:52:15 +08:00
parent 8ef8c61862
commit 313e619744
4 changed files with 24 additions and 53 deletions
@@ -1,45 +0,0 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import test from 'node:test'
const migration = readFileSync(
fileURLToPath(new URL('../../db/migrations/113_finance_channel_cutover.sql', import.meta.url)),
'utf8',
)
test('113 迁移必须先删旧约束、再归一销售事实,最后加新约束', () => {
const dropIndex = migration.indexOf(
'DROP CONSTRAINT IF EXISTS chk_sales_daily_facts_fulfillment_mode',
)
const updateIndex = migration.indexOf('UPDATE sales_daily_facts')
const constraintIndex = migration.indexOf('ADD CONSTRAINT chk_sales_daily_facts_fulfillment_mode')
assert.ok(dropIndex > 0, '缺少旧渠道约束的删除')
assert.ok(updateIndex > dropIndex, '必须先删旧约束再归一;否则 archived 会被旧约束拒绝')
assert.ok(constraintIndex > updateIndex, '必须先归一数据,再加新约束')
assert.ok(
migration.includes("WHEN fulfillment_mode = 'legacy_platform' THEN 'archived'"),
'legacy_platform 必须归入 archived',
)
assert.ok(
migration.includes("ELSE 'unclassified'"),
'其它未知旧值必须归入 unclassified,避免约束因脏数据失败',
)
for (const channel of [
'work_order',
'affiliate_dash',
'third_party_voucher',
'manual',
'unclassified',
'archived',
]) {
assert.ok(migration.includes(`'${channel}'`), `新约束必须允许 ${channel}`)
}
})
test('113 迁移的异常表旧行 scope_key 必须保证唯一', () => {
assert.ok(
migration.includes("'|legacy:' || id"),
'旧异常行 scope_key 必须拼 id,避免同 reason + subject_id 撞唯一索引',
)
})