forked from lavina/lavina
Sketch a serialization test
This commit is contained in:
parent
8d2e56fac9
commit
021bde729c
|
@ -183,6 +183,7 @@ pub struct XUserItem {
|
|||
pub jid: Jid,
|
||||
pub role: Role,
|
||||
}
|
||||
|
||||
impl ToXml for XUserItem {
|
||||
fn serialize(&self, output: &mut Vec<Event<'static>>) {
|
||||
let mut meg = BytesStart::new("item");
|
||||
|
@ -201,6 +202,7 @@ pub enum Affiliation {
|
|||
Outcast,
|
||||
None,
|
||||
}
|
||||
|
||||
impl Affiliation {
|
||||
pub fn from_str(s: &str) -> Option<Self> {
|
||||
match s {
|
||||
|
@ -231,6 +233,7 @@ pub enum Role {
|
|||
Visitor,
|
||||
None,
|
||||
}
|
||||
|
||||
impl Role {
|
||||
pub fn from_str(s: &str) -> Option<Self> {
|
||||
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:
|
||||
|
||||
<message from="duqedadi@conference.oflor.me/misha" xml:lang="en" to="misha@oflor.me/tux" type="groupchat" id="7ca7cb14-b2af-49c9-bd90-05dabb1113a5">
|
||||
<delay xmlns="urn:xmpp:delay" stamp="2024-05-17T16:05:28.440337Z" from="duqedadi@conference.oflor.me"/>
|
||||
|
@ -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#"<message from="duqedadi@conference.oflor.me/misha" xml:lang="en" to="misha@oflor.me/tux" type="groupchat" id="7ca7cb14-b2af-49c9-bd90-05dabb1113a5"><delay xmlns="urn:xmpp:delay" stamp="2024-05-17T16:05:28.440337Z" from="duqedadi@conference.oflor.me"/><body></body></message>"#;
|
||||
|
||||
// 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue