@@ -453,6 +453,93 @@ describe('ClientWidgetApi', () => {
453453                roomId , 
454454            ) ; 
455455        } ) ; 
456+ 
457+         it ( 'should reject requests when the driver throws an exception' ,  async  ( )  =>  { 
458+             driver . sendDelayedEvent . mockRejectedValue ( 
459+                 new  Error ( "M_BAD_JSON: Content must be a JSON object" ) , 
460+             ) ; 
461+ 
462+             const  event : ISendEventFromWidgetActionRequest  =  { 
463+                 api : WidgetApiDirection . FromWidget , 
464+                 widgetId : 'test' , 
465+                 requestId : '0' , 
466+                 action : WidgetApiFromWidgetAction . SendEvent , 
467+                 data : { 
468+                     type : 'm.room.message' , 
469+                     content : 'hello' , 
470+                     delay : 5000 , 
471+                     parent_delay_id : 'fp' , 
472+                 } , 
473+             } ; 
474+ 
475+             await  loadIframe ( [ 
476+                 `org.matrix.msc2762.timeline:${ event . data . room_id }  ` , 
477+                 `org.matrix.msc2762.send.event:${ event . data . type }  ` , 
478+                 'org.matrix.msc4157.send.delayed_event' , 
479+             ] ) ; 
480+ 
481+             emitEvent ( new  CustomEvent ( '' ,  {  detail : event  } ) ) ; 
482+ 
483+             await  waitFor ( ( )  =>  { 
484+                 expect ( transport . reply ) . toBeCalledWith ( event ,  { 
485+                     error : {  message : 'Error sending event'  } , 
486+                 } ) ; 
487+             } ) ; 
488+         } ) ; 
489+ 
490+         it ( 'should reject with Matrix API error response thrown by driver' ,  async  ( )  =>  { 
491+             driver . processError . mockImplementation ( processCustomMatrixError ) ; 
492+ 
493+             driver . sendDelayedEvent . mockRejectedValue ( 
494+                 new  CustomMatrixError ( 
495+                     'failed to send event' , 
496+                     400 , 
497+                     'M_NOT_JSON' , 
498+                     { 
499+                         reason : 'Content must be a JSON object.' , 
500+                     } , 
501+                 ) , 
502+             ) ; 
503+ 
504+             const  event : ISendEventFromWidgetActionRequest  =  { 
505+                 api : WidgetApiDirection . FromWidget , 
506+                 widgetId : 'test' , 
507+                 requestId : '0' , 
508+                 action : WidgetApiFromWidgetAction . SendEvent , 
509+                 data : { 
510+                     type : 'm.room.message' , 
511+                     content : 'hello' , 
512+                     delay : 5000 , 
513+                     parent_delay_id : 'fp' , 
514+                 } , 
515+             } ; 
516+ 
517+             await  loadIframe ( [ 
518+                 `org.matrix.msc2762.timeline:${ event . data . room_id }  ` , 
519+                 `org.matrix.msc2762.send.event:${ event . data . type }  ` , 
520+                 'org.matrix.msc4157.send.delayed_event' , 
521+             ] ) ; 
522+ 
523+             emitEvent ( new  CustomEvent ( '' ,  {  detail : event  } ) ) ; 
524+ 
525+             await  waitFor ( ( )  =>  { 
526+                 expect ( transport . reply ) . toBeCalledWith ( event ,  { 
527+                     error : { 
528+                         message : 'Error sending event' , 
529+                         matrix_api_error : { 
530+                             http_status : 400 , 
531+                             http_headers : { } , 
532+                             url : '' , 
533+                             response : { 
534+                                 errcode : 'M_NOT_JSON' , 
535+                                 error : 'failed to send event' , 
536+                                 reason : 'Content must be a JSON object.' , 
537+                             } , 
538+                         }  satisfies  IMatrixApiError , 
539+                     } , 
540+                 } ) ; 
541+             } ) ; 
542+         } ) ; 
456543    } ) ; 
457544
458545    describe ( 'update_delayed_event action' ,  ( )  =>  { 
@@ -539,6 +626,81 @@ describe('ClientWidgetApi', () => {
539626                ) ; 
540627            } 
541628        } ) ; 
629+ 
630+         it ( 'should reject requests when the driver throws an exception' ,  async  ( )  =>  { 
631+             driver . updateDelayedEvent . mockRejectedValue ( 
632+                 new  Error ( "M_BAD_JSON: Content must be a JSON object" ) , 
633+             ) ; 
634+ 
635+             const  event : IUpdateDelayedEventFromWidgetActionRequest  =  { 
636+                 api : WidgetApiDirection . FromWidget , 
637+                 widgetId : 'test' , 
638+                 requestId : '0' , 
639+                 action : WidgetApiFromWidgetAction . MSC4157UpdateDelayedEvent , 
640+                 data : { 
641+                     delay_id : 'f' , 
642+                     action : UpdateDelayedEventAction . Send , 
643+                 } , 
644+             } ; 
645+ 
646+             await  loadIframe ( [ 'org.matrix.msc4157.update_delayed_event' ] ) ; 
647+ 
648+             emitEvent ( new  CustomEvent ( '' ,  {  detail : event  } ) ) ; 
649+ 
650+             await  waitFor ( ( )  =>  { 
651+                 expect ( transport . reply ) . toBeCalledWith ( event ,  { 
652+                     error : {  message : 'Error updating delayed event'  } , 
653+                 } ) ; 
654+             } ) ; 
655+         } ) ; 
656+ 
657+         it ( 'should reject with Matrix API error response thrown by driver' ,  async  ( )  =>  { 
658+             driver . processError . mockImplementation ( processCustomMatrixError ) ; 
659+ 
660+             driver . updateDelayedEvent . mockRejectedValue ( 
661+                 new  CustomMatrixError ( 
662+                     'failed to update delayed event' , 
663+                     400 , 
664+                     'M_NOT_JSON' , 
665+                     { 
666+                         reason : 'Content must be a JSON object.' , 
667+                     } , 
668+                 ) , 
669+             ) ; 
670+ 
671+             const  event : IUpdateDelayedEventFromWidgetActionRequest  =  { 
672+                 api : WidgetApiDirection . FromWidget , 
673+                 widgetId : 'test' , 
674+                 requestId : '0' , 
675+                 action : WidgetApiFromWidgetAction . MSC4157UpdateDelayedEvent , 
676+                 data : { 
677+                     delay_id : 'f' , 
678+                     action : UpdateDelayedEventAction . Send , 
679+                 } , 
680+             } ; 
681+ 
682+             await  loadIframe ( [ 'org.matrix.msc4157.update_delayed_event' ] ) ; 
683+ 
684+             emitEvent ( new  CustomEvent ( '' ,  {  detail : event  } ) ) ; 
685+ 
686+             await  waitFor ( ( )  =>  { 
687+                 expect ( transport . reply ) . toBeCalledWith ( event ,  { 
688+                     error : { 
689+                         message : 'Error updating delayed event' , 
690+                         matrix_api_error : { 
691+                             http_status : 400 , 
692+                             http_headers : { } , 
693+                             url : '' , 
694+                             response : { 
695+                                 errcode : 'M_NOT_JSON' , 
696+                                 error : 'failed to update delayed event' , 
697+                                 reason : 'Content must be a JSON object.' , 
698+                             } , 
699+                         }  satisfies  IMatrixApiError , 
700+                     } , 
701+                 } ) ; 
702+             } ) ; 
703+         } ) ; 
542704    } ) ; 
543705
544706    describe ( 'org.matrix.msc2876.read_events action' ,  ( )  =>  { 
0 commit comments