@@ -22,7 +22,9 @@ import {
22
22
KeysClaimRequest ,
23
23
KeysQueryRequest ,
24
24
KeysUploadRequest ,
25
+ RoomMessageRequest ,
25
26
SignatureUploadRequest ,
27
+ ToDeviceRequest ,
26
28
} from "@matrix-org/matrix-sdk-crypto-js" ;
27
29
28
30
import { TypedEventEmitter } from "../../../src/models/typed-event-emitter" ;
@@ -103,6 +105,58 @@ describe("OutgoingRequestProcessor", () => {
103
105
} ) ;
104
106
}
105
107
108
+ it ( "should handle ToDeviceRequests" , async ( ) => {
109
+ const testBody = '{ "foo": "bar" }' ;
110
+ const outgoingRequest = new ToDeviceRequest ( "1234" , "test/type" , "test/txnid" , testBody ) ;
111
+
112
+ const reqProm = processor . makeOutgoingRequest ( outgoingRequest ) ;
113
+
114
+ const testResponse = '{ "result": 1 }' ;
115
+ httpBackend
116
+ . when ( "PUT" , "/_matrix" )
117
+ . check ( ( req ) => {
118
+ expect ( req . path ) . toEqual ( "https://example.com/_matrix/client/v3/sendToDevice/test%2Ftype/test%2Ftxnid" ) ;
119
+ expect ( req . rawData ) . toEqual ( testBody ) ;
120
+ expect ( req . headers [ "Accept" ] ) . toEqual ( "application/json" ) ;
121
+ expect ( req . headers [ "Content-Type" ] ) . toEqual ( "application/json" ) ;
122
+ } )
123
+ . respond ( 200 , testResponse , true ) ;
124
+
125
+ const markSentCallPromise = awaitCallToMarkAsSent ( ) ;
126
+ await httpBackend . flushAllExpected ( ) ;
127
+
128
+ await Promise . all ( [ reqProm , markSentCallPromise ] ) ;
129
+ expect ( olmMachine . markRequestAsSent ) . toHaveBeenCalledWith ( "1234" , outgoingRequest . type , testResponse ) ;
130
+ httpBackend . verifyNoOutstandingRequests ( ) ;
131
+ } ) ;
132
+
133
+ it ( "should handle RoomMessageRequests" , async ( ) => {
134
+ const testBody = '{ "foo": "bar" }' ;
135
+ const outgoingRequest = new RoomMessageRequest ( "1234" , "test/room" , "test/txnid" , "test/type" , testBody ) ;
136
+
137
+ const reqProm = processor . makeOutgoingRequest ( outgoingRequest ) ;
138
+
139
+ const testResponse = '{ "result": 1 }' ;
140
+ httpBackend
141
+ . when ( "PUT" , "/_matrix" )
142
+ . check ( ( req ) => {
143
+ expect ( req . path ) . toEqual (
144
+ "https://example.com/_matrix/client/v3/room/test%2Froom/send/test%2Ftype/test%2Ftxnid" ,
145
+ ) ;
146
+ expect ( req . rawData ) . toEqual ( testBody ) ;
147
+ expect ( req . headers [ "Accept" ] ) . toEqual ( "application/json" ) ;
148
+ expect ( req . headers [ "Content-Type" ] ) . toEqual ( "application/json" ) ;
149
+ } )
150
+ . respond ( 200 , testResponse , true ) ;
151
+
152
+ const markSentCallPromise = awaitCallToMarkAsSent ( ) ;
153
+ await httpBackend . flushAllExpected ( ) ;
154
+
155
+ await Promise . all ( [ reqProm , markSentCallPromise ] ) ;
156
+ expect ( olmMachine . markRequestAsSent ) . toHaveBeenCalledWith ( "1234" , outgoingRequest . type , testResponse ) ;
157
+ httpBackend . verifyNoOutstandingRequests ( ) ;
158
+ } ) ;
159
+
106
160
it ( "does not explode with unknown requests" , async ( ) => {
107
161
const outgoingRequest = { id : "5678" , type : 987 } ;
108
162
const markSentCallPromise = awaitCallToMarkAsSent ( ) ;
0 commit comments