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

Commit

Permalink
Add tests and fix rules names
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Velten committed Jun 14, 2023
1 parent e8c1f44 commit bdd9854
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rust/src/push/base_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[
default_enabled: true,
},
PushRule {
rule_id: Cow::Borrowed("global/override/.m.is_user_mention"),
rule_id: Cow::Borrowed("global/override/.m.rule.is_user_mention"),
priority_class: 5,
conditions: Cow::Borrowed(&[Condition::Known(
KnownCondition::ExactEventPropertyContainsType(EventPropertyIsTypeCondition {
Expand All @@ -163,7 +163,7 @@ pub const BASE_APPEND_OVERRIDE_RULES: &[PushRule] = &[
default_enabled: true,
},
PushRule {
rule_id: Cow::Borrowed("global/override/.m.is_room_mention"),
rule_id: Cow::Borrowed("global/override/.m.rule.is_room_mention"),
priority_class: 5,
conditions: Cow::Borrowed(&[
Condition::Known(KnownCondition::EventPropertyIs(EventPropertyIsCondition {
Expand Down
38 changes: 38 additions & 0 deletions tests/rest/client/test_push_rule_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,41 @@ def test_actions_404_when_put_non_existent_server_rule(self) -> None:
)
self.assertEqual(channel.code, 404)
self.assertEqual(channel.json_body["errcode"], Codes.NOT_FOUND)


def test_contains_user_name(self) -> None:
"""
Tests that `contains_user_name` rule is present and have proper value in `pattern`.
"""
username = "bob"
self.register_user(username, "pass")
token = self.login(username, "pass")

channel = self.make_request(
"GET",
"/pushrules/global/content/.m.rule.contains_user_name",
access_token=token,
)

self.assertEqual(channel.code, 200)
self.assertIn("pattern", channel.json_body)
self.assertEqual(channel.json_body["pattern"], username)

def test_is_user_mention(self) -> None:
"""
Tests that `is_user_mention` rule is present and have proper value in `value`.
"""
user = self.register_user("bob", "pass")
token = self.login("bob", "pass")

channel = self.make_request(
"GET",
"/pushrules/global/override/.m.rule.is_user_mention",
access_token=token,
)

self.assertEqual(channel.code, 200)
self.assertIn("conditions", channel.json_body)
self.assertEqual(len(channel.json_body["conditions"]), 1)
self.assertIn("value", channel.json_body["conditions"][0])
self.assertEqual(channel.json_body["conditions"][0]["value"], user)

0 comments on commit bdd9854

Please sign in to comment.