@@ -35,7 +35,7 @@ import {
35
35
import { createRoomWidgetClient , MsgType , UpdateDelayedEventAction } from "../../src/matrix" ;
36
36
import { MatrixClient , ClientEvent , ITurnServer as IClientTurnServer } from "../../src/client" ;
37
37
import { SyncState } from "../../src/sync" ;
38
- import { ICapabilities } from "../../src/embedded" ;
38
+ import { ICapabilities , RoomWidgetClient } from "../../src/embedded" ;
39
39
import { MatrixEvent } from "../../src/models/event" ;
40
40
import { ToDeviceBatch } from "../../src/models/ToDeviceMessage" ;
41
41
import { DeviceInfo } from "../../src/crypto/deviceinfo" ;
@@ -493,6 +493,23 @@ describe("RoomWidgetClient", () => {
493
493
[ "@bob:example.org" ] : { [ "bobDesktop" ] : { hello : "bob!" } } ,
494
494
} ;
495
495
496
+ const encryptedContentMap = new Map < string , Map < string , object > > ( [
497
+ [ "@alice:example.org" , new Map ( [ [ "aliceMobile" , { hello : "alice!" } ] ] ) ] ,
498
+ [ "@bob:example.org" , new Map ( [ [ "bobDesktop" , { hello : "bob!" } ] ] ) ] ,
499
+ ] ) ;
500
+
501
+ it ( "sends unencrypted (sendToDeviceViaWidgetApi)" , async ( ) => {
502
+ await makeClient ( { sendToDevice : [ "org.example.foo" ] } ) ;
503
+ expect ( widgetApi . requestCapabilityToSendToDevice ) . toHaveBeenCalledWith ( "org.example.foo" ) ;
504
+
505
+ await ( client as RoomWidgetClient ) . sendToDeviceViaWidgetApi (
506
+ "org.example.foo" ,
507
+ false ,
508
+ unencryptedContentMap ,
509
+ ) ;
510
+ expect ( widgetApi . sendToDevice ) . toHaveBeenCalledWith ( "org.example.foo" , false , expectedRequestData ) ;
511
+ } ) ;
512
+
496
513
it ( "sends unencrypted (sendToDevice)" , async ( ) => {
497
514
await makeClient ( { sendToDevice : [ "org.example.foo" ] } ) ;
498
515
expect ( widgetApi . requestCapabilityToSendToDevice ) . toHaveBeenCalledWith ( "org.example.foo" ) ;
@@ -534,6 +551,17 @@ describe("RoomWidgetClient", () => {
534
551
} ) ;
535
552
} ) ;
536
553
554
+ it ( "sends encrypted (sendToDeviceViaWidgetApi)" , async ( ) => {
555
+ await makeClient ( { sendToDevice : [ "org.example.foo" ] } ) ;
556
+ expect ( widgetApi . requestCapabilityToSendToDevice ) . toHaveBeenCalledWith ( "org.example.foo" ) ;
557
+
558
+ await ( client as RoomWidgetClient ) . sendToDeviceViaWidgetApi ( "org.example.foo" , true , encryptedContentMap ) ;
559
+ expect ( widgetApi . sendToDevice ) . toHaveBeenCalledWith ( "org.example.foo" , true , {
560
+ "@alice:example.org" : { aliceMobile : { hello : "alice!" } } ,
561
+ "@bob:example.org" : { bobDesktop : { hello : "bob!" } } ,
562
+ } ) ;
563
+ } ) ;
564
+
537
565
it . each ( [
538
566
{ encrypted : false , title : "unencrypted" } ,
539
567
{ encrypted : true , title : "encrypted" } ,
0 commit comments