roster: Fix group serialisation and add a test.
This commit is contained in:
parent
4338d9d638
commit
96fe2d200e
1 changed files with 24 additions and 2 deletions
|
@ -65,7 +65,7 @@ impl Into<Element> for Item {
|
|||
.attr("jid", String::from(self.jid))
|
||||
.attr("name", self.name)
|
||||
.attr("subscription", self.subscription)
|
||||
.append(self.groups)
|
||||
.append(self.groups.iter().map(|group| Element::builder("group").ns(ns::ROSTER).append(group)).collect::<Vec<_>>())
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
@ -172,6 +172,29 @@ mod tests {
|
|||
assert_eq!(roster.items[0].groups, vec!(String::from("Friends")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_groups() {
|
||||
let elem: Element = r#"
|
||||
<query xmlns='jabber:iq:roster'>
|
||||
<item jid='test@example.org'>
|
||||
<group>A</group>
|
||||
<group>B</group>
|
||||
</item>
|
||||
</query>
|
||||
"#.parse().unwrap();
|
||||
let elem1 = elem.clone();
|
||||
let roster = Roster::try_from(elem).unwrap();
|
||||
assert!(roster.ver.is_none());
|
||||
assert_eq!(roster.items.len(), 1);
|
||||
assert_eq!(roster.items[0].jid, Jid::from_str("test@example.org").unwrap());
|
||||
assert_eq!(roster.items[0].name, None);
|
||||
assert_eq!(roster.items[0].groups.len(), 2);
|
||||
assert_eq!(roster.items[0].groups[0], String::from("A"));
|
||||
assert_eq!(roster.items[0].groups[1], String::from("B"));
|
||||
let elem2 = roster.into();
|
||||
assert_eq!(elem1, elem2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set() {
|
||||
let elem: Element = "<query xmlns='jabber:iq:roster'><item jid='nurse@example.com'/></query>".parse().unwrap();
|
||||
|
@ -186,7 +209,6 @@ mod tests {
|
|||
<group>Servants</group>
|
||||
</item>
|
||||
</query>
|
||||
</query>
|
||||
"#.parse().unwrap();
|
||||
let roster = Roster::try_from(elem).unwrap();
|
||||
assert!(roster.ver.is_none());
|
||||
|
|
Loading…
Reference in a new issue