@@ -2213,14 +2213,17 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
22132213 )
22142214
22152215 def make_public_rooms_request (
2216- self , room_types : Union [List [Union [str , None ]], None ]
2216+ self ,
2217+ room_types : Optional [List [Union [str , None ]]],
2218+ instance_id : Optional [str ] = None ,
22172219 ) -> Tuple [List [Dict [str , Any ]], int ]:
2218- channel = self .make_request (
2219- "POST" ,
2220- self .url ,
2221- {"filter" : {PublicRoomsFilterFields .ROOM_TYPES : room_types }},
2222- self .token ,
2223- )
2220+ body : JsonDict = {"filter" : {PublicRoomsFilterFields .ROOM_TYPES : room_types }}
2221+ if instance_id :
2222+ body ["third_party_instance_id" ] = "test|test"
2223+
2224+ channel = self .make_request ("POST" , self .url , body , self .token )
2225+ self .assertEqual (channel .code , 200 )
2226+
22242227 chunk = channel .json_body ["chunk" ]
22252228 count = channel .json_body ["total_room_count_estimate" ]
22262229
@@ -2230,31 +2233,49 @@ def make_public_rooms_request(
22302233
22312234 def test_returns_both_rooms_and_spaces_if_no_filter (self ) -> None :
22322235 chunk , count = self .make_public_rooms_request (None )
2233-
22342236 self .assertEqual (count , 2 )
22352237
2238+ # Also check if there's no filter property at all in the body.
2239+ channel = self .make_request ("POST" , self .url , {}, self .token )
2240+ self .assertEqual (channel .code , 200 )
2241+ self .assertEqual (len (channel .json_body ["chunk" ]), 2 )
2242+ self .assertEqual (channel .json_body ["total_room_count_estimate" ], 2 )
2243+
2244+ chunk , count = self .make_public_rooms_request (None , "test|test" )
2245+ self .assertEqual (count , 0 )
2246+
22362247 def test_returns_only_rooms_based_on_filter (self ) -> None :
22372248 chunk , count = self .make_public_rooms_request ([None ])
22382249
22392250 self .assertEqual (count , 1 )
22402251 self .assertEqual (chunk [0 ].get ("room_type" , None ), None )
22412252
2253+ chunk , count = self .make_public_rooms_request ([None ], "test|test" )
2254+ self .assertEqual (count , 0 )
2255+
22422256 def test_returns_only_space_based_on_filter (self ) -> None :
22432257 chunk , count = self .make_public_rooms_request (["m.space" ])
22442258
22452259 self .assertEqual (count , 1 )
22462260 self .assertEqual (chunk [0 ].get ("room_type" , None ), "m.space" )
22472261
2262+ chunk , count = self .make_public_rooms_request (["m.space" ], "test|test" )
2263+ self .assertEqual (count , 0 )
2264+
22482265 def test_returns_both_rooms_and_space_based_on_filter (self ) -> None :
22492266 chunk , count = self .make_public_rooms_request (["m.space" , None ])
2250-
22512267 self .assertEqual (count , 2 )
22522268
2269+ chunk , count = self .make_public_rooms_request (["m.space" , None ], "test|test" )
2270+ self .assertEqual (count , 0 )
2271+
22532272 def test_returns_both_rooms_and_spaces_if_array_is_empty (self ) -> None :
22542273 chunk , count = self .make_public_rooms_request ([])
2255-
22562274 self .assertEqual (count , 2 )
22572275
2276+ chunk , count = self .make_public_rooms_request ([], "test|test" )
2277+ self .assertEqual (count , 0 )
2278+
22582279
22592280class PublicRoomsTestRemoteSearchFallbackTestCase (unittest .HomeserverTestCase ):
22602281 """Test that we correctly fallback to local filtering if a remote server
0 commit comments