@@ -31,6 +31,7 @@ vi.mock('@/lib/workflows/active-context', () => ({
3131
3232import {
3333 authorizeWorkflowByWorkspacePermission ,
34+ setWorkflowVariables ,
3435 validateWorkflowPermissions ,
3536} from '@/lib/workflows/utils'
3637
@@ -363,3 +364,30 @@ describe('authorizeWorkflowByWorkspacePermission', () => {
363364 expect ( mockGetActiveWorkflowContext ) . not . toHaveBeenCalled ( )
364365 } )
365366} )
367+
368+ describe ( 'setWorkflowVariables' , ( ) => {
369+ beforeEach ( ( ) => {
370+ vi . clearAllMocks ( )
371+ } )
372+
373+ it ( 'persists variables to the workflow row' , async ( ) => {
374+ const snapshotVariables = {
375+ var1 : { id : 'var1' , name : 'API Token' , type : 'string' , value : 'secret' } ,
376+ }
377+
378+ const mockWhere = vi . fn ( ) . mockResolvedValue ( undefined )
379+ const mockSet = vi . fn ( ( ) => ( { where : mockWhere } ) )
380+ vi . mocked ( mockDb . update ) . mockReturnValue ( { set : mockSet } as any )
381+
382+ await setWorkflowVariables ( 'wf-1' , snapshotVariables )
383+
384+ expect ( mockDb . update ) . toHaveBeenCalled ( )
385+ expect ( mockSet ) . toHaveBeenCalledWith (
386+ expect . objectContaining ( {
387+ variables : snapshotVariables ,
388+ updatedAt : expect . any ( Date ) ,
389+ } )
390+ )
391+ expect ( mockWhere ) . toHaveBeenCalled ( )
392+ } )
393+ } )
0 commit comments