@@ -2,7 +2,7 @@ use std::time::Duration;
2
2
3
3
use assert_matches2:: assert_matches;
4
4
use matrix_sdk:: config:: SyncSettings ;
5
- use matrix_sdk_base:: RoomState ;
5
+ use matrix_sdk_base:: { RoomInfoNotableUpdateReasons , RoomState } ;
6
6
use matrix_sdk_test:: {
7
7
async_test, test_json, GlobalAccountDataTestEvent , LeftRoomBuilder , SyncResponseBuilder ,
8
8
DEFAULT_TEST_ROOM_ID ,
@@ -77,6 +77,67 @@ async fn test_forget_non_direct_room() {
77
77
}
78
78
}
79
79
80
+ #[ async_test]
81
+ async fn test_forget_banned_room ( ) {
82
+ let ( client, server) = logged_in_client_with_server ( ) . await ;
83
+ let user_id = client. user_id ( ) . unwrap ( ) ;
84
+
85
+ let event_cache = client. event_cache ( ) ;
86
+ event_cache. subscribe ( ) . unwrap ( ) ;
87
+ event_cache. enable_storage ( ) . unwrap ( ) ;
88
+
89
+ Mock :: given ( method ( "POST" ) )
90
+ . and ( path_regex ( r"^/_matrix/client/r0/rooms/.*/forget$" ) )
91
+ . and ( header ( "authorization" , "Bearer 1234" ) )
92
+ . respond_with ( ResponseTemplate :: new ( 200 ) . set_body_json ( & * test_json:: EMPTY ) )
93
+ . named ( "forget" )
94
+ . expect ( 1 )
95
+ . mount ( & server)
96
+ . await ;
97
+
98
+ Mock :: given ( method ( "PUT" ) )
99
+ . and ( path ( format ! ( "/_matrix/client/r0/user/{user_id}/account_data/m.direct" ) ) )
100
+ . and ( header ( "authorization" , "Bearer 1234" ) )
101
+ . respond_with ( ResponseTemplate :: new ( 200 ) . set_body_json ( & * test_json:: EMPTY ) )
102
+ . named ( "set_mdirect" )
103
+ . expect ( 0 )
104
+ . mount ( & server)
105
+ . await ;
106
+
107
+ mock_sync ( & server, & * test_json:: LEAVE_SYNC , None ) . await ;
108
+
109
+ let sync_settings = SyncSettings :: new ( ) . timeout ( Duration :: from_millis ( 3000 ) ) ;
110
+ let _response = client. sync_once ( sync_settings) . await . unwrap ( ) ;
111
+
112
+ // Let the event cache process updates.
113
+ yield_now ( ) . await ;
114
+
115
+ {
116
+ // There is some data in the cache store.
117
+ let event_cache_store = client. event_cache_store ( ) . lock ( ) . await . unwrap ( ) ;
118
+ let room_data = event_cache_store. reload_linked_chunk ( & DEFAULT_TEST_ROOM_ID ) . await . unwrap ( ) ;
119
+ assert ! ( !room_data. is_empty( ) ) ;
120
+ }
121
+
122
+ // Make the room banned
123
+ let room = client. get_room ( & DEFAULT_TEST_ROOM_ID ) . unwrap ( ) ;
124
+ let mut room_info = room. clone_info ( ) ;
125
+ room_info. mark_as_banned ( ) ;
126
+ room. set_room_info ( room_info, RoomInfoNotableUpdateReasons :: MEMBERSHIP ) ;
127
+ assert_eq ! ( room. state( ) , RoomState :: Banned ) ;
128
+
129
+ room. forget ( ) . await . unwrap ( ) ;
130
+
131
+ assert ! ( client. get_room( & DEFAULT_TEST_ROOM_ID ) . is_none( ) ) ;
132
+
133
+ {
134
+ // Data in the event cache store has been removed.
135
+ let event_cache_store = client. event_cache_store ( ) . lock ( ) . await . unwrap ( ) ;
136
+ let room_data = event_cache_store. reload_linked_chunk ( & DEFAULT_TEST_ROOM_ID ) . await . unwrap ( ) ;
137
+ assert ! ( room_data. is_empty( ) ) ;
138
+ }
139
+ }
140
+
80
141
#[ async_test]
81
142
async fn test_forget_direct_room ( ) {
82
143
let ( client, server) = logged_in_client_with_server ( ) . await ;
0 commit comments