From 021bde729c9bf9cb1fe9ffc0dac66f58c5e08b06 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Fri, 24 May 2024 20:07:40 +0200 Subject: [PATCH] Sketch a serialization test --- crates/proto-xmpp/src/muc/mod.rs | 46 +++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/crates/proto-xmpp/src/muc/mod.rs b/crates/proto-xmpp/src/muc/mod.rs index fecc58c..4df427c 100644 --- a/crates/proto-xmpp/src/muc/mod.rs +++ b/crates/proto-xmpp/src/muc/mod.rs @@ -183,6 +183,7 @@ pub struct XUserItem { pub jid: Jid, pub role: Role, } + impl ToXml for XUserItem { fn serialize(&self, output: &mut Vec>) { let mut meg = BytesStart::new("item"); @@ -201,6 +202,7 @@ pub enum Affiliation { Outcast, None, } + impl Affiliation { pub fn from_str(s: &str) -> Option { match s { @@ -231,6 +233,7 @@ pub enum Role { Visitor, None, } + impl Role { pub fn from_str(s: &str) -> Option { match s { @@ -278,7 +281,7 @@ impl ToXml for Delay { } /* - Example of an XMPP message with history stanza: + Example of an XMPP message with a history stanza: @@ -326,6 +329,7 @@ impl ToXml for XmppHistoryMessage { #[cfg(test)] mod test { use super::*; + use crate::bind::{Name, Resource, Server}; #[test] fn test_history_success_empty() { @@ -408,4 +412,44 @@ mod test { }; assert_eq!(res, expected); } + + #[test] + fn test_history_message_serialization() { + // Arrange + let history_message = XmppHistoryMessage { + id: "id".to_string(), + to: Jid { + name: Some(Name("sauer@oflor.me".into())), + server: Server("localhost".into()), + resource: Some(Resource("tester".into())), + }, + from: Jid { + name: Some(Name("pepe".into())), + server: Server("rooms.localhost".into()), + resource: Some(Resource("sauer".into())), + }, + delay: Delay { + from: Jid { + name: Some(Name("pepe".into())), + server: Server("rooms.localhost".into()), + resource: Some(Resource("tester".into())), + }, + stamp: "2021-10-10T10:10:10Z".to_string(), + }, + body: "Hello World.".to_string(), + }; + let mut events = vec![]; + let expected = r#""#; + + // Act + history_message.serialize(&mut events); + + // Assert + assert_eq!( + // events.pop().unwrap().to_vec(), + // expected.as_bytes() + String::from_utf8(events.pop().unwrap().to_vec()).unwrap(), + expected + ); + } }