pubsub: Add serialization test for configure element

Maxime “pep” Buquet created

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>

Change summary

xmpp-parsers/src/ns.rs            |  2 +
xmpp-parsers/src/pubsub/pubsub.rs | 38 ++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)

Detailed changes

xmpp-parsers/src/ns.rs 🔗

@@ -52,6 +52,8 @@ pub const PUBSUB_ERRORS: &str = "http://jabber.org/protocol/pubsub#errors";
 pub const PUBSUB_EVENT: &str = "http://jabber.org/protocol/pubsub#event";
 /// XEP-0060: Publish-Subscribe
 pub const PUBSUB_OWNER: &str = "http://jabber.org/protocol/pubsub#owner";
+/// XEP-0060: Publish-Subscribe node configuration
+pub const PUBSUB_CONFIGURE: &str = "http://jabber.org/protocol/pubsub#node_config";
 
 /// XEP-0071: XHTML-IM
 pub const XHTML_IM: &str = "http://jabber.org/protocol/xhtml-im";

xmpp-parsers/src/pubsub/pubsub.rs 🔗

@@ -518,6 +518,7 @@ impl From<PubSub> for Element {
 #[cfg(test)]
 mod tests {
     use super::*;
+    use crate::data_forms::{DataForm, DataFormType, Field, FieldType};
 
     #[test]
     fn create() {
@@ -556,7 +557,7 @@ mod tests {
     }
 
     #[test]
-    fn create_and_configure() {
+    fn create_and_configure_empty() {
         let elem: Element =
             "<pubsub xmlns='http://jabber.org/protocol/pubsub'><create/><configure/></pubsub>"
                 .parse()
@@ -575,6 +576,41 @@ mod tests {
         assert_eq!(elem1, elem2);
     }
 
+    #[test]
+    fn create_and_configure_simple() {
+        // XXX: Do we want xmpp-parsers to always specify the field type in the output Element?
+        let elem: Element = "<pubsub xmlns='http://jabber.org/protocol/pubsub'><create node='foo'/><configure><x xmlns='jabber:x:data' type='submit'><field var='FORM_TYPE' type='hidden'><value>http://jabber.org/protocol/pubsub#node_config</value></field><field var='pubsub#access_model' type='list-single'><value>whitelist</value></field></x></configure></pubsub>"
+        .parse()
+        .unwrap();
+        let elem1 = elem.clone();
+
+        let pubsub = PubSub::Create {
+            create: Create {
+                node: Some(NodeName(String::from("foo"))),
+            },
+            configure: Some(Configure {
+                form: Some(DataForm {
+                    type_: DataFormType::Submit,
+                    form_type: Some(String::from(ns::PUBSUB_CONFIGURE)),
+                    title: None,
+                    instructions: None,
+                    fields: vec![Field {
+                        var: String::from("pubsub#access_model"),
+                        type_: FieldType::ListSingle,
+                        label: None,
+                        required: false,
+                        options: vec![],
+                        values: vec![String::from("whitelist")],
+                        media: vec![],
+                    }],
+                }),
+            }),
+        };
+
+        let elem2 = Element::from(pubsub);
+        assert_eq!(elem1, elem2);
+    }
+
     #[test]
     fn publish() {
         let elem: Element =