@@ -3418,6 +3418,61 @@ async fn test_expire_past_members_after_60_days() -> Result<()> {
3418
3418
Ok ( ( ) )
3419
3419
}
3420
3420
3421
+ /// Test that past members are ordered by the timestamp of their removal.
3422
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
3423
+ async fn test_past_members_order ( ) -> Result < ( ) > {
3424
+ let t = & TestContext :: new_alice ( ) . await ;
3425
+
3426
+ let bob_contact_id =
Contact :: create ( t
, "Bob" , "[email protected] " ) . await ?
;
3427
+ let charlie_contact_id =
Contact :: create ( t
, "Charlie" , "[email protected] " ) . await ?
;
3428
+ let fiona_contact_id =
Contact :: create ( t
, "Fiona" , "[email protected] " ) . await ?
;
3429
+
3430
+ let chat_id = create_group_chat ( t, ProtectionStatus :: Unprotected , "Group chat" ) . await ?;
3431
+ add_contact_to_chat ( t, chat_id, bob_contact_id) . await ?;
3432
+ add_contact_to_chat ( t, chat_id, charlie_contact_id) . await ?;
3433
+ add_contact_to_chat ( t, chat_id, fiona_contact_id) . await ?;
3434
+ t. send_text ( chat_id, "Hi! I created a group." ) . await ;
3435
+
3436
+ assert_eq ! ( get_past_chat_contacts( t, chat_id) . await ?. len( ) , 0 ) ;
3437
+
3438
+ remove_contact_from_chat ( t, chat_id, charlie_contact_id) . await ?;
3439
+
3440
+ let past_contacts = get_past_chat_contacts ( t, chat_id) . await ?;
3441
+ assert_eq ! ( past_contacts. len( ) , 1 ) ;
3442
+ assert_eq ! ( past_contacts[ 0 ] , charlie_contact_id) ;
3443
+
3444
+ SystemTime :: shift ( Duration :: from_secs ( 5 ) ) ;
3445
+ remove_contact_from_chat ( t, chat_id, bob_contact_id) . await ?;
3446
+
3447
+ let past_contacts = get_past_chat_contacts ( t, chat_id) . await ?;
3448
+ assert_eq ! ( past_contacts. len( ) , 2 ) ;
3449
+ assert_eq ! ( past_contacts[ 0 ] , bob_contact_id) ;
3450
+ assert_eq ! ( past_contacts[ 1 ] , charlie_contact_id) ;
3451
+
3452
+ SystemTime :: shift ( Duration :: from_secs ( 5 ) ) ;
3453
+ remove_contact_from_chat ( t, chat_id, fiona_contact_id) . await ?;
3454
+
3455
+ let past_contacts = get_past_chat_contacts ( t, chat_id) . await ?;
3456
+ assert_eq ! ( past_contacts. len( ) , 3 ) ;
3457
+ assert_eq ! ( past_contacts[ 0 ] , fiona_contact_id) ;
3458
+ assert_eq ! ( past_contacts[ 1 ] , bob_contact_id) ;
3459
+ assert_eq ! ( past_contacts[ 2 ] , charlie_contact_id) ;
3460
+
3461
+ // Adding and removing Bob
3462
+ // moves him to the top of past member list.
3463
+ SystemTime :: shift ( Duration :: from_secs ( 5 ) ) ;
3464
+ add_contact_to_chat ( t, chat_id, bob_contact_id) . await ?;
3465
+ remove_contact_from_chat ( t, chat_id, bob_contact_id) . await ?;
3466
+
3467
+ let past_contacts = get_past_chat_contacts ( t, chat_id) . await ?;
3468
+ assert_eq ! ( past_contacts. len( ) , 3 ) ;
3469
+ assert_eq ! ( past_contacts[ 0 ] , bob_contact_id) ;
3470
+ assert_eq ! ( past_contacts[ 1 ] , fiona_contact_id) ;
3471
+ assert_eq ! ( past_contacts[ 2 ] , charlie_contact_id) ;
3472
+
3473
+ Ok ( ( ) )
3474
+ }
3475
+
3421
3476
/// Test the case when Alice restores a backup older than 60 days
3422
3477
/// with outdated member list.
3423
3478
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
0 commit comments