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 jid: Jid,
|
||||||
pub role: Role,
|
pub role: Role,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToXml for XUserItem {
|
impl ToXml for XUserItem {
|
||||||
fn serialize(&self, output: &mut Vec<Event<'static>>) {
|
fn serialize(&self, output: &mut Vec<Event<'static>>) {
|
||||||
let mut meg = BytesStart::new("item");
|
let mut meg = BytesStart::new("item");
|
||||||
|
@ -201,6 +202,7 @@ pub enum Affiliation {
|
||||||
Outcast,
|
Outcast,
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Affiliation {
|
impl Affiliation {
|
||||||
pub fn from_str(s: &str) -> Option<Self> {
|
pub fn from_str(s: &str) -> Option<Self> {
|
||||||
match s {
|
match s {
|
||||||
|
@ -231,6 +233,7 @@ pub enum Role {
|
||||||
Visitor,
|
Visitor,
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Role {
|
impl Role {
|
||||||
pub fn from_str(s: &str) -> Option<Self> {
|
pub fn from_str(s: &str) -> Option<Self> {
|
||||||
match s {
|
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">
|
<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"/>
|
<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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::bind::{Name, Resource, Server};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_history_success_empty() {
|
fn test_history_success_empty() {
|
||||||
|
@ -408,4 +412,44 @@ mod test {
|
||||||
};
|
};
|
||||||
assert_eq!(res, expected);
|
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