fix(finance): 收敛内部 SKU 履约路由与载体状态
统一内部 SKU 与渠道主/兜底解析,禁止并列主渠道。 运营指定渠道改为先创建真实载体,失败保持明确 pending。 历史缺载体、多载体冲突和自动发货兜底统一由管道修复。 迁移人工配置与旧 sku_code 规则,补充严格预检和集成测试。
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
planInternalSkuChannels,
|
||||
type InternalSkuChannelRow,
|
||||
} from './internal-sku-channel-service.js'
|
||||
|
||||
function channel(patch: Partial<InternalSkuChannelRow>): InternalSkuChannelRow {
|
||||
return {
|
||||
internal_sku: '内部SKU',
|
||||
channel: 'manual',
|
||||
priority: 10,
|
||||
is_fallback: false,
|
||||
enabled: true,
|
||||
canonical_product_id: null,
|
||||
config_json: {},
|
||||
source: 'test',
|
||||
...patch,
|
||||
}
|
||||
}
|
||||
|
||||
test('渠道计划:主渠道失败后按优先级使用显式兜底', () => {
|
||||
const plan = planInternalSkuChannels([
|
||||
channel({ channel: 'manual', priority: 90, is_fallback: true }),
|
||||
channel({ channel: 'affiliate_dash', priority: 10 }),
|
||||
])
|
||||
assert.equal(plan.primary?.channel, 'affiliate_dash')
|
||||
assert.deepEqual(
|
||||
plan.attempts.map((item) => item.channel),
|
||||
['affiliate_dash', 'manual'],
|
||||
)
|
||||
})
|
||||
|
||||
test('渠道计划:同级多主渠道是冲突,不能静默按字母选一个', () => {
|
||||
const plan = planInternalSkuChannels([
|
||||
channel({ channel: 'manual', priority: 10 }),
|
||||
channel({ channel: 'work_order', priority: 10 }),
|
||||
])
|
||||
assert.equal(plan.primary, null)
|
||||
assert.deepEqual(plan.conflicts.map((item) => item.channel).sort(), ['manual', 'work_order'])
|
||||
})
|
||||
|
||||
test('渠道计划:非兜底渠道即使优先级数值更大也压过兜底渠道', () => {
|
||||
const plan = planInternalSkuChannels([
|
||||
channel({ channel: 'manual', priority: 1, is_fallback: true }),
|
||||
channel({ channel: 'work_order', priority: 50 }),
|
||||
])
|
||||
assert.equal(plan.primary?.channel, 'work_order')
|
||||
assert.equal(plan.fallbacks[0]?.channel, 'manual')
|
||||
})
|
||||
|
||||
test('渠道计划:仅有一个兜底渠道时仍可作为实际主渠道', () => {
|
||||
const plan = planInternalSkuChannels([
|
||||
channel({ channel: 'manual', priority: 90, is_fallback: true }),
|
||||
])
|
||||
assert.equal(plan.primary?.channel, 'manual')
|
||||
assert.deepEqual(
|
||||
plan.attempts.map((item) => item.channel),
|
||||
['manual'],
|
||||
)
|
||||
})
|
||||
Reference in New Issue
Block a user