Files
order_site/apps/backend/src/services/finance/finance-cutover-migration.test.ts
T

35 lines
1.2 KiB
TypeScript

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 updateIndex = migration.indexOf('UPDATE sales_daily_facts')
const constraintIndex = migration.indexOf('ADD CONSTRAINT chk_sales_daily_facts_fulfillment_mode')
assert.ok(updateIndex > 0, '缺少 sales_daily_facts 旧口径归一')
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}`)
}
})