Skip to content

Commit

Permalink
add regression test for wildcard filters
Browse files Browse the repository at this point in the history
  • Loading branch information
thebalaa committed Jan 4, 2024
1 parent 00de6da commit fbab81e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
26 changes: 26 additions & 0 deletions tests/rest/client/test_rooms.py
Expand Up @@ -2154,6 +2154,32 @@ def test_room_messages_purge(self) -> None:
chunk = channel.json_body["chunk"]
self.assertEqual(len(chunk), 0, [event["content"] for event in chunk])

def test_room_message_filter_wildcard(self) -> None:
store = self.hs.get_datastores().main
# Send a first message in the room, which will be removed by the purge.
self.helper.send(self.room_id, "message 1", type="f.message.1")
self.helper.send(self.room_id, "message 1", type="f.message.2")

first_event_id = self.helper.send(self.room_id, "message 1")["event_id"]
first_token = self.get_success(
store.get_topological_token_for_event(first_event_id)
)
first_token_str = self.get_success(first_token.to_string(store))

channel = self.make_request(
"GET",
"/rooms/%s/messages?access_token=x&from=%s&dir=b&filter=%s"
% (
self.room_id,
first_token_str,
json.dumps({"types": ['f.message.*']}),
),
)
self.assertEqual(channel.code, HTTPStatus.OK, channel.json_body)

chunk = channel.json_body["chunk"]
self.assertEqual(len(chunk), 2, [event["content"] for event in chunk])


class RoomSearchTestCase(unittest.HomeserverTestCase):
servlets = [
Expand Down
3 changes: 2 additions & 1 deletion tests/rest/client/utils.py
Expand Up @@ -364,6 +364,7 @@ def send(
tok: Optional[str] = None,
expect_code: int = HTTPStatus.OK,
custom_headers: Optional[Iterable[Tuple[AnyStr, AnyStr]]] = None,
type: str = "m.room.message",
) -> JsonDict:
if body is None:
body = "body_text_here"
Expand All @@ -372,7 +373,7 @@ def send(

return self.send_event(
room_id,
"m.room.message",
type,
content,
txn_id,
tok,
Expand Down

0 comments on commit fbab81e

Please sign in to comment.