diff options
author | H. Shay <hillerys@element.io> | 2023-02-21 14:27:38 -0800 |
---|---|---|
committer | H. Shay <hillerys@element.io> | 2023-02-21 14:27:38 -0800 |
commit | b564f29fe25d70d5e1b3252f2df6071a7c429fc8 (patch) | |
tree | fe8999c5a9a18299ed7d70b1ae3d5b48319f256a | |
parent | update tests to reflect new function signature (diff) | |
download | synapse-b564f29fe25d70d5e1b3252f2df6071a7c429fc8.tar.xz |
add a new test to check sending an additional event into room
-rw-r--r-- | tests/rest/client/test_third_party_rules.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/rest/client/test_third_party_rules.py b/tests/rest/client/test_third_party_rules.py index 3325d43a2f..3277a116e8 100644 --- a/tests/rest/client/test_third_party_rules.py +++ b/tests/rest/client/test_third_party_rules.py @@ -273,6 +273,46 @@ class ThirdPartyRulesTestCase(unittest.FederatingHomeserverTestCase): ev = channel.json_body self.assertEqual(ev["content"]["x"], "y") + def test_add_event(self) -> None: + # needs checking of combo of return conditions, ie replace event and send event + async def check( + ev: EventBase, state: StateMap[EventBase] + ) -> Tuple[bool, Optional[JsonDict], Optional[dict]]: + event_dict = { + "type": "m.room.test", + "room_id": self.room_id, + "sender": self.user_id, + "content": { + "creator": "test_user", + "body": "message", + "msgtype": "message", + }, + } + if ev.type == "message": + return True, None, event_dict + else: + return True, None, None + + self.hs.get_third_party_event_rules()._check_event_allowed_v2_callbacks = [ + check + ] + + channel = self.make_request( + "PUT", + "/_matrix/client/r0/rooms/%s/send/message/1" % self.room_id, + {"x": "x"}, + access_token=self.tok, + ) + self.assertEqual(channel.code, 200, channel.result) + + events = self.get_success( + self.hs.get_datastores().main.get_forward_extremities_for_room(self.room_id) + ) + event = events[1] + + e = self.get_success(self.hs.get_datastores().main.get_event(event["event_id"])) + self.assertEqual("m.room.test", e.type) + def test_message_edit(self) -> None: """Ensure that the module doesn't cause issues with edited messages.""" # first patch the event checker so that it will modify the event |