@@ -155,4 +155,73 @@ describe('Workflow deployment version revert route', () => {
155155 } )
156156 )
157157 } )
158+
159+ it ( 'restores variables from the deployment snapshot' , async ( ) => {
160+ mockDbLimit . mockResolvedValue ( [
161+ {
162+ state : {
163+ blocks : { 'block-1' : { id : 'block-1' , type : 'start_trigger' , name : 'Start' } } ,
164+ edges : [ ] ,
165+ loops : { } ,
166+ parallels : { } ,
167+ variables : {
168+ var1 : { id : 'var1' , name : 'API Token' , type : 'string' , value : 'secret' } ,
169+ } ,
170+ } ,
171+ } ,
172+ ] )
173+ mockValidateWorkflowAccess . mockResolvedValue ( {
174+ workflow : { id : 'wf-1' , name : 'Test Workflow' , workspaceId : 'ws-1' } ,
175+ auth : {
176+ success : true ,
177+ userId : 'api-user' ,
178+ userName : 'API Key Actor' ,
179+ userEmail : 'api@example.com' ,
180+ authType : 'api_key' ,
181+ } ,
182+ } )
183+
184+ const req = new NextRequest ( 'http://localhost:3000/api/workflows/wf-1/deployments/3/revert' , {
185+ method : 'POST' ,
186+ headers : { 'x-api-key' : 'test-key' } ,
187+ } )
188+
189+ await POST ( req , { params : Promise . resolve ( { id : 'wf-1' , version : '3' } ) } )
190+
191+ expect ( mockSaveWorkflowToNormalizedTables ) . toHaveBeenCalledWith (
192+ 'wf-1' ,
193+ expect . objectContaining ( {
194+ variables : {
195+ var1 : { id : 'var1' , name : 'API Token' , type : 'string' , value : 'secret' } ,
196+ } ,
197+ } )
198+ )
199+ } )
200+
201+ it ( 'defaults variables safely when missing from the deployment snapshot' , async ( ) => {
202+ mockValidateWorkflowAccess . mockResolvedValue ( {
203+ workflow : { id : 'wf-1' , name : 'Test Workflow' , workspaceId : 'ws-1' } ,
204+ auth : {
205+ success : true ,
206+ userId : 'api-user' ,
207+ userName : 'API Key Actor' ,
208+ userEmail : 'api@example.com' ,
209+ authType : 'api_key' ,
210+ } ,
211+ } )
212+
213+ const req = new NextRequest ( 'http://localhost:3000/api/workflows/wf-1/deployments/3/revert' , {
214+ method : 'POST' ,
215+ headers : { 'x-api-key' : 'test-key' } ,
216+ } )
217+
218+ await POST ( req , { params : Promise . resolve ( { id : 'wf-1' , version : '3' } ) } )
219+
220+ expect ( mockSaveWorkflowToNormalizedTables ) . toHaveBeenCalledWith (
221+ 'wf-1' ,
222+ expect . objectContaining ( {
223+ variables : { } ,
224+ } )
225+ )
226+ } )
158227} )
0 commit comments