From 38492dd09e77079714bc3ae6448da928a3f8fd62 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Tue, 23 Jul 2019 01:31:03 -0700 Subject: [PATCH] Split presence serialization/deserialization tests into two test cases. --- src/presence.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/presence.rs b/src/presence.rs index e10fa0f0..71951295 100644 --- a/src/presence.rs +++ b/src/presence.rs @@ -81,10 +81,8 @@ mod tests { use super::{PresenceEvent, PresenceEventContent, PresenceState}; - /// Test serialization and deserialization of example m.presence event from the spec - /// https://github.com/turt2live/matrix-doc/blob/master/event-schemas/examples/m.presence #[test] - fn test_example_event() { + fn serialization() { let event = PresenceEvent { content: PresenceEventContent { avatar_url: Some("mxc://localhost:wefuiwegh8742w".to_string()), @@ -96,12 +94,30 @@ mod tests { }, sender: UserId::try_from("@example:localhost").unwrap(), }; - let serialized_event = + + let json = r#"{"content":{"avatar_url":"mxc://localhost:wefuiwegh8742w","currently_active":false,"last_active_ago":2478593,"presence":"online","status_msg":"Making cupcakes"},"sender":"@example:localhost","type":"m.presence"}"#; - assert_eq!(to_string(&event).unwrap(), serialized_event); - let deserialized_event: PresenceEvent = serialized_event.parse().unwrap(); - assert_eq!(deserialized_event.content, event.content); - assert_eq!(deserialized_event.sender, event.sender); + assert_eq!(to_string(&event).unwrap(), json); + } + + #[test] + fn deserialization() { + let event = PresenceEvent { + content: PresenceEventContent { + avatar_url: Some("mxc://localhost:wefuiwegh8742w".to_string()), + currently_active: Some(false), + displayname: None, + last_active_ago: Some(UInt::try_from(2_478_593).unwrap()), + presence: PresenceState::Online, + status_msg: Some("Making cupcakes".to_string()), + }, + sender: UserId::try_from("@example:localhost").unwrap(), + }; + + let json = + r#"{"content":{"avatar_url":"mxc://localhost:wefuiwegh8742w","currently_active":false,"last_active_ago":2478593,"presence":"online","status_msg":"Making cupcakes"},"sender":"@example:localhost","type":"m.presence"}"#; + + assert_eq!(json.parse::().unwrap(), event); } }