Files
dacli/tests/unit/form_relationform_repair.test.ts
sushub f403a7e80e import: ssw/dacli@eea0ebc (2026-08-12) 起点版本
本仓 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,未来以本仓历史为主
2026-08-12 15:58:06 +08:00

30 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { applyNormalizedPatch, validateStrictSchema } from '../../src/commands/form/_schema_normalize.ts'
describe('relationForm 完整性 + 旧 schema 修复 (Task 2)', () => {
it('缺 modelId 触发 relationForm 合法化失败', () => {
const existing = [{ __vModel__: 'f_x', __config__: { jnpfKey: 'relationForm' } }]
const r = validateStrictSchema(existing)
expect(r.ok).toBe(false)
expect(r.errors[0]).toMatch(/modelId/)
})
it('旧 schema 缺 modelId,但 patch 提供合法 modelId → 修复成功', () => {
const existing = [{ __vModel__: 'f_x', __config__: { jnpfKey: 'relationForm' } }]
const merged = applyNormalizedPatch(existing, [{
__vModel__: 'f_x',
__config__: { jnpfKey: 'relationForm', modelId: '123', propsValue: 'f_x_name', relationField: 'f_x_ref' },
}])
const r = validateStrictSchema(merged)
expect(r.ok).toBe(true)
})
it('relationForm → select 后 relationField 必须清除', () => {
const existing = [{ __vModel__: 'f_x', __config__: { jnpfKey: 'relationForm', modelId: '123', relationField: 'f_x_ref' } }]
const merged = applyNormalizedPatch(existing, [{ __vModel__: 'f_x', __config__: { jnpfKey: 'select', optionsList: [] } }])
expect(merged[0].__config__.jnpfKey).toBe('select')
expect(merged[0].__config__.modelId).toBeUndefined()
expect(merged[0].__config__.relationField).toBeUndefined()
})
})