matrix_sdk_test/sync_builder/
test_event.rs

1use ruma::{
2    events::{
3        AnyRoomAccountDataEvent, AnyStrippedStateEvent, AnySyncStateEvent, presence::PresenceEvent,
4    },
5    serde::Raw,
6};
7use serde_json::{Value as JsonValue, from_value as from_json_value};
8
9use crate::test_json;
10
11/// Test events that can be added to the state.
12pub enum StateTestEvent {
13    Alias,
14    Aliases,
15    Create,
16    Encryption,
17    EncryptionWithEncryptedStateEvents,
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 From<StateTestEvent> for JsonValue {
37    fn from(val: StateTestEvent) -> Self {
38        match val {
39            StateTestEvent::Alias => test_json::sync_events::ALIAS.to_owned(),
40            StateTestEvent::Aliases => test_json::sync_events::ALIASES.to_owned(),
41            StateTestEvent::Create => test_json::sync_events::CREATE.to_owned(),
42            StateTestEvent::Encryption => test_json::sync_events::ENCRYPTION.to_owned(),
43            StateTestEvent::EncryptionWithEncryptedStateEvents => {
44                test_json::sync_events::ENCRYPTION_WITH_ENCRYPTED_STATE_EVENTS.to_owned()
45            }
46            StateTestEvent::HistoryVisibility => {
47                test_json::sync_events::HISTORY_VISIBILITY.to_owned()
48            }
49            StateTestEvent::JoinRules => test_json::sync_events::JOIN_RULES.to_owned(),
50            StateTestEvent::Member => test_json::sync_events::MEMBER.to_owned(),
51            StateTestEvent::MemberAdditional => {
52                test_json::sync_events::MEMBER_ADDITIONAL.to_owned()
53            }
54            StateTestEvent::MemberBan => test_json::sync_events::MEMBER_BAN.to_owned(),
55            StateTestEvent::MemberInvite => test_json::sync_events::MEMBER_INVITE.to_owned(),
56            StateTestEvent::MemberLeave => test_json::sync_events::MEMBER_LEAVE.to_owned(),
57            StateTestEvent::MemberNameChange => {
58                test_json::sync_events::MEMBER_NAME_CHANGE.to_owned()
59            }
60            StateTestEvent::PowerLevels => test_json::sync_events::POWER_LEVELS.to_owned(),
61            StateTestEvent::RedactedInvalid => test_json::sync_events::REDACTED_INVALID.to_owned(),
62            StateTestEvent::RedactedState => test_json::sync_events::REDACTED_STATE.to_owned(),
63            StateTestEvent::RoomAvatar => test_json::sync_events::ROOM_AVATAR.to_owned(),
64            StateTestEvent::RoomName => test_json::sync_events::NAME.to_owned(),
65            StateTestEvent::RoomPinnedEvents => test_json::sync_events::PINNED_EVENTS.to_owned(),
66            StateTestEvent::RoomTopic => test_json::sync_events::TOPIC.to_owned(),
67            StateTestEvent::Custom(json) => json,
68        }
69    }
70}
71
72impl From<StateTestEvent> for Raw<AnySyncStateEvent> {
73    fn from(val: StateTestEvent) -> Self {
74        from_json_value(val.into()).unwrap()
75    }
76}
77
78/// Test events that can be added to the stripped state.
79pub enum StrippedStateTestEvent {
80    Member,
81    RoomName,
82    Custom(JsonValue),
83}
84
85impl From<StrippedStateTestEvent> for JsonValue {
86    fn from(val: StrippedStateTestEvent) -> Self {
87        match val {
88            StrippedStateTestEvent::Member => test_json::sync_events::MEMBER_STRIPPED.to_owned(),
89            StrippedStateTestEvent::RoomName => test_json::sync_events::NAME_STRIPPED.to_owned(),
90            StrippedStateTestEvent::Custom(json) => json,
91        }
92    }
93}
94
95impl From<StrippedStateTestEvent> for Raw<AnyStrippedStateEvent> {
96    fn from(val: StrippedStateTestEvent) -> Self {
97        from_json_value(val.into()).unwrap()
98    }
99}
100
101/// Test events that can be added to the room account data.
102pub enum RoomAccountDataTestEvent {
103    FullyRead,
104    Tags,
105    MarkedUnread,
106    Custom(JsonValue),
107}
108
109impl From<RoomAccountDataTestEvent> for JsonValue {
110    fn from(val: RoomAccountDataTestEvent) -> Self {
111        match val {
112            RoomAccountDataTestEvent::FullyRead => test_json::sync_events::FULLY_READ.to_owned(),
113            RoomAccountDataTestEvent::Tags => test_json::sync_events::TAG.to_owned(),
114            RoomAccountDataTestEvent::MarkedUnread => {
115                test_json::sync_events::MARKED_UNREAD.to_owned()
116            }
117            RoomAccountDataTestEvent::Custom(json) => json,
118        }
119    }
120}
121
122impl From<RoomAccountDataTestEvent> for Raw<AnyRoomAccountDataEvent> {
123    fn from(val: RoomAccountDataTestEvent) -> Self {
124        from_json_value(val.into()).unwrap()
125    }
126}
127
128/// Test events that can be added to the presence events.
129pub enum PresenceTestEvent {
130    Presence,
131    Custom(JsonValue),
132}
133
134impl From<PresenceTestEvent> for JsonValue {
135    fn from(val: PresenceTestEvent) -> Self {
136        match val {
137            PresenceTestEvent::Presence => test_json::sync_events::PRESENCE.to_owned(),
138            PresenceTestEvent::Custom(json) => json,
139        }
140    }
141}
142
143impl From<PresenceTestEvent> for Raw<PresenceEvent> {
144    fn from(val: PresenceTestEvent) -> Self {
145        from_json_value(val.into()).unwrap()
146    }
147}