fix(data): 清理旧数据并保护服务端写入
This commit is contained in:
35
apps/web/lib/requirement-source-target.test.ts
Normal file
35
apps/web/lib/requirement-source-target.test.ts
Normal 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 Team,Alpha 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'],
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user