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

Commit 96df312

Browse files
Add a unit test for copying over arbitrary room types when upgrading a room (#12792)
1 parent 177b884 commit 96df312

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

changelog.d/12792.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement [MSC3818: Copy room type on upgrade](https://github.com/matrix-org/matrix-spec-proposals/pull/3818).

synapse/handlers/room.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ async def clone_existing_room(
427427
requester: the user requesting the upgrade
428428
old_room_id : the id of the room to be replaced
429429
new_room_id: the id to give the new room (should already have been
430-
created with _gemerate_room_id())
430+
created with _generate_room_id())
431431
new_room_version: the new room version to use
432432
tombstone_event_id: the ID of the tombstone event in the old room.
433433
"""

tests/rest/client/test_upgrade_room.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_not_in_room(self) -> None:
7676
"""
7777
Upgrading a room should work fine.
7878
"""
79-
# THe user isn't in the room.
79+
# The user isn't in the room.
8080
roomless = self.register_user("roomless", "pass")
8181
roomless_token = self.login(roomless, "pass")
8282

@@ -263,3 +263,33 @@ def test_space(self) -> None:
263263
self.assertIn((EventTypes.SpaceChild, self.room_id), state_ids)
264264
# The child that was removed should not be copied over.
265265
self.assertNotIn((EventTypes.SpaceChild, old_room_id), state_ids)
266+
267+
def test_custom_room_type(self) -> None:
268+
"""Test upgrading a room that has a custom room type set."""
269+
test_room_type = "com.example.my_custom_room_type"
270+
271+
# Create a room with a custom room type.
272+
room_id = self.helper.create_room_as(
273+
self.creator,
274+
tok=self.creator_token,
275+
extra_content={
276+
"creation_content": {EventContentFields.ROOM_TYPE: test_room_type}
277+
},
278+
)
279+
280+
# Upgrade the room!
281+
channel = self._upgrade_room(room_id=room_id)
282+
self.assertEqual(200, channel.code, channel.result)
283+
self.assertIn("replacement_room", channel.json_body)
284+
285+
new_room_id = channel.json_body["replacement_room"]
286+
287+
state_ids = self.get_success(self.store.get_current_state_ids(new_room_id))
288+
289+
# Ensure the new room is the same type as the old room.
290+
create_event = self.get_success(
291+
self.store.get_event(state_ids[(EventTypes.Create, "")])
292+
)
293+
self.assertEqual(
294+
create_event.content.get(EventContentFields.ROOM_TYPE), test_room_type
295+
)

0 commit comments

Comments
 (0)