use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use super::{EventType, ToDeviceEvent};
pub type DummyEvent = ToDeviceEvent<DummyEventContent>;
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct DummyEventContent {
#[serde(flatten)]
other: BTreeMap<String, Value>,
}
impl DummyEventContent {
pub fn new() -> Self {
Default::default()
}
}
impl EventType for DummyEventContent {
const EVENT_TYPE: &'static str = "m.dummy";
}
#[cfg(test)]
pub(super) mod tests {
use serde_json::{json, Value};
use super::DummyEvent;
pub fn json() -> Value {
json!({
"sender": "@alice:example.org",
"content": {
"m.custom": "something custom",
},
"type": "m.dummy",
"m.custom.top": "something custom in the top",
})
}
#[test]
fn deserialization() -> Result<(), serde_json::Error> {
let json = json();
let event: DummyEvent = serde_json::from_value(json.clone())?;
let serialized = serde_json::to_value(event)?;
assert_eq!(json, serialized);
Ok(())
}
}