本仓 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,未来以本仓历史为主
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
/**
|
|
* vitest test: dm/_validate.ts (Phase D2 E2E 自动化)
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import { validateDmCreate } from '../../../src/commands/dm/_validate.ts'
|
|
|
|
describe('dm/_validate.ts step machine', () => {
|
|
it('成功路径: 合法 table + 字段 + 主键', () => {
|
|
const r = validateDmCreate({
|
|
table: 'MyTable',
|
|
tableName: '测试表',
|
|
fields: [
|
|
{ field: 'f_id', fieldName: '主键', dataType: 'bigint', primaryKey: 1, allowNull: 0 },
|
|
{ field: 'f_name', fieldName: '名称', dataType: 'varchar', dataLength: '100', allowNull: 0 },
|
|
],
|
|
})
|
|
expect(r.ok).toBe(true)
|
|
})
|
|
|
|
it('dataType 非法 → 拦截', () => {
|
|
const r = validateDmCreate({
|
|
table: 'MyTable',
|
|
tableName: '测试表',
|
|
fields: [
|
|
{ field: 'f_id', fieldName: '主键', dataType: 'bigint', primaryKey: 1, allowNull: 0 },
|
|
{ field: 'f_bad', fieldName: '坏', dataType: 'BLOB', allowNull: 0 }, // 不在白名单
|
|
],
|
|
})
|
|
expect(r.ok).toBe(false)
|
|
expect(r.steps[1].errors.some((e) => e.field?.includes('dataType'))).toBe(true)
|
|
})
|
|
|
|
it('字段与系统列冲突 (f_description) → 拦截', () => {
|
|
const r = validateDmCreate({
|
|
table: 'MyTable',
|
|
tableName: '测试表',
|
|
fields: [
|
|
{ field: 'f_description', fieldName: '描述', dataType: 'text', allowNull: 0 }, // 系统自动注入列冲突
|
|
],
|
|
})
|
|
expect(r.steps[1].errors.some((e) => e.message.includes('系统自动注入列冲突'))).toBe(true)
|
|
})
|
|
|
|
it('主键 allowNull=1 → 拦截', () => {
|
|
const r = validateDmCreate({
|
|
table: 'MyTable',
|
|
tableName: '测试表',
|
|
fields: [
|
|
{ field: 'f_id', fieldName: '主键', dataType: 'bigint', primaryKey: 1, allowNull: 1 },
|
|
],
|
|
})
|
|
expect(r.steps[1].errors.some((e) => e.field?.includes('allowNull'))).toBe(true)
|
|
})
|
|
|
|
it('Java 关键字作表名 → 拦截', () => {
|
|
const r = validateDmCreate({
|
|
table: 'class', // Java 关键字
|
|
tableName: '测试表',
|
|
fields: [
|
|
{ field: 'f_id', fieldName: '主键', dataType: 'bigint', primaryKey: 1, allowNull: 0 },
|
|
],
|
|
})
|
|
expect(r.steps[2].errors.some((e) => e.field === 'table')).toBe(true)
|
|
})
|
|
}) |