@@ -2,9 +2,14 @@ import { describe, expect, it, vi } from 'vitest'
22
33vi . unmock ( '@/blocks/registry' )
44
5+ vi . mock ( '@/lib/api/client/request' , ( ) => ( {
6+ requestJson : vi . fn ( ) . mockResolvedValue ( { } ) ,
7+ } ) )
8+
59import {
610 extractWorkflowName ,
711 parseWorkflowJson ,
12+ persistImportedWorkflow ,
813 sanitizePathSegment ,
914} from '@/lib/workflows/operations/import-export'
1015
@@ -134,6 +139,67 @@ describe('workflow import/export parsing', () => {
134139 } )
135140} )
136141
142+ describe ( 'persistImportedWorkflow description handling' , ( ) => {
143+ function buildContent ( description ?: string ) {
144+ const state = createLegacyState ( )
145+ return JSON . stringify ( {
146+ data : {
147+ version : '1.0' ,
148+ workflow : { name : 'Imported Workflow' } ,
149+ state : {
150+ ...state ,
151+ metadata : { name : 'Imported Workflow' , description } ,
152+ } ,
153+ } ,
154+ } )
155+ }
156+
157+ async function importWithContent ( content : string , descriptionOverride ?: string ) {
158+ const createWorkflow = vi . fn ( ) . mockResolvedValue ( { id : 'wf-1' } )
159+ await persistImportedWorkflow ( {
160+ content,
161+ filename : 'imported-workflow.json' ,
162+ workspaceId : 'ws-1' ,
163+ descriptionOverride,
164+ createWorkflow,
165+ } )
166+ return createWorkflow . mock . calls [ 0 ] [ 0 ] . description as string
167+ }
168+
169+ it ( 'scrubs placeholder metadata descriptions to an empty string' , async ( ) => {
170+ expect ( await importWithContent ( buildContent ( 'New workflow' ) ) ) . toBe ( '' )
171+ expect (
172+ await importWithContent ( buildContent ( 'Your first workflow - start building here!' ) )
173+ ) . toBe ( '' )
174+ } )
175+
176+ it ( 'scrubs name-equal metadata descriptions to an empty string' , async ( ) => {
177+ expect ( await importWithContent ( buildContent ( 'Imported Workflow' ) ) ) . toBe ( '' )
178+ } )
179+
180+ it ( 'preserves meaningful metadata descriptions' , async ( ) => {
181+ expect ( await importWithContent ( buildContent ( 'Syncs leads from HubSpot to Slack' ) ) ) . toBe (
182+ 'Syncs leads from HubSpot to Slack'
183+ )
184+ } )
185+
186+ it ( 'uses an empty string when no description is present' , async ( ) => {
187+ expect ( await importWithContent ( buildContent ( undefined ) ) ) . toBe ( '' )
188+ } )
189+
190+ it ( 'prefers a meaningful override over metadata' , async ( ) => {
191+ expect (
192+ await importWithContent ( buildContent ( 'Metadata description' ) , 'Override description' )
193+ ) . toBe ( 'Override description' )
194+ } )
195+
196+ it ( 'falls back to meaningful metadata when the override is a placeholder' , async ( ) => {
197+ expect ( await importWithContent ( buildContent ( 'Metadata description' ) , 'New workflow' ) ) . toBe (
198+ 'Metadata description'
199+ )
200+ } )
201+ } )
202+
137203describe ( 'sanitizePathSegment' , ( ) => {
138204 it ( 'should preserve ASCII alphanumeric characters' , ( ) => {
139205 expect ( sanitizePathSegment ( 'workflow-123_abc' ) ) . toBe ( 'workflow-123_abc' )
0 commit comments