@@ -33,6 +33,7 @@ import * as testUtils from "../test-utils/test-utils";
3333import { makeBeaconInfoContent } from "../../src/content-helpers" ;
3434import { M_BEACON_INFO } from "../../src/@types/beacon" ;
3535import { Room } from "../../src" ;
36+ import { makeBeaconEvent } from "../test-utils/beacon" ;
3637
3738jest . useFakeTimers ( ) ;
3839
@@ -815,6 +816,9 @@ describe("MatrixClient", function() {
815816 } ,
816817 addPendingEvent : jest . fn ( ) ,
817818 updatePendingEvent : jest . fn ( ) ,
819+ reEmitter : {
820+ reEmit : jest . fn ( ) ,
821+ } ,
818822 } ;
819823
820824 beforeEach ( ( ) => {
@@ -999,10 +1003,10 @@ describe("MatrixClient", function() {
9991003 } ) ;
10001004
10011005 it ( "creates new beacon info" , async ( ) => {
1002- await client . unstable_createLiveBeacon ( roomId , content , '123' ) ;
1006+ await client . unstable_createLiveBeacon ( roomId , content ) ;
10031007
10041008 // event type combined
1005- const expectedEventType = ` ${ M_BEACON_INFO . name } . ${ userId } .123` ;
1009+ const expectedEventType = M_BEACON_INFO . name ;
10061010 const [ callback , method , path , queryParams , requestContent ] = client . http . authedRequest . mock . calls [ 0 ] ;
10071011 expect ( callback ) . toBeFalsy ( ) ;
10081012 expect ( method ) . toBe ( 'PUT' ) ;
@@ -1015,17 +1019,97 @@ describe("MatrixClient", function() {
10151019 } ) ;
10161020
10171021 it ( "updates beacon info with specific event type" , async ( ) => {
1018- const eventType = `${ M_BEACON_INFO . name } .${ userId } .456` ;
1019-
1020- await client . unstable_setLiveBeacon ( roomId , eventType , content ) ;
1022+ await client . unstable_setLiveBeacon ( roomId , content ) ;
10211023
10221024 // event type combined
10231025 const [ , , path , , requestContent ] = client . http . authedRequest . mock . calls [ 0 ] ;
10241026 expect ( path ) . toEqual (
10251027 `/rooms/${ encodeURIComponent ( roomId ) } /state/` +
1026- `${ encodeURIComponent ( eventType ) } /${ encodeURIComponent ( userId ) } ` ,
1028+ `${ encodeURIComponent ( M_BEACON_INFO . name ) } /${ encodeURIComponent ( userId ) } ` ,
10271029 ) ;
10281030 expect ( requestContent ) . toEqual ( content ) ;
10291031 } ) ;
1032+
1033+ describe ( 'processBeaconEvents()' , ( ) => {
1034+ it ( 'does nothing when events is falsy' , ( ) => {
1035+ const room = new Room ( roomId , client , userId ) ;
1036+ const roomStateProcessSpy = jest . spyOn ( room . currentState , 'processBeaconEvents' ) ;
1037+
1038+ client . processBeaconEvents ( room , undefined ) ;
1039+ expect ( roomStateProcessSpy ) . not . toHaveBeenCalled ( ) ;
1040+ } ) ;
1041+
1042+ it ( 'does nothing when events is of length 0' , ( ) => {
1043+ const room = new Room ( roomId , client , userId ) ;
1044+ const roomStateProcessSpy = jest . spyOn ( room . currentState , 'processBeaconEvents' ) ;
1045+
1046+ client . processBeaconEvents ( room , [ ] ) ;
1047+ expect ( roomStateProcessSpy ) . not . toHaveBeenCalled ( ) ;
1048+ } ) ;
1049+
1050+ it ( 'calls room states processBeaconEvents with m.beacon events' , ( ) => {
1051+ const room = new Room ( roomId , client , userId ) ;
1052+ const roomStateProcessSpy = jest . spyOn ( room . currentState , 'processBeaconEvents' ) ;
1053+
1054+ const messageEvent = testUtils . mkMessage ( { room : roomId , user : userId , event : true } ) ;
1055+ const beaconEvent = makeBeaconEvent ( userId ) ;
1056+
1057+ client . processBeaconEvents ( room , [ messageEvent , beaconEvent ] ) ;
1058+ expect ( roomStateProcessSpy ) . toHaveBeenCalledWith ( [ beaconEvent ] ) ;
1059+ } ) ;
1060+ } ) ;
1061+ } ) ;
1062+
1063+ describe ( "setPassword" , ( ) => {
1064+ const auth = { session : 'abcdef' , type : 'foo' } ;
1065+ const newPassword = 'newpassword' ;
1066+ const callback = ( ) => { } ;
1067+
1068+ const passwordTest = ( expectedRequestContent : any , expectedCallback ?: Function ) => {
1069+ const [ callback , method , path , queryParams , requestContent ] = client . http . authedRequest . mock . calls [ 0 ] ;
1070+ if ( expectedCallback ) {
1071+ expect ( callback ) . toBe ( expectedCallback ) ;
1072+ } else {
1073+ expect ( callback ) . toBeFalsy ( ) ;
1074+ }
1075+ expect ( method ) . toBe ( 'POST' ) ;
1076+ expect ( path ) . toEqual ( '/account/password' ) ;
1077+ expect ( queryParams ) . toBeFalsy ( ) ;
1078+ expect ( requestContent ) . toEqual ( expectedRequestContent ) ;
1079+ } ;
1080+
1081+ beforeEach ( ( ) => {
1082+ client . http . authedRequest . mockClear ( ) . mockResolvedValue ( { } ) ;
1083+ } ) ;
1084+
1085+ it ( "no logout_devices specified" , async ( ) => {
1086+ await client . setPassword ( auth , newPassword ) ;
1087+ passwordTest ( { auth, new_password : newPassword } ) ;
1088+ } ) ;
1089+
1090+ it ( "no logout_devices specified + callback" , async ( ) => {
1091+ await client . setPassword ( auth , newPassword , callback ) ;
1092+ passwordTest ( { auth, new_password : newPassword } , callback ) ;
1093+ } ) ;
1094+
1095+ it ( "overload logoutDevices=true" , async ( ) => {
1096+ await client . setPassword ( auth , newPassword , true ) ;
1097+ passwordTest ( { auth, new_password : newPassword , logout_devices : true } ) ;
1098+ } ) ;
1099+
1100+ it ( "overload logoutDevices=true + callback" , async ( ) => {
1101+ await client . setPassword ( auth , newPassword , true , callback ) ;
1102+ passwordTest ( { auth, new_password : newPassword , logout_devices : true } , callback ) ;
1103+ } ) ;
1104+
1105+ it ( "overload logoutDevices=false" , async ( ) => {
1106+ await client . setPassword ( auth , newPassword , false ) ;
1107+ passwordTest ( { auth, new_password : newPassword , logout_devices : false } ) ;
1108+ } ) ;
1109+
1110+ it ( "overload logoutDevices=false + callback" , async ( ) => {
1111+ await client . setPassword ( auth , newPassword , false , callback ) ;
1112+ passwordTest ( { auth, new_password : newPassword , logout_devices : false } , callback ) ;
1113+ } ) ;
10301114 } ) ;
10311115} ) ;
0 commit comments