matrix_sdk_crypto/types/events/
dummy.rs1use std::collections::BTreeMap;
18
19use serde::{Deserialize, Serialize};
20use serde_json::Value;
21
22use super::{EventType, ToDeviceEvent};
23
24pub type DummyEvent = ToDeviceEvent<DummyEventContent>;
26
27#[derive(Clone, Debug, Default, Serialize, Deserialize)]
29pub struct DummyEventContent {
30 #[serde(flatten)]
32 other: BTreeMap<String, Value>,
33}
34
35impl DummyEventContent {
36 pub fn new() -> Self {
38 Default::default()
39 }
40}
41
42impl EventType for DummyEventContent {
43 const EVENT_TYPE: &'static str = "m.dummy";
44}
45
46#[cfg(test)]
47pub(super) mod tests {
48 use serde_json::{json, Value};
49
50 use super::DummyEvent;
51
52 pub fn json() -> Value {
53 json!({
54 "sender": "@alice:example.org",
55 "content": {
56 "m.custom": "something custom",
57 },
58 "type": "m.dummy",
59 "m.custom.top": "something custom in the top",
60 })
61 }
62
63 #[test]
64 fn deserialization() -> Result<(), serde_json::Error> {
65 let json = json();
66 let event: DummyEvent = serde_json::from_value(json.clone())?;
67
68 let serialized = serde_json::to_value(event)?;
69 assert_eq!(json, serialized);
70
71 Ok(())
72 }
73}