matrix_sdk_test/sync_builder/
test_event.rs
1use ruma::{
2 events::{
3 presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent,
4 AnyStrippedStateEvent, AnySyncStateEvent,
5 },
6 serde::Raw,
7};
8use serde_json::{from_value as from_json_value, Value as JsonValue};
9
10use crate::test_json;
11
12pub 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 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 pub fn into_raw_event(self) -> Raw<AnySyncStateEvent> {
65 from_json_value(self.into_json_value()).unwrap()
66 }
67}
68
69pub enum StrippedStateTestEvent {
71 Member,
72 RoomName,
73 Custom(JsonValue),
74}
75
76impl StrippedStateTestEvent {
77 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 pub fn into_raw_event(self) -> Raw<AnyStrippedStateEvent> {
88 from_json_value(self.into_json_value()).unwrap()
89 }
90}
91
92pub enum RoomAccountDataTestEvent {
94 FullyRead,
95 Tags,
96 Custom(JsonValue),
97}
98
99impl RoomAccountDataTestEvent {
100 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 pub fn into_raw_event(self) -> Raw<AnyRoomAccountDataEvent> {
111 from_json_value(self.into_json_value()).unwrap()
112 }
113}
114
115pub enum PresenceTestEvent {
117 Presence,
118 Custom(JsonValue),
119}
120
121impl PresenceTestEvent {
122 pub fn into_json_value(self) -> JsonValue {
124 match self {
125 Self::Presence => test_json::sync_events::PRESENCE.to_owned(),
126 Self::Custom(json) => json,
127 }
128 }
129
130 pub fn into_raw_event(self) -> Raw<PresenceEvent> {
132 from_json_value(self.into_json_value()).unwrap()
133 }
134}
135
136pub enum GlobalAccountDataTestEvent {
138 Direct,
139 PushRules,
140 Custom(JsonValue),
141}
142
143impl GlobalAccountDataTestEvent {
144 pub fn into_json_value(self) -> JsonValue {
146 match self {
147 Self::Direct => test_json::sync_events::DIRECT.to_owned(),
148 Self::PushRules => test_json::sync_events::PUSH_RULES.to_owned(),
149 Self::Custom(json) => json,
150 }
151 }
152
153 pub fn into_raw_event(self) -> Raw<AnyGlobalAccountDataEvent> {
155 from_json_value(self.into_json_value()).unwrap()
156 }
157}