mirror of
https://github.com/langgenius/dify.git
synced 2026-04-12 22:17:09 +08:00
Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: lif <1835304752@qq.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: Stephen Zhou <hi@hyoban.cc> Co-authored-by: tmimmanuel <14046872+tmimmanuel@users.noreply.github.com> Co-authored-by: Desel72 <pedroluiscolmenares722@gmail.com> Co-authored-by: Renzo <170978465+RenzoMXD@users.noreply.github.com> Co-authored-by: Krishna Chaitanya <krishnabkc15@gmail.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { DSLImportStatus } from '@/models/app'
|
|
import { AppModeEnum } from '@/types/app'
|
|
import { BlockEnum } from '../types'
|
|
import {
|
|
getInvalidNodeTypes,
|
|
isImportCompleted,
|
|
normalizeWorkflowFeatures,
|
|
validateDSLContent,
|
|
} from '../update-dsl-modal.helpers'
|
|
|
|
describe('update-dsl-modal helpers', () => {
|
|
describe('dsl validation', () => {
|
|
it('should reject advanced chat dsl content with disallowed trigger nodes', () => {
|
|
const content = `
|
|
workflow:
|
|
graph:
|
|
nodes:
|
|
- data:
|
|
type: trigger-webhook
|
|
`
|
|
|
|
expect(validateDSLContent(content, AppModeEnum.ADVANCED_CHAT)).toBe(false)
|
|
})
|
|
|
|
it('should reject malformed yaml and answer nodes in non-advanced mode', () => {
|
|
expect(validateDSLContent('[', AppModeEnum.CHAT)).toBe(false)
|
|
expect(validateDSLContent(`
|
|
workflow:
|
|
graph:
|
|
nodes:
|
|
- data:
|
|
type: answer
|
|
`, AppModeEnum.CHAT)).toBe(false)
|
|
})
|
|
|
|
it('should accept valid node types for advanced chat mode', () => {
|
|
expect(validateDSLContent(`
|
|
workflow:
|
|
graph:
|
|
nodes:
|
|
- data:
|
|
type: tool
|
|
`, AppModeEnum.ADVANCED_CHAT)).toBe(true)
|
|
})
|
|
|
|
it('should expose the invalid node sets per mode', () => {
|
|
expect(getInvalidNodeTypes(AppModeEnum.ADVANCED_CHAT)).toEqual(
|
|
expect.arrayContaining([BlockEnum.End, BlockEnum.TriggerWebhook]),
|
|
)
|
|
expect(getInvalidNodeTypes(AppModeEnum.CHAT)).toEqual([BlockEnum.Answer])
|
|
})
|
|
})
|
|
|
|
describe('status and feature normalization', () => {
|
|
it('should treat completed statuses as successful imports', () => {
|
|
expect(isImportCompleted(DSLImportStatus.COMPLETED)).toBe(true)
|
|
expect(isImportCompleted(DSLImportStatus.COMPLETED_WITH_WARNINGS)).toBe(true)
|
|
expect(isImportCompleted(DSLImportStatus.PENDING)).toBe(false)
|
|
})
|
|
|
|
it('should normalize workflow features with defaults', () => {
|
|
const features = normalizeWorkflowFeatures({
|
|
file_upload: {
|
|
image: {
|
|
enabled: true,
|
|
},
|
|
},
|
|
opening_statement: 'hello',
|
|
suggested_questions: ['what can you do?'],
|
|
})
|
|
|
|
expect(features.file.enabled).toBe(true)
|
|
expect(features.file.number_limits).toBe(3)
|
|
expect(features.opening.enabled).toBe(true)
|
|
expect(features.suggested).toEqual({ enabled: false })
|
|
expect(features.text2speech).toEqual({ enabled: false })
|
|
})
|
|
})
|
|
})
|