Update ignored_user_list tests

This commit is contained in:
Jonas Platte 2020-05-02 11:15:46 +02:00
parent f23d7414ec
commit d61b6c705c
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -70,6 +70,7 @@ pub(crate) mod raw {
mod tests { mod tests {
use std::convert::TryFrom; use std::convert::TryFrom;
use matches::assert_matches;
use ruma_identifiers::UserId; use ruma_identifiers::UserId;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
@ -84,7 +85,7 @@ mod tests {
}, },
}; };
let json_data = json!({ let json = json!({
"content": { "content": {
"ignored_users": { "ignored_users": {
"@carl:example.com": {} "@carl:example.com": {}
@ -93,12 +94,12 @@ mod tests {
"type": "m.ignored_user_list" "type": "m.ignored_user_list"
}); });
assert_eq!(to_json_value(ignored_user_list_event).unwrap(), json_data); assert_eq!(to_json_value(ignored_user_list_event).unwrap(), json);
} }
#[test] #[test]
fn deserialization() { fn deserialization() {
let json_data = json!({ let json = json!({
"content": { "content": {
"ignored_users": { "ignored_users": {
"@carl:example.com": {} "@carl:example.com": {}
@ -107,17 +108,14 @@ mod tests {
"type": "m.ignored_user_list" "type": "m.ignored_user_list"
}); });
let actual = from_json_value::<EventJson<IgnoredUserListEvent>>(json_data) assert_matches!(
from_json_value::<EventJson<IgnoredUserListEvent>>(json)
.unwrap() .unwrap()
.deserialize() .deserialize()
.unwrap(); .unwrap(),
IgnoredUserListEvent {
let expected = IgnoredUserListEvent { content: IgnoredUserListEventContent { ignored_users, },
content: IgnoredUserListEventContent { } if ignored_users == vec![UserId::try_from("@carl:example.com").unwrap()]
ignored_users: vec![UserId::try_from("@carl:example.com").unwrap()], );
},
};
assert_eq!(actual, expected);
} }
} }