Files
order_site/apps/backend/src/services/scheduler/config-service.test.ts
T
yml2213 65b7f4f9dc refactor(finance)!: 强制渠道模型,移除旧履约方式与同步链路
- 删除 fulfillment_mode 相关的旧同步/回填链路与定时任务
- 删除 cost_finance_sync、成本快照同步、人工商品归一等遗留服务
- 迁移 113 直接删除 order_items.fulfillment_mode 及其索引约束
- 断代脚本自带归档步骤,不再依赖独立回填脚本
- 退款/事实/总账统一走渠道版销售事实
2026-10-31 19:52:03 +08:00

138 lines
3.7 KiB
TypeScript

import assert from 'node:assert/strict'
import test from 'node:test'
import { normalizeScheduledJobsConfig } from './config-service.js'
test('normalizeScheduledJobsConfig drops retired cloudtentacles_health jobs', () => {
const config = normalizeScheduledJobsConfig({
enabled: true,
jobs: [
{
id: 'cloudtentacles-health',
type: 'cloudtentacles_health',
enabled: true,
intervalSeconds: 300,
config: { assetThreshold: 100 },
},
{
id: 'work-order-timeout',
type: 'work_order_timeout',
enabled: true,
intervalSeconds: 60,
config: { scanLimit: 50 },
},
],
})
assert.equal(
config.jobs.some((item) => item.type === 'cloudtentacles_health'),
false,
)
assert.equal(
config.jobs.some((item) => item.id === 'work-order-timeout'),
true,
)
})
test('normalizeScheduledJobsConfig ensures default jobs exist', () => {
const config = normalizeScheduledJobsConfig({ enabled: true, jobs: [] })
const ids = config.jobs.map((item) => item.id)
assert.ok(ids.includes('work-order-timeout'))
assert.ok(ids.includes('deposit-unfreeze'))
assert.ok(ids.includes('data-retention'))
assert.ok(ids.includes('pdd_order_sync'))
// 旧财务闭环作业已下线,不再作为默认任务注入。
assert.equal(ids.includes('cost-finance-sync'), false)
assert.ok(ids.includes('channel-assign'))
assert.ok(ids.includes('ledger-post'))
})
test('旧的 cost_finance_sync 任务已彻底移除,不再出现在配置里', () => {
const config = normalizeScheduledJobsConfig({
enabled: true,
jobs: [
{
id: 'cost-finance-sync',
type: 'cost_finance_sync',
enabled: true,
intervalSeconds: 900,
config: { days: 7 },
},
],
})
assert.equal(
config.jobs.some((item) => item.type === 'cost_finance_sync'),
false,
)
})
test('normalizeScheduledJobsConfig 收录 v2 六个管道作业并保持各自配置', () => {
const config = normalizeScheduledJobsConfig({
enabled: true,
jobs: [
{
id: 'channel-assign',
type: 'channel_assign',
enabled: true,
intervalSeconds: 60,
config: { batchSize: 800, maxBatches: 5 },
},
{
id: 'carrier-dispatch',
type: 'carrier_dispatch',
enabled: false,
intervalSeconds: 60,
config: { limit: 50 },
},
{
id: 'product-normalize',
type: 'product_normalize',
enabled: true,
intervalSeconds: 300,
config: {},
},
{
id: 'cost-snapshot',
type: 'cost_snapshot',
enabled: true,
intervalSeconds: 300,
config: {},
},
{
id: 'sales-facts',
type: 'sales_facts',
enabled: true,
intervalSeconds: 600,
config: { days: 7 },
},
{
id: 'ledger-post',
type: 'ledger_post',
enabled: true,
intervalSeconds: 600,
config: { days: 7 },
},
],
})
const byType = new Map(config.jobs.map((item) => [item.type, item]))
assert.equal(byType.get('channel_assign')?.config.batchSize, 800)
assert.equal(byType.get('carrier_dispatch')?.enabled, false)
assert.equal(byType.get('sales_facts')?.config.days, 7)
assert.equal(byType.get('ledger_post')?.config.days, 7)
assert.ok(byType.has('product_normalize'))
assert.ok(byType.has('cost_snapshot'))
})
test('normalizeScheduledJobsConfig 丢弃未知任务类型', () => {
const config = normalizeScheduledJobsConfig({
enabled: true,
jobs: [{ id: 'nope', type: 'unknown_type', enabled: true, intervalSeconds: 60, config: {} }],
})
assert.equal(
config.jobs.some((item) => item.type === 'unknown_type'),
false,
)
})