mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-14 11:57:44 +00:00
Add test to make sure only joined spaces are taken into account
This commit is contained in:
parent
212ea3568a
commit
813cda92df
1 changed files with 74 additions and 4 deletions
|
@ -642,7 +642,7 @@ class FilterRoomsTestCase(HomeserverTestCase):
|
|||
|
||||
def test_filter_dm_rooms(self) -> None:
|
||||
"""
|
||||
Test filter for DM rooms
|
||||
Test `filter.is_dm` for DM rooms
|
||||
"""
|
||||
user1_id = self.register_user("user1", "pass")
|
||||
user1_tok = self.login(user1_id, "pass")
|
||||
|
@ -683,7 +683,7 @@ class FilterRoomsTestCase(HomeserverTestCase):
|
|||
|
||||
def test_filter_non_dm_rooms(self) -> None:
|
||||
"""
|
||||
Test filter for non-DM rooms
|
||||
Test `filter.is_dm` for non-DM rooms
|
||||
"""
|
||||
user1_id = self.register_user("user1", "pass")
|
||||
user1_tok = self.login(user1_id, "pass")
|
||||
|
@ -724,7 +724,7 @@ class FilterRoomsTestCase(HomeserverTestCase):
|
|||
|
||||
def test_filter_space_rooms(self) -> None:
|
||||
"""
|
||||
Test filter for rooms in spaces
|
||||
Test `filter.spaces` for rooms in spaces
|
||||
"""
|
||||
user1_id = self.register_user("user1", "pass")
|
||||
user1_tok = self.login(user1_id, "pass")
|
||||
|
@ -764,7 +764,7 @@ class FilterRoomsTestCase(HomeserverTestCase):
|
|||
is_public=False,
|
||||
tok=user1_tok,
|
||||
)
|
||||
# Add to space_a and space b
|
||||
# Add to space_a and space_b
|
||||
self._add_space_child(space_a, room_id2, user1_tok)
|
||||
self._add_space_child(space_c, room_id2, user1_tok)
|
||||
|
||||
|
@ -824,3 +824,73 @@ class FilterRoomsTestCase(HomeserverTestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(filtered_room_ids, {room_id1, room_id2, room_id3})
|
||||
|
||||
def test_filter_only_joined_spaces(self) -> None:
|
||||
"""
|
||||
Test `filter.spaces` to make sure the filter only takes into account spaces we
|
||||
are joined to.
|
||||
"""
|
||||
user1_id = self.register_user("user1", "pass")
|
||||
user1_tok = self.login(user1_id, "pass")
|
||||
user2_id = self.register_user("user2", "pass")
|
||||
user2_tok = self.login(user2_id, "pass")
|
||||
|
||||
# space_a created by user1
|
||||
space_a = self.helper.create_room_as(
|
||||
user1_id,
|
||||
tok=user1_tok,
|
||||
extra_content={
|
||||
"creation_content": {EventContentFields.ROOM_TYPE: RoomTypes.SPACE}
|
||||
},
|
||||
)
|
||||
# space_b created by user2
|
||||
space_b = self.helper.create_room_as(
|
||||
user2_id,
|
||||
tok=user2_tok,
|
||||
extra_content={
|
||||
"creation_content": {EventContentFields.ROOM_TYPE: RoomTypes.SPACE}
|
||||
},
|
||||
)
|
||||
|
||||
room_id1 = self.helper.create_room_as(
|
||||
user1_id,
|
||||
is_public=False,
|
||||
tok=user1_tok,
|
||||
)
|
||||
# Add to space_a
|
||||
self._add_space_child(space_a, room_id1, user1_tok)
|
||||
|
||||
room_id2 = self.helper.create_room_as(
|
||||
user1_id,
|
||||
is_public=False,
|
||||
tok=user1_tok,
|
||||
)
|
||||
# Add to space_b
|
||||
self._add_space_child(space_b, room_id2, user2_tok)
|
||||
|
||||
# TODO: Better way to avoid the circular import? (see
|
||||
# https://github.com/element-hq/synapse/pull/17187#discussion_r1619492779)
|
||||
from synapse.handlers.sliding_sync import SlidingSyncConfig
|
||||
|
||||
filters = SlidingSyncConfig.SlidingSyncList.Filters(
|
||||
spaces=[
|
||||
space_a,
|
||||
space_b,
|
||||
],
|
||||
)
|
||||
|
||||
# Try filtering the rooms
|
||||
filtered_room_ids = self.get_success(
|
||||
self.sliding_sync_handler.filter_rooms(
|
||||
UserID.from_string(user1_id),
|
||||
{
|
||||
# a
|
||||
room_id1,
|
||||
# b (but user1 isn't in space_b)
|
||||
room_id2,
|
||||
},
|
||||
filters,
|
||||
)
|
||||
)
|
||||
|
||||
self.assertEqual(filtered_room_ids, {room_id1})
|
||||
|
|
Loading…
Reference in a new issue