matrix_sdk_test/sync_builder/
test_event.rs

1use ruma::{
2    events::{
3        presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent,
4        AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncStateEvent,
5    },
6    serde::Raw,
7};
8use serde_json::{from_value as from_json_value, Value as JsonValue};
9
10use crate::test_json;
11
12/// Test events that can be added to the state.
13pub enum StateTestEvent {
14    Alias,
15    Aliases,
16    Create,
17    Encryption,
18    HistoryVisibility,
19    JoinRules,
20    Member,
21    MemberAdditional,
22    MemberBan,
23    MemberInvite,
24    MemberLeave,
25    MemberNameChange,
26    PowerLevels,
27    RedactedInvalid,
28    RedactedState,
29    RoomAvatar,
30    RoomName,
31    RoomPinnedEvents,
32    RoomTopic,
33    Custom(JsonValue),
34}
35
36impl StateTestEvent {
37    /// Get the JSON representation of this test event.
38    pub fn into_json_value(self) -> JsonValue {
39        match self {
40            Self::Alias => test_json::sync_events::ALIAS.to_owned(),
41            Self::Aliases => test_json::sync_events::ALIASES.to_owned(),
42            Self::Create => test_json::sync_events::CREATE.to_owned(),
43            Self::Encryption => test_json::sync_events::ENCRYPTION.to_owned(),
44            Self::HistoryVisibility => test_json::sync_events::HISTORY_VISIBILITY.to_owned(),
45            Self::JoinRules => test_json::sync_events::JOIN_RULES.to_owned(),
46            Self::Member => test_json::sync_events::MEMBER.to_owned(),
47            Self::MemberAdditional => test_json::sync_events::MEMBER_ADDITIONAL.to_owned(),
48            Self::MemberBan => test_json::sync_events::MEMBER_BAN.to_owned(),
49            Self::MemberInvite => test_json::sync_events::MEMBER_INVITE.to_owned(),
50            Self::MemberLeave => test_json::sync_events::MEMBER_LEAVE.to_owned(),
51            Self::MemberNameChange => test_json::sync_events::MEMBER_NAME_CHANGE.to_owned(),
52            Self::PowerLevels => test_json::sync_events::POWER_LEVELS.to_owned(),
53            Self::RedactedInvalid => test_json::sync_events::REDACTED_INVALID.to_owned(),
54            Self::RedactedState => test_json::sync_events::REDACTED_STATE.to_owned(),
55            Self::RoomAvatar => test_json::sync_events::ROOM_AVATAR.to_owned(),
56            Self::RoomName => test_json::sync_events::NAME.to_owned(),
57            Self::RoomPinnedEvents => test_json::sync_events::PINNED_EVENTS.to_owned(),
58            Self::RoomTopic => test_json::sync_events::TOPIC.to_owned(),
59            Self::Custom(json) => json,
60        }
61    }
62
63    /// Get the typed JSON representation of this test event.
64    pub fn into_raw_event(self) -> Raw<AnySyncStateEvent> {
65        from_json_value(self.into_json_value()).unwrap()
66    }
67}
68
69/// Test events that can be added to the stripped state.
70pub enum StrippedStateTestEvent {
71    Member,
72    RoomName,
73    Custom(JsonValue),
74}
75
76impl StrippedStateTestEvent {
77    /// Get the JSON representation of this test event.
78    pub fn into_json_value(self) -> JsonValue {
79        match self {
80            Self::Member => test_json::sync_events::MEMBER_STRIPPED.to_owned(),
81            Self::RoomName => test_json::sync_events::NAME_STRIPPED.to_owned(),
82            Self::Custom(json) => json,
83        }
84    }
85
86    /// Get the typed JSON representation of this test event.
87    pub fn into_raw_event(self) -> Raw<AnyStrippedStateEvent> {
88        from_json_value(self.into_json_value()).unwrap()
89    }
90}
91
92/// Test events that can be added to the room account data.
93pub enum RoomAccountDataTestEvent {
94    FullyRead,
95    Tags,
96    Custom(JsonValue),
97}
98
99impl RoomAccountDataTestEvent {
100    /// Get the JSON representation of this test event.
101    pub fn into_json_value(self) -> JsonValue {
102        match self {
103            Self::FullyRead => test_json::sync_events::FULLY_READ.to_owned(),
104            Self::Tags => test_json::sync_events::TAG.to_owned(),
105            Self::Custom(json) => json,
106        }
107    }
108
109    /// Get the typed JSON representation of this test event.
110    pub fn into_raw_event(self) -> Raw<AnyRoomAccountDataEvent> {
111        from_json_value(self.into_json_value()).unwrap()
112    }
113}
114
115/// Test events that can be added to the ephemeral events.
116pub enum EphemeralTestEvent {
117    ReadReceipt,
118    ReadReceiptOther,
119    Typing,
120    Custom(JsonValue),
121}
122
123impl EphemeralTestEvent {
124    /// Get the JSON representation of this test event.
125    pub fn into_json_value(self) -> JsonValue {
126        match self {
127            Self::ReadReceipt => test_json::sync_events::READ_RECEIPT.to_owned(),
128            Self::ReadReceiptOther => test_json::sync_events::READ_RECEIPT_OTHER.to_owned(),
129            Self::Typing => test_json::sync_events::TYPING.to_owned(),
130            Self::Custom(json) => json,
131        }
132    }
133
134    /// Get the typed JSON representation of this test event.
135    pub fn into_raw_event(self) -> Raw<AnySyncEphemeralRoomEvent> {
136        from_json_value(self.into_json_value()).unwrap()
137    }
138}
139
140/// Test events that can be added to the presence events.
141pub enum PresenceTestEvent {
142    Presence,
143    Custom(JsonValue),
144}
145
146impl PresenceTestEvent {
147    /// Get the JSON representation of this test event.
148    pub fn into_json_value(self) -> JsonValue {
149        match self {
150            Self::Presence => test_json::sync_events::PRESENCE.to_owned(),
151            Self::Custom(json) => json,
152        }
153    }
154
155    /// Get the typed JSON representation of this test event.
156    pub fn into_raw_event(self) -> Raw<PresenceEvent> {
157        from_json_value(self.into_json_value()).unwrap()
158    }
159}
160
161/// Test events that can be added to the global account data.
162pub enum GlobalAccountDataTestEvent {
163    Direct,
164    PushRules,
165    Custom(JsonValue),
166}
167
168impl GlobalAccountDataTestEvent {
169    /// Get the JSON representation of this test event.
170    pub fn into_json_value(self) -> JsonValue {
171        match self {
172            Self::Direct => test_json::sync_events::DIRECT.to_owned(),
173            Self::PushRules => test_json::sync_events::PUSH_RULES.to_owned(),
174            Self::Custom(json) => json,
175        }
176    }
177
178    /// Get the typed JSON representation of this test event.
179    pub fn into_raw_event(self) -> Raw<AnyGlobalAccountDataEvent> {
180        from_json_value(self.into_json_value()).unwrap()
181    }
182}