本仓 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,未来以本仓历史为主
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
/**
|
|
* vitest test: di/_validate.ts (Phase D2 E2E 自动化)
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import { validateDiUpdate } from '../../../src/commands/di/_validate.ts'
|
|
|
|
describe('di/_validate.ts step machine', () => {
|
|
it('成功路径: 合法 fullName + enCode + type=1 SQL', () => {
|
|
const r = validateDiUpdate({
|
|
fullName: '测试 DI',
|
|
enCode: 'test_di',
|
|
category: 'cat1',
|
|
type: 1,
|
|
action: 3,
|
|
enabledMark: 1,
|
|
sortCode: 0,
|
|
hasPage: 1,
|
|
isPostPosition: 0,
|
|
})
|
|
expect(r.ok).toBe(true)
|
|
})
|
|
|
|
it('type=1 SQL 但 action 空 → 拦截', () => {
|
|
const r = validateDiUpdate({
|
|
fullName: 'X',
|
|
enCode: 'xtest',
|
|
category: 'c',
|
|
type: 1,
|
|
action: undefined, // type=1 必填
|
|
})
|
|
expect(r.steps[1].errors.some((e) => e.field === 'action')).toBe(true)
|
|
})
|
|
|
|
it('type=2 静态 hasPage=1 不合理 → 拦截', () => {
|
|
const r = validateDiUpdate({
|
|
fullName: 'X',
|
|
enCode: 'xtest',
|
|
category: 'c',
|
|
type: 2,
|
|
action: 1,
|
|
hasPage: 1, // type=2 不建议启用分页
|
|
})
|
|
expect(r.steps[1].errors.some((e) => e.field === 'hasPage')).toBe(true)
|
|
})
|
|
|
|
it('enCode 无正则 (web 端 di 不强制正则, 与 menu/dict 不同)', () => {
|
|
const r = validateDiUpdate({
|
|
fullName: 'X',
|
|
enCode: 'bad_underscore', // 应允许, 无正则
|
|
category: 'c',
|
|
type: 2,
|
|
})
|
|
// 不应触发 enCode 正则校验
|
|
expect(r.steps[0].errors.some((e) => e.field === 'enCode' && e.message.includes('正则'))).toBe(false)
|
|
})
|
|
|
|
it('fullName 重复 → EXIST001', () => {
|
|
const r = validateDiUpdate({
|
|
fullName: '重复 DI',
|
|
enCode: 'new_di',
|
|
category: 'c',
|
|
type: 2,
|
|
existingDIs: [{ fullName: '重复 DI', enCode: 'old', id: 'other' }],
|
|
})
|
|
expect(r.steps[2].errors.some((e) => e.code === 'EXIST001')).toBe(true)
|
|
})
|
|
}) |