@@ -33,6 +33,7 @@ import {
33
33
IRelationsRequestOpts ,
34
34
IStateEventWithRoomId ,
35
35
JoinRule ,
36
+ MatrixClient ,
36
37
MatrixEvent ,
37
38
MatrixEventEvent ,
38
39
PendingEventOrdering ,
@@ -3225,4 +3226,52 @@ describe("Room", function () {
3225
3226
expect ( room . getBlacklistUnverifiedDevices ( ) ) . toBe ( false ) ;
3226
3227
} ) ;
3227
3228
} ) ;
3229
+
3230
+ describe ( "findPredecessorRoomId" , ( ) => {
3231
+ function roomCreateEvent ( newRoomId : string , predecessorRoomId : string | null ) : MatrixEvent {
3232
+ const content : {
3233
+ creator : string ;
3234
+ [ "m.federate" ] : boolean ;
3235
+ room_version : string ;
3236
+ predecessor : { event_id : string ; room_id : string } | undefined ;
3237
+ } = {
3238
+ "creator" : "@daryl:alexandria.example.com" ,
3239
+ "predecessor" : undefined ,
3240
+ "m.federate" : true ,
3241
+ "room_version" : "9" ,
3242
+ } ;
3243
+ if ( predecessorRoomId ) {
3244
+ content . predecessor = {
3245
+ event_id : "spec_is_not_clear_what_id_this_is" ,
3246
+ room_id : predecessorRoomId ,
3247
+ } ;
3248
+ }
3249
+ return new MatrixEvent ( {
3250
+ content,
3251
+ event_id : `create_event_id_pred_${ predecessorRoomId } ` ,
3252
+ origin_server_ts : 1432735824653 ,
3253
+ room_id : newRoomId ,
3254
+ sender : "@daryl:alexandria.example.com" ,
3255
+ state_key : "" ,
3256
+ type : "m.room.create" ,
3257
+ } ) ;
3258
+ }
3259
+
3260
+ it ( "Returns null if there is no create event" , ( ) => {
3261
+ const room = new Room ( "roomid" , null as unknown as MatrixClient , "@u:example.com" ) ;
3262
+ expect ( room . findPredecessorRoomId ( ) ) . toBeNull ( ) ;
3263
+ } ) ;
3264
+
3265
+ it ( "Returns null if the create event has no predecessor" , ( ) => {
3266
+ const room = new Room ( "roomid" , null as unknown as MatrixClient , "@u:example.com" ) ;
3267
+ room . addLiveEvents ( [ roomCreateEvent ( "roomid" , null ) ] ) ;
3268
+ expect ( room . findPredecessorRoomId ( ) ) . toBeNull ( ) ;
3269
+ } ) ;
3270
+
3271
+ it ( "Returns the predecessor ID if one is provided via create event" , ( ) => {
3272
+ const room = new Room ( "roomid" , null as unknown as MatrixClient , "@u:example.com" ) ;
3273
+ room . addLiveEvents ( [ roomCreateEvent ( "roomid" , "replacedroomid" ) ] ) ;
3274
+ expect ( room . findPredecessorRoomId ( ) ) . toBe ( "replacedroomid" ) ;
3275
+ } ) ;
3276
+ } ) ;
3228
3277
} ) ;
0 commit comments