本仓 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,未来以本仓历史为主
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
/**
|
|
* vitest test: role/_validate.ts (Phase D2 E2E 自动化)
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import { validateRoleCreate } from '../../../src/commands/role/_validate.ts'
|
|
|
|
describe('role/_validate.ts step machine', () => {
|
|
it('成功路径: 合法 fullName + enCode + type', () => {
|
|
const r = validateRoleCreate({
|
|
fullName: '测试角色',
|
|
enCode: 'test_role',
|
|
type: 0,
|
|
enabledMark: 1,
|
|
sortCode: 0,
|
|
})
|
|
expect(r.ok).toBe(true)
|
|
})
|
|
|
|
it('enCode 含下划线 → 拦截', () => {
|
|
const r = validateRoleCreate({
|
|
fullName: 'X',
|
|
enCode: 'bad_underscore',
|
|
type: 0,
|
|
})
|
|
expect(r.steps[0].errors.some((e) => e.field === 'enCode')).toBe(true)
|
|
})
|
|
|
|
it('type 非法 → 拦截', () => {
|
|
const r = validateRoleCreate({
|
|
fullName: 'X',
|
|
enCode: 'xtest',
|
|
type: 9,
|
|
})
|
|
expect(r.steps[0].errors.some((e) => e.field === 'type')).toBe(true)
|
|
})
|
|
|
|
it('isCondition=true 但 constraintType 空 → 拦截', () => {
|
|
const r = validateRoleCreate({
|
|
fullName: 'X',
|
|
enCode: 'xtest',
|
|
type: 0,
|
|
isCondition: 1,
|
|
})
|
|
expect(r.steps[1].errors.some((e) => e.field === 'constraintType')).toBe(true)
|
|
})
|
|
|
|
it('enCode 全平台唯一 → EXIST002 (BS-47)', () => {
|
|
const r = validateRoleCreate({
|
|
fullName: 'X',
|
|
enCode: 'dup_role',
|
|
type: 0,
|
|
existingRoles: [{ fullName: '已存在', enCode: 'dup_role', type: 0 }],
|
|
})
|
|
expect(r.steps[2].errors.some((e) => e.code === 'EXIST002')).toBe(true)
|
|
})
|
|
}) |