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