@@ -49,9 +49,11 @@ describe('Copilot Checkpoints Revert API Route', () => {
4949
5050 authMockFns . mockGetSession . mockResolvedValue ( null )
5151
52+ /** Authorization is the route's workflow read, so an allowed result always carries one. */
5253 workflowAuthzMockFns . mockAuthorizeWorkflowByWorkspacePermission . mockResolvedValue ( {
5354 allowed : true ,
5455 status : 200 ,
56+ workflow : { id : 'b2c3d4e5-f6a7-4b89-a0d1-e2f3a4b5c6d7' , workspaceId : 'ws-123' } ,
5557 } )
5658
5759 mockGetAccessibleCopilotChat . mockResolvedValue ( { id : 'chat-123' , userId : 'user-123' } )
@@ -201,7 +203,12 @@ describe('Copilot Checkpoints Revert API Route', () => {
201203 }
202204
203205 queueTableRows ( schemaMock . workflowCheckpoints , [ mockCheckpoint ] )
204- queueTableRows ( schemaMock . workflow , [ ] )
206+ /** Authorization performs the workflow read, so a missing workflow surfaces through it. */
207+ workflowAuthzMockFns . mockAuthorizeWorkflowByWorkspacePermission . mockResolvedValueOnce ( {
208+ allowed : false ,
209+ status : 404 ,
210+ workflow : null ,
211+ } )
205212
206213 const req = new NextRequest ( 'http://localhost:3000/api/copilot/checkpoints/revert' , {
207214 method : 'POST' ,
@@ -214,6 +221,7 @@ describe('Copilot Checkpoints Revert API Route', () => {
214221 expect ( response . status ) . toBe ( 404 )
215222 const responseData = await response . json ( )
216223 expect ( responseData . error ) . toBe ( 'Workflow not found' )
224+ expect ( mockSaveWorkflowNormalizedState ) . not . toHaveBeenCalled ( )
217225 } )
218226
219227 it ( 'should return 401 when workflow belongs to different user' , async ( ) => {
@@ -237,6 +245,7 @@ describe('Copilot Checkpoints Revert API Route', () => {
237245 workflowAuthzMockFns . mockAuthorizeWorkflowByWorkspacePermission . mockResolvedValueOnce ( {
238246 allowed : false ,
239247 status : 403 ,
248+ workflow : { id : 'b2c3d4e5-f6a7-4b89-a0d1-e2f3a4b5c6d7' , workspaceId : 'ws-123' } ,
240249 } )
241250
242251 const req = new NextRequest ( 'http://localhost:3000/api/copilot/checkpoints/revert' , {
@@ -562,8 +571,9 @@ describe('Copilot Checkpoints Revert API Route', () => {
562571 }
563572
564573 dbChainMockFns . where . mockReturnValueOnce ( Promise . resolve ( [ mockCheckpoint ] ) )
565- dbChainMockFns . where . mockReturnValueOnce (
566- Promise . reject ( new Error ( 'Database error during workflow lookup' ) )
574+ /** Authorization performs the workflow read, so a failed lookup surfaces through it. */
575+ workflowAuthzMockFns . mockAuthorizeWorkflowByWorkspacePermission . mockRejectedValueOnce (
576+ new Error ( 'Database error during workflow lookup' )
567577 )
568578
569579 const req = new NextRequest ( 'http://localhost:3000/api/copilot/checkpoints/revert' , {
0 commit comments