1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
use ruma::{
    events::{
        presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent,
        AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncStateEvent,
    },
    serde::Raw,
};
use serde_json::{from_value as from_json_value, Value as JsonValue};

use crate::test_json;

/// Test events that can be added to the state.
pub enum StateTestEvent {
    Alias,
    Aliases,
    Create,
    Encryption,
    HistoryVisibility,
    JoinRules,
    Member,
    MemberAdditional,
    MemberBan,
    MemberInvite,
    MemberLeave,
    MemberNameChange,
    PowerLevels,
    RedactedInvalid,
    RedactedState,
    RoomAvatar,
    RoomName,
    RoomTopic,
    Custom(JsonValue),
}

impl StateTestEvent {
    /// Get the JSON representation of this test event.
    pub fn into_json_value(self) -> JsonValue {
        match self {
            Self::Alias => test_json::sync_events::ALIAS.to_owned(),
            Self::Aliases => test_json::sync_events::ALIASES.to_owned(),
            Self::Create => test_json::sync_events::CREATE.to_owned(),
            Self::Encryption => test_json::sync_events::ENCRYPTION.to_owned(),
            Self::HistoryVisibility => test_json::sync_events::HISTORY_VISIBILITY.to_owned(),
            Self::JoinRules => test_json::sync_events::JOIN_RULES.to_owned(),
            Self::Member => test_json::sync_events::MEMBER.to_owned(),
            Self::MemberAdditional => test_json::sync_events::MEMBER_ADDITIONAL.to_owned(),
            Self::MemberBan => test_json::sync_events::MEMBER_BAN.to_owned(),
            Self::MemberInvite => test_json::sync_events::MEMBER_INVITE.to_owned(),
            Self::MemberLeave => test_json::sync_events::MEMBER_LEAVE.to_owned(),
            Self::MemberNameChange => test_json::sync_events::MEMBER_NAME_CHANGE.to_owned(),
            Self::PowerLevels => test_json::sync_events::POWER_LEVELS.to_owned(),
            Self::RedactedInvalid => test_json::sync_events::REDACTED_INVALID.to_owned(),
            Self::RedactedState => test_json::sync_events::REDACTED_STATE.to_owned(),
            Self::RoomAvatar => test_json::sync_events::ROOM_AVATAR.to_owned(),
            Self::RoomName => test_json::sync_events::NAME.to_owned(),
            Self::RoomTopic => test_json::sync_events::TOPIC.to_owned(),
            Self::Custom(json) => json,
        }
    }

    /// Get the typed JSON representation of this test event.
    pub fn into_raw_event(self) -> Raw<AnySyncStateEvent> {
        from_json_value(self.into_json_value()).unwrap()
    }
}

/// Test events that can be added to the stripped state.
pub enum StrippedStateTestEvent {
    Member,
    RoomName,
    Custom(JsonValue),
}

impl StrippedStateTestEvent {
    /// Get the JSON representation of this test event.
    pub fn into_json_value(self) -> JsonValue {
        match self {
            Self::Member => test_json::sync_events::MEMBER_STRIPPED.to_owned(),
            Self::RoomName => test_json::sync_events::NAME_STRIPPED.to_owned(),
            Self::Custom(json) => json,
        }
    }

    /// Get the typed JSON representation of this test event.
    pub fn into_raw_event(self) -> Raw<AnyStrippedStateEvent> {
        from_json_value(self.into_json_value()).unwrap()
    }
}

/// Test events that can be added to the room account data.
pub enum RoomAccountDataTestEvent {
    FullyRead,
    Tags,
    Custom(JsonValue),
}

impl RoomAccountDataTestEvent {
    /// Get the JSON representation of this test event.
    pub fn into_json_value(self) -> JsonValue {
        match self {
            Self::FullyRead => test_json::sync_events::FULLY_READ.to_owned(),
            Self::Tags => test_json::sync_events::TAG.to_owned(),
            Self::Custom(json) => json,
        }
    }

    /// Get the typed JSON representation of this test event.
    pub fn into_raw_event(self) -> Raw<AnyRoomAccountDataEvent> {
        from_json_value(self.into_json_value()).unwrap()
    }
}

/// Test events that can be added to the ephemeral events.
pub enum EphemeralTestEvent {
    ReadReceipt,
    ReadReceiptOther,
    Typing,
    Custom(JsonValue),
}

impl EphemeralTestEvent {
    /// Get the JSON representation of this test event.
    pub fn into_json_value(self) -> JsonValue {
        match self {
            Self::ReadReceipt => test_json::sync_events::READ_RECEIPT.to_owned(),
            Self::ReadReceiptOther => test_json::sync_events::READ_RECEIPT_OTHER.to_owned(),
            Self::Typing => test_json::sync_events::TYPING.to_owned(),
            Self::Custom(json) => json,
        }
    }

    /// Get the typed JSON representation of this test event.
    pub fn into_raw_event(self) -> Raw<AnySyncEphemeralRoomEvent> {
        from_json_value(self.into_json_value()).unwrap()
    }
}

/// Test events that can be added to the presence events.
pub enum PresenceTestEvent {
    Presence,
    Custom(JsonValue),
}

impl PresenceTestEvent {
    /// Get the JSON representation of this test event.
    pub fn into_json_value(self) -> JsonValue {
        match self {
            Self::Presence => test_json::sync_events::PRESENCE.to_owned(),
            Self::Custom(json) => json,
        }
    }

    /// Get the typed JSON representation of this test event.
    pub fn into_raw_event(self) -> Raw<PresenceEvent> {
        from_json_value(self.into_json_value()).unwrap()
    }
}

/// Test events that can be added to the global account data.
pub enum GlobalAccountDataTestEvent {
    Direct,
    PushRules,
    Custom(JsonValue),
}

impl GlobalAccountDataTestEvent {
    /// Get the JSON representation of this test event.
    pub fn into_json_value(self) -> JsonValue {
        match self {
            Self::Direct => test_json::sync_events::DIRECT.to_owned(),
            Self::PushRules => test_json::sync_events::PUSH_RULES.to_owned(),
            Self::Custom(json) => json,
        }
    }

    /// Get the typed JSON representation of this test event.
    pub fn into_raw_event(self) -> Raw<AnyGlobalAccountDataEvent> {
        from_json_value(self.into_json_value()).unwrap()
    }
}