xmpp-parsers: Add a MIX serialisation test.

Emmanuel Gil Peyrot created

Change summary

xmpp-parsers/src/mix.rs | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)

Detailed changes

xmpp-parsers/src/mix.rs 🔗

@@ -348,4 +348,45 @@ mod tests {
         let destroy = Destroy::try_from(elem).unwrap();
         assert_eq!(destroy.channel.0, "coucou");
     }
+
+    #[test]
+    fn serialise() {
+        let elem: Element = Join::from_nick_and_nodes("coucou", &["foo", "bar"]).into();
+        let xml = String::from(&elem);
+        assert_eq!(xml, "<join xmlns=\"urn:xmpp:mix:core:1\"><nick xmlns=\"urn:xmpp:mix:core:1\">coucou</nick><subscribe xmlns=\"urn:xmpp:mix:core:1\" node=\"foo\"/><subscribe xmlns=\"urn:xmpp:mix:core:1\" node=\"bar\"/></join>");
+
+        let elem: Element = UpdateSubscription::from_nodes(&["foo", "bar"]).into();
+        let xml = String::from(&elem);
+        assert_eq!(xml, "<update-subscription xmlns=\"urn:xmpp:mix:core:1\"><subscribe xmlns=\"urn:xmpp:mix:core:1\" node=\"foo\"/><subscribe xmlns=\"urn:xmpp:mix:core:1\" node=\"bar\"/></update-subscription>");
+
+        let elem: Element = Leave.into();
+        let xml = String::from(&elem);
+        assert_eq!(xml, "<leave xmlns=\"urn:xmpp:mix:core:1\"/>");
+
+        let elem: Element = SetNick::new("coucou").into();
+        let xml = String::from(&elem);
+        assert_eq!(xml, "<setnick xmlns=\"urn:xmpp:mix:core:1\"><nick xmlns=\"urn:xmpp:mix:core:1\">coucou</nick></setnick>");
+
+        let elem: Element = Mix::new("coucou", "coucou@example").into();
+        let xml = String::from(&elem);
+        assert_eq!(xml, "<mix xmlns=\"urn:xmpp:mix:core:1\"><nick xmlns=\"urn:xmpp:mix:core:1\">coucou</nick><jid xmlns=\"urn:xmpp:mix:core:1\">coucou@example</jid></mix>");
+
+        let elem: Element = Create::new().into();
+        let xml = String::from(&elem);
+        assert_eq!(xml, "<create xmlns=\"urn:xmpp:mix:core:1\"/>");
+
+        let elem: Element = Create::from_channel_id("coucou").into();
+        let xml = String::from(&elem);
+        assert_eq!(
+            xml,
+            "<create xmlns=\"urn:xmpp:mix:core:1\" channel=\"coucou\"/>"
+        );
+
+        let elem: Element = Destroy::new("coucou").into();
+        let xml = String::from(&elem);
+        assert_eq!(
+            xml,
+            "<destroy xmlns=\"urn:xmpp:mix:core:1\" channel=\"coucou\"/>"
+        );
+    }
 }