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, ) })