fix(data): 清理旧数据并保护服务端写入

This commit is contained in:
Script Generator
2026-07-02 09:30:50 +08:00
parent 28e0c6de19
commit 916bd17a48
38 changed files with 1346 additions and 194 deletions

View File

@@ -0,0 +1,35 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import type { SourceTarget } from './requirement';
import {
filterSourceTargetsByKeyword,
formatSourceTargetSelection,
parseSourceTargetSelection,
} from './requirement';
const targets: SourceTarget[] = [
{ id: 'st-1', name: 'Alpha Bank', sourceType: 'customer', createdAt: '2026-07-01' },
{ id: 'st-2', name: 'Beta Retail', sourceType: 'customer', createdAt: '2026-07-01' },
{ id: 'st-3', name: 'Product Team', sourceType: 'internal', createdAt: '2026-07-01' },
];
test('parses and formats requirement source target multi-selection', () => {
assert.deepEqual(parseSourceTargetSelection('Alpha Bank、 Beta Retail, Product TeamAlpha Bank'), [
'Alpha Bank',
'Beta Retail',
'Product Team',
]);
assert.equal(formatSourceTargetSelection(['Alpha Bank', '', 'Beta Retail', 'Alpha Bank']), 'Alpha Bank、Beta Retail');
});
test('filters source targets by source type and keyword', () => {
assert.deepEqual(
filterSourceTargetsByKeyword(targets, 'customer', 'bank').map((target) => target.id),
['st-1'],
);
assert.deepEqual(
filterSourceTargetsByKeyword(targets, 'internal', '').map((target) => target.id),
['st-3'],
);
});