add test for deserializing room_member

This commit is contained in:
Takayuki Maeda 2021-03-10 23:07:07 +09:00 committed by Jonas Platte
parent 9cfa3b075c
commit eb3763b301

View File

@ -68,3 +68,37 @@ impl RoomMember {
Default::default()
}
}
#[cfg(test)]
mod test {
use super::RoomMember;
use matches::assert_matches;
use serde_json::{from_value as from_json_value, json};
#[test]
fn deserialize_room_member() {
assert_matches!(
from_json_value::<RoomMember>(json!({
"display_name": "alice",
"avatar_url": "mxc://localhost:wefuiwegh8742w",
})).unwrap(),
RoomMember {
display_name: Some(display_name),
avatar_url: Some(avatar_url),
} if display_name == "alice"
&& avatar_url == "mxc://localhost:wefuiwegh8742w"
);
#[cfg(feature = "compat")]
assert_matches!(
from_json_value::<RoomMember>(json!({
"display_name": "alice",
"avatar_url": "",
})).unwrap(),
RoomMember {
display_name: Some(display_name),
avatar_url: None,
} if display_name == "alice"
);
}
}