本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的 dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。 - 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12) - 历史未带 ssw main 整体历史(避免大仓污染) - 此为新仓基线 commit,未来以本仓历史为主
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
/**
|
|
* vitest test: dict/_validate.ts (Phase D2 E2E 自动化)
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import { validateDictTypeCreate } from '../../../src/commands/dict/_validate.ts'
|
|
|
|
describe('dict/_validate.ts step machine', () => {
|
|
it('成功路径: 合法 fullName + enCode + parentId', () => {
|
|
const r = validateDictTypeCreate({
|
|
parentId: '0',
|
|
fullName: '测试字典',
|
|
enCode: 'test_dict',
|
|
isTree: 0,
|
|
sortCode: 0,
|
|
})
|
|
expect(r.ok).toBe(true)
|
|
})
|
|
|
|
it('enCode 重复 → EXIST002 (BS-47)', () => {
|
|
const r = validateDictTypeCreate({
|
|
parentId: '0',
|
|
fullName: '新字典',
|
|
enCode: 'dup_dict',
|
|
isTree: 0,
|
|
sortCode: 0,
|
|
existingTypes: [{ fullName: '已存在', enCode: 'dup_dict' }],
|
|
})
|
|
expect(r.steps[1].errors.some((e) => e.code === 'EXIST002')).toBe(true)
|
|
})
|
|
|
|
it('fullName 重复 → EXIST001 (BS-47)', () => {
|
|
const r = validateDictTypeCreate({
|
|
parentId: '0',
|
|
fullName: '重复字典',
|
|
enCode: 'new_dict',
|
|
isTree: 0,
|
|
sortCode: 0,
|
|
existingTypes: [{ fullName: '重复字典', enCode: 'existing' }],
|
|
})
|
|
expect(r.steps[1].errors.some((e) => e.code === 'EXIST001')).toBe(true)
|
|
})
|
|
|
|
it('enCode 含下划线 → 拦截', () => {
|
|
const r = validateDictTypeCreate({
|
|
parentId: '0',
|
|
fullName: 'X',
|
|
enCode: 'bad_underscore',
|
|
isTree: 0,
|
|
sortCode: 0,
|
|
})
|
|
expect(r.steps[0].errors.some((e) => e.field === 'enCode')).toBe(true)
|
|
})
|
|
|
|
it('items enCode 重复 → 拦截', () => {
|
|
const r = validateDictTypeCreate({
|
|
parentId: '0',
|
|
fullName: 'X',
|
|
enCode: 'xtest',
|
|
items: [
|
|
{ enCode: 'dup_item', fullName: 'X1' },
|
|
{ enCode: 'dup_item', fullName: 'X2' },
|
|
],
|
|
})
|
|
expect(r.steps[2].errors.some((e) => e.message.includes('已重复'))).toBe(true)
|
|
})
|
|
}) |