@@ -728,4 +728,128 @@ describe("MatrixClient", function() {
728
728
expect ( httpLookups . length ) . toEqual ( 0 ) ;
729
729
} ) ;
730
730
} ) ;
731
+
732
+ describe ( "sendEvent" , ( ) => {
733
+ const roomId = "!room:example.org" ;
734
+ const body = "This is the body" ;
735
+ const content = { body } ;
736
+
737
+ it ( "overload without threadId works" , async ( ) => {
738
+ const eventId = "$eventId:example.org" ;
739
+ const txnId = client . makeTxnId ( ) ;
740
+ httpLookups = [ {
741
+ method : "PUT" ,
742
+ path : `/rooms/${ encodeURIComponent ( roomId ) } /send/m.room.message/${ txnId } ` ,
743
+ data : { event_id : eventId } ,
744
+ expectBody : content ,
745
+ } ] ;
746
+
747
+ await client . sendEvent ( roomId , EventType . RoomMessage , content , txnId ) ;
748
+ } ) ;
749
+
750
+ it ( "overload with null threadId works" , async ( ) => {
751
+ const eventId = "$eventId:example.org" ;
752
+ const txnId = client . makeTxnId ( ) ;
753
+ httpLookups = [ {
754
+ method : "PUT" ,
755
+ path : `/rooms/${ encodeURIComponent ( roomId ) } /send/m.room.message/${ txnId } ` ,
756
+ data : { event_id : eventId } ,
757
+ expectBody : content ,
758
+ } ] ;
759
+
760
+ await client . sendEvent ( roomId , null , EventType . RoomMessage , content , txnId ) ;
761
+ } ) ;
762
+
763
+ it ( "overload with threadId works" , async ( ) => {
764
+ const eventId = "$eventId:example.org" ;
765
+ const txnId = client . makeTxnId ( ) ;
766
+ httpLookups = [ {
767
+ method : "PUT" ,
768
+ path : `/rooms/${ encodeURIComponent ( roomId ) } /send/m.room.message/${ txnId } ` ,
769
+ data : { event_id : eventId } ,
770
+ expectBody : content ,
771
+ } ] ;
772
+
773
+ await client . sendEvent ( roomId , "$threadId:server" , EventType . RoomMessage , content , txnId ) ;
774
+ } ) ;
775
+ } ) ;
776
+
777
+ describe ( "redactEvent" , ( ) => {
778
+ const roomId = "!room:example.org" ;
779
+ const mockRoom = {
780
+ getMyMembership : ( ) => "join" ,
781
+ currentState : {
782
+ getStateEvents : ( eventType , stateKey ) => {
783
+ if ( eventType === EventType . RoomEncryption ) {
784
+ expect ( stateKey ) . toEqual ( "" ) ;
785
+ return new MatrixEvent ( { content : { } } ) ;
786
+ } else {
787
+ throw new Error ( "Unexpected event type or state key" ) ;
788
+ }
789
+ } ,
790
+ } ,
791
+ threads : {
792
+ get : jest . fn ( ) ,
793
+ } ,
794
+ addPendingEvent : jest . fn ( ) ,
795
+ updatePendingEvent : jest . fn ( ) ,
796
+ } ;
797
+
798
+ beforeEach ( ( ) => {
799
+ client . getRoom = ( getRoomId ) => {
800
+ expect ( getRoomId ) . toEqual ( roomId ) ;
801
+ return mockRoom ;
802
+ } ;
803
+ } ) ;
804
+
805
+ it ( "overload without threadId works" , async ( ) => {
806
+ const eventId = "$eventId:example.org" ;
807
+ const txnId = client . makeTxnId ( ) ;
808
+ httpLookups = [ {
809
+ method : "PUT" ,
810
+ path : `/rooms/${ encodeURIComponent ( roomId ) } /redact/${ encodeURIComponent ( eventId ) } /${ txnId } ` ,
811
+ data : { event_id : eventId } ,
812
+ } ] ;
813
+
814
+ await client . redactEvent ( roomId , eventId , txnId ) ;
815
+ } ) ;
816
+
817
+ it ( "overload with null threadId works" , async ( ) => {
818
+ const eventId = "$eventId:example.org" ;
819
+ const txnId = client . makeTxnId ( ) ;
820
+ httpLookups = [ {
821
+ method : "PUT" ,
822
+ path : `/rooms/${ encodeURIComponent ( roomId ) } /redact/${ encodeURIComponent ( eventId ) } /${ txnId } ` ,
823
+ data : { event_id : eventId } ,
824
+ } ] ;
825
+
826
+ await client . redactEvent ( roomId , null , eventId , txnId ) ;
827
+ } ) ;
828
+
829
+ it ( "overload with threadId works" , async ( ) => {
830
+ const eventId = "$eventId:example.org" ;
831
+ const txnId = client . makeTxnId ( ) ;
832
+ httpLookups = [ {
833
+ method : "PUT" ,
834
+ path : `/rooms/${ encodeURIComponent ( roomId ) } /redact/${ encodeURIComponent ( eventId ) } /${ txnId } ` ,
835
+ data : { event_id : eventId } ,
836
+ } ] ;
837
+
838
+ await client . redactEvent ( roomId , "$threadId:server" , eventId , txnId ) ;
839
+ } ) ;
840
+
841
+ it ( "does not get wrongly encrypted" , async ( ) => {
842
+ const eventId = "$eventId:example.org" ;
843
+ const txnId = client . makeTxnId ( ) ;
844
+ const reason = "This is the redaction reason" ;
845
+ httpLookups = [ {
846
+ method : "PUT" ,
847
+ path : `/rooms/${ encodeURIComponent ( roomId ) } /redact/${ encodeURIComponent ( eventId ) } /${ txnId } ` ,
848
+ expectBody : { reason } , // NOT ENCRYPTED
849
+ data : { event_id : eventId } ,
850
+ } ] ;
851
+
852
+ await client . redactEvent ( roomId , eventId , txnId , { reason } ) ;
853
+ } ) ;
854
+ } ) ;
731
855
} ) ;
0 commit comments