tests: add support for the global account PushRules event in the event factory

This commit is contained in:
Benjamin Bouvier
2025-08-21 12:44:42 +02:00
parent 9a3ceb8be6
commit e6b1ffba99
8 changed files with 64 additions and 247 deletions
@@ -49,6 +49,7 @@ use ruma::{
UnstablePollAnswer, UnstablePollStartContentBlock, UnstablePollStartEventContent,
},
},
push_rules::PushRulesEventContent,
reaction::ReactionEventContent,
receipt::{Receipt, ReceiptEventContent, ReceiptThread, ReceiptType},
relation::{Annotation, BundledThread, InReplyTo, Replacement, Thread},
@@ -74,6 +75,7 @@ use ruma::{
sticker::StickerEventContent,
typing::TypingEventContent,
},
push::Ruleset,
room_version_rules::AuthorizationRules,
serde::Raw,
server_name,
@@ -1010,6 +1012,13 @@ impl EventFactory {
builder
}
/// Create a new `m.push_rules` global account data event.
pub fn push_rules(&self, rules: Ruleset) -> EventBuilder<PushRulesEventContent> {
let mut builder = self.event(PushRulesEventContent::new(rules));
builder.is_global = true;
builder
}
/// Set the next server timestamp.
///
/// Timestamps will continue to increase by 1 (millisecond) from that value.
@@ -151,7 +151,6 @@ impl SyncResponseBuilder {
event: GlobalAccountDataTestEvent,
) -> &mut Self {
let val = match event {
GlobalAccountDataTestEvent::PushRules => test_json::PUSH_RULES.to_owned(),
GlobalAccountDataTestEvent::Custom(json) => json,
};
@@ -149,14 +149,12 @@ impl From<PresenceTestEvent> for Raw<PresenceEvent> {
/// Test events that can be added to the global account data.
pub enum GlobalAccountDataTestEvent {
PushRules,
Custom(JsonValue),
}
impl From<GlobalAccountDataTestEvent> for JsonValue {
fn from(val: GlobalAccountDataTestEvent) -> Self {
match val {
GlobalAccountDataTestEvent::PushRules => test_json::sync_events::PUSH_RULES.to_owned(),
GlobalAccountDataTestEvent::Custom(json) => json,
}
}
+1 -1
View File
@@ -30,7 +30,7 @@ pub use sync::{
};
pub use sync_events::{
ALIAS, ALIASES, ENCRYPTION, MEMBER, MEMBER_ADDITIONAL, MEMBER_BAN, MEMBER_INVITE, MEMBER_LEAVE,
MEMBER_NAME_CHANGE, MEMBER_STRIPPED, NAME, NAME_STRIPPED, POWER_LEVELS, PRESENCE, PUSH_RULES,
MEMBER_NAME_CHANGE, MEMBER_STRIPPED, NAME, NAME_STRIPPED, POWER_LEVELS, PRESENCE,
REDACTED_INVALID, REDACTED_STATE, TAG, TOPIC, TOPIC_REDACTION,
};
@@ -3,8 +3,6 @@
use once_cell::sync::Lazy;
use serde_json::{Value as JsonValue, json};
use crate::DEFAULT_TEST_ROOM_ID;
pub static ALIAS: Lazy<JsonValue> = Lazy::new(|| {
json!({
"content": {
@@ -392,218 +390,6 @@ pub static PRESENCE: Lazy<JsonValue> = Lazy::new(|| {
})
});
pub static PUSH_RULES: Lazy<JsonValue> = Lazy::new(|| {
json!({
"content": {
"global": {
"content": [
{
"actions": [
"notify",
{
"set_tweak": "sound",
"value": "default"
},
{
"set_tweak": "highlight"
}
],
"default": true,
"enabled": true,
"pattern": "example",
"rule_id": ".m.rule.contains_user_name"
}
],
"override": [
{
"actions": [
"dont_notify"
],
"conditions": [],
"default": true,
"enabled": false,
"rule_id": ".m.rule.master"
},
{
"actions": [
"dont_notify"
],
"conditions": [
{
"key": "content.msgtype",
"kind": "event_match",
"pattern": "m.notice"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.suppress_notices"
}
],
"room": [
{
"actions": [
"notify",
{
"set_tweak": "sound",
"value": "default"
}
],
"rule_id": *DEFAULT_TEST_ROOM_ID,
"default": false,
"enabled": true
}
],
"sender": [],
"underride": [
{
"actions": [
"notify",
{
"set_tweak": "sound",
"value": "ring"
},
{
"set_tweak": "highlight",
"value": false
}
],
"conditions": [
{
"key": "type",
"kind": "event_match",
"pattern": "m.call.invite"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.call"
},
{
"actions": [
"notify",
{
"set_tweak": "sound",
"value": "default"
},
{
"set_tweak": "highlight"
}
],
"conditions": [
{
"kind": "contains_display_name"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.contains_display_name"
},
{
"actions": [
"notify",
{
"set_tweak": "sound",
"value": "default"
},
{
"set_tweak": "highlight",
"value": false
}
],
"conditions": [
{
"is": "2",
"kind": "room_member_count"
},
{
"key": "type",
"kind": "event_match",
"pattern": "m.room.message"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.room_one_to_one"
},
{
"actions": [
"notify",
{
"set_tweak": "sound",
"value": "default"
},
{
"set_tweak": "highlight",
"value": false
}
],
"conditions": [
{
"key": "type",
"kind": "event_match",
"pattern": "m.room.member"
},
{
"key": "content.membership",
"kind": "event_match",
"pattern": "invite"
},
{
"key": "state_key",
"kind": "event_match",
"pattern": "@example:localhost"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.invite_for_me"
},
{
"actions": [
"notify",
{
"set_tweak": "highlight",
"value": false
}
],
"conditions": [
{
"key": "type",
"kind": "event_match",
"pattern": "m.room.member"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.member_event"
},
{
"actions": [
"notify",
{
"set_tweak": "highlight",
"value": false
}
],
"conditions": [
{
"key": "type",
"kind": "event_match",
"pattern": "m.room.message"
}
],
"default": true,
"enabled": true,
"rule_id": ".m.rule.message"
}
]
}
},
"type": "m.push_rules"
})
});
pub static REDACTED_INVALID: Lazy<JsonValue> = Lazy::new(|| {
json!({
"content": {},