events: Add serialization test for reaction

This commit is contained in:
Kévin Commaille 2022-11-25 20:03:18 +01:00 committed by Kévin Commaille
parent 5faff343a0
commit 80056c8a35

View File

@ -35,9 +35,10 @@ impl From<Annotation> for ReactionEventContent {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use assert_matches::assert_matches; use assert_matches::assert_matches;
use serde_json::{from_value as from_json_value, json}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
use super::ReactionEventContent; use super::ReactionEventContent;
use crate::{event_id, events::relation::Annotation};
#[test] #[test]
fn deserialize() { fn deserialize() {
@ -56,4 +57,23 @@ mod tests {
assert_eq!(relates_to.event_id, "$1598361704261elfgc:localhost"); assert_eq!(relates_to.event_id, "$1598361704261elfgc:localhost");
assert_eq!(relates_to.key, "🦛"); assert_eq!(relates_to.key, "🦛");
} }
#[test]
fn serialize() {
let content = ReactionEventContent::new(Annotation::new(
event_id!("$my_reaction").to_owned(),
"🏠".to_owned(),
));
assert_eq!(
to_json_value(&content).unwrap(),
json!({
"m.relates_to": {
"rel_type": "m.annotation",
"event_id": "$my_reaction",
"key": "🏠"
}
})
);
}
} }