summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMatt C <96466754+buffless-matt@users.noreply.github.com>2022-08-04 19:34:05 +1000
committerGitHub <noreply@github.com>2022-08-04 09:34:05 +0000
commita91078200dbf41f6929762381e02cdeb21ff07d1 (patch)
treeeb3a4f84007c19b6bd8f9633d241de2ec82299fa /tests
parentFix rooms not being properly excluded from incremental sync (#13408) (diff)
downloadsynapse-a91078200dbf41f6929762381e02cdeb21ff07d1.tar.xz
Add module API method to create a room (#13429)
Co-authored-by: MattC <buffless-matt@users.noreply.github.com>
Co-authored-by: Brendan Abolivier <babolivier@matrix.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/module_api/test_api.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/module_api/test_api.py b/tests/module_api/test_api.py
index 8e05590230..9bf95472e1 100644
--- a/tests/module_api/test_api.py
+++ b/tests/module_api/test_api.py
@@ -654,6 +654,57 @@ class ModuleApiTestCase(HomeserverTestCase):
 
         self.assertEqual(room_id, reference_room_id)
 
+    def test_create_room(self) -> None:
+        """Test that modules can create a room."""
+        # First test user validation (i.e. user is local).
+        self.get_failure(
+            self.module_api.create_room(
+                user_id=f"@user:{self.module_api.server_name}abc",
+                config={},
+                ratelimit=False,
+            ),
+            RuntimeError,
+        )
+
+        # Now do the happy path.
+        user_id = self.register_user("user", "password")
+        access_token = self.login(user_id, "password")
+
+        room_id, room_alias = self.get_success(
+            self.module_api.create_room(
+                user_id=user_id, config={"room_alias_name": "foo-bar"}, ratelimit=False
+            )
+        )
+
+        # Check room creator.
+        channel = self.make_request(
+            "GET",
+            f"/_matrix/client/v3/rooms/{room_id}/state/m.room.create",
+            access_token=access_token,
+        )
+        self.assertEqual(channel.code, 200, channel.result)
+        self.assertEqual(channel.json_body["creator"], user_id)
+
+        # Check room alias.
+        self.assertEquals(room_alias, f"#foo-bar:{self.module_api.server_name}")
+
+        # Let's try a room with no alias.
+        room_id, room_alias = self.get_success(
+            self.module_api.create_room(user_id=user_id, config={}, ratelimit=False)
+        )
+
+        # Check room creator.
+        channel = self.make_request(
+            "GET",
+            f"/_matrix/client/v3/rooms/{room_id}/state/m.room.create",
+            access_token=access_token,
+        )
+        self.assertEqual(channel.code, 200, channel.result)
+        self.assertEqual(channel.json_body["creator"], user_id)
+
+        # Check room alias.
+        self.assertIsNone(room_alias)
+
 
 class ModuleApiWorkerTestCase(BaseMultiWorkerStreamTestCase):
     """For testing ModuleApi functionality in a multi-worker setup"""