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

Add a ModuleApi method to update a user's membership in a room #11147

Merged
merged 16 commits into from
Oct 28, 2021
Merged
Prev Previous commit
Next Next commit
Test invites, and users with no profile
  • Loading branch information
babolivier committed Oct 28, 2021
commit 555d59581223dd3ef74878c871d68bf2e93da7fe
42 changes: 42 additions & 0 deletions tests/module_api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,28 @@ def test_update_membership(self):

self.assertEqual(channel.code, 200, channel.result)

# Make Peter invite Lesley to the room.
self.get_success(
defer.ensureDeferred(
self.module_api.update_room_membership(peter, lesley, room_id, "invite")
)
)

res = self.helper.get_state(
room_id=room_id,
event_type="m.room.member",
state_key=lesley,
tok=tok,
)

# Check the membership is correct.
self.assertEqual(res["membership"], "invite")

# Also check that the profile was correctly filled out, and that it's not
# Peter's.
self.assertEqual(res["displayname"], "Lesley May")
self.assertEqual(res["avatar_url"], "some_url")

# Make lesley join it.
self.get_success(
defer.ensureDeferred(
Expand Down Expand Up @@ -467,6 +489,26 @@ def test_update_membership(self):

self.get_failure(d, RuntimeError)

babolivier marked this conversation as resolved.
Show resolved Hide resolved
# Check that inviting a user that doesn't have a profile falls back to using a
# default (localpart + no avatar) profile.
simone = "@simone:" + self.hs.config.server.server_name
self.get_success(
defer.ensureDeferred(
self.module_api.update_room_membership(peter, simone, room_id, "invite")
)
)

res = self.helper.get_state(
room_id=room_id,
event_type="m.room.member",
state_key=simone,
tok=tok,
)

self.assertEqual(res["membership"], "invite")
self.assertEqual(res["displayname"], "simone")
self.assertIsNone(res["avatar_url"])


class ModuleApiWorkerTestCase(BaseMultiWorkerStreamTestCase):
"""For testing ModuleApi functionality in a multi-worker setup"""
Expand Down