diff --git a/xmpp-parsers/src/ns.rs b/xmpp-parsers/src/ns.rs index 231d78e..511761a 100644 --- a/xmpp-parsers/src/ns.rs +++ b/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"; diff --git a/xmpp-parsers/src/pubsub/pubsub.rs b/xmpp-parsers/src/pubsub/pubsub.rs index 42e9bda..13184f6 100644 --- a/xmpp-parsers/src/pubsub/pubsub.rs +++ b/xmpp-parsers/src/pubsub/pubsub.rs @@ -518,6 +518,7 @@ impl From 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 = "" .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 = "http://jabber.org/protocol/pubsub#node_configwhitelist" + .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 =