Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add a unit test for copying over arbitrary room types when upgrading a room #12792

Merged
merged 4 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12792.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement [MSC3818: Copy room type on upgrade](https://github.com/matrix-org/matrix-spec-proposals/pull/3818).
2 changes: 1 addition & 1 deletion synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ async def clone_existing_room(
requester: the user requesting the upgrade
old_room_id : the id of the room to be replaced
new_room_id: the id to give the new room (should already have been
created with _gemerate_room_id())
created with _generate_room_id())
new_room_version: the new room version to use
tombstone_event_id: the ID of the tombstone event in the old room.
"""
Expand Down
32 changes: 31 additions & 1 deletion tests/rest/client/test_upgrade_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_not_in_room(self) -> None:
"""
Upgrading a room should work fine.
"""
# THe user isn't in the room.
# The user isn't in the room.
roomless = self.register_user("roomless", "pass")
roomless_token = self.login(roomless, "pass")

Expand Down Expand Up @@ -263,3 +263,33 @@ def test_space(self) -> None:
self.assertIn((EventTypes.SpaceChild, self.room_id), state_ids)
# The child that was removed should not be copied over.
self.assertNotIn((EventTypes.SpaceChild, old_room_id), state_ids)

def test_custom_room_type(self) -> None:
"""Test upgrading a room that has a custom room type set."""
test_room_type = "com.example.my_custom_room_type"

# Create a room with a custom room type.
room_id = self.helper.create_room_as(
self.creator,
tok=self.creator_token,
extra_content={
"creation_content": {EventContentFields.ROOM_TYPE: test_room_type}
},
)

# Upgrade the room!
channel = self._upgrade_room(room_id=room_id)
self.assertEqual(200, channel.code, channel.result)
self.assertIn("replacement_room", channel.json_body)

new_room_id = channel.json_body["replacement_room"]

state_ids = self.get_success(self.store.get_current_state_ids(new_room_id))

# Ensure the new room is the same type as the old room.
create_event = self.get_success(
self.store.get_event(state_ids[(EventTypes.Create, "")])
)
self.assertEqual(
create_event.content.get(EventContentFields.ROOM_TYPE), test_room_type
)