mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
xmpp-parsers: Simplify DataForm creation using constructors
The redundancy made it harder to review changes to the Field struct, for
instance in a1bee56ee1
.
This commit is contained in:
parent
3d52905fe9
commit
2af07f4fc0
3 changed files with 35 additions and 122 deletions
|
@ -223,22 +223,12 @@ mod tests {
|
|||
|
||||
let pubsub = PubSubOwner::Configure(Configure {
|
||||
node: Some(NodeName(String::from("foo"))),
|
||||
form: Some(DataForm {
|
||||
type_: DataFormType::Submit,
|
||||
form_type: Some(String::from(ns::PUBSUB_CONFIGURE)),
|
||||
title: None,
|
||||
instructions: None,
|
||||
fields: vec![Field {
|
||||
var: Some(String::from("pubsub#access_model")),
|
||||
type_: FieldType::ListSingle,
|
||||
label: None,
|
||||
required: false,
|
||||
desc: None,
|
||||
options: vec![],
|
||||
values: vec![String::from("whitelist")],
|
||||
media: vec![],
|
||||
}],
|
||||
}),
|
||||
form: Some(DataForm::new(
|
||||
DataFormType::Submit,
|
||||
ns::PUBSUB_CONFIGURE,
|
||||
vec![Field::new("pubsub#access_model", FieldType::ListSingle)
|
||||
.with_value("whitelist")],
|
||||
)),
|
||||
});
|
||||
|
||||
let elem2 = Element::from(pubsub);
|
||||
|
@ -271,22 +261,12 @@ mod tests {
|
|||
let elem1 = elem.clone();
|
||||
|
||||
let pubsub = PubSubOwner::Default(Default {
|
||||
form: Some(DataForm {
|
||||
type_: DataFormType::Submit,
|
||||
form_type: Some(String::from(ns::PUBSUB_CONFIGURE)),
|
||||
title: None,
|
||||
instructions: None,
|
||||
fields: vec![Field {
|
||||
var: Some(String::from("pubsub#access_model")),
|
||||
type_: FieldType::ListSingle,
|
||||
label: None,
|
||||
required: false,
|
||||
desc: None,
|
||||
options: vec![],
|
||||
values: vec![String::from("whitelist")],
|
||||
media: vec![],
|
||||
}],
|
||||
}),
|
||||
form: Some(DataForm::new(
|
||||
DataFormType::Submit,
|
||||
ns::PUBSUB_CONFIGURE,
|
||||
vec![Field::new("pubsub#access_model", FieldType::ListSingle)
|
||||
.with_value("whitelist")],
|
||||
)),
|
||||
});
|
||||
|
||||
let elem2 = Element::from(pubsub);
|
||||
|
|
|
@ -615,22 +615,12 @@ mod tests {
|
|||
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: Some(String::from("pubsub#access_model")),
|
||||
type_: FieldType::ListSingle,
|
||||
label: None,
|
||||
required: false,
|
||||
desc: None,
|
||||
options: vec![],
|
||||
values: vec![String::from("whitelist")],
|
||||
media: vec![],
|
||||
}],
|
||||
}),
|
||||
form: Some(DataForm::new(
|
||||
DataFormType::Submit,
|
||||
ns::PUBSUB_CONFIGURE,
|
||||
vec![Field::new("pubsub#access_model", FieldType::ListSingle)
|
||||
.with_value("whitelist")],
|
||||
)),
|
||||
}),
|
||||
};
|
||||
|
||||
|
|
|
@ -116,81 +116,24 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_simple() {
|
||||
let form = DataForm {
|
||||
type_: DataFormType::Result_,
|
||||
form_type: Some(String::from(ns::SERVER_INFO)),
|
||||
title: None,
|
||||
instructions: None,
|
||||
fields: vec![
|
||||
Field {
|
||||
var: Some(String::from("abuse-addresses")),
|
||||
type_: FieldType::ListMulti,
|
||||
label: None,
|
||||
required: false,
|
||||
desc: None,
|
||||
options: vec![],
|
||||
values: vec![],
|
||||
media: vec![],
|
||||
},
|
||||
Field {
|
||||
var: Some(String::from("admin-addresses")),
|
||||
type_: FieldType::ListMulti,
|
||||
label: None,
|
||||
required: false,
|
||||
desc: None,
|
||||
options: vec![],
|
||||
values: vec![
|
||||
String::from("xmpp:admin@foo.bar"),
|
||||
String::from("https://foo.bar/chat/"),
|
||||
String::from("mailto:admin@foo.bar"),
|
||||
let form = DataForm::new(
|
||||
DataFormType::Result_,
|
||||
ns::SERVER_INFO,
|
||||
vec![
|
||||
Field::new("abuse-addresses", FieldType::ListMulti),
|
||||
Field::new("admin-addresses", FieldType::ListMulti)
|
||||
.with_value("xmpp:admin@foo.bar")
|
||||
.with_value("https://foo.bar/chat/")
|
||||
.with_value("mailto:admin@foo.bar"),
|
||||
Field::new("feedback-addresses", FieldType::ListMulti),
|
||||
Field::new("sales-addresses", FieldType::ListMulti),
|
||||
Field::new("security-addresses", FieldType::ListMulti)
|
||||
.with_value("xmpp:security@foo.bar")
|
||||
.with_value("mailto:security@foo.bar"),
|
||||
Field::new("support-addresses", FieldType::ListMulti)
|
||||
.with_value("mailto:support@foo.bar"),
|
||||
],
|
||||
media: vec![],
|
||||
},
|
||||
Field {
|
||||
var: Some(String::from("feedback-addresses")),
|
||||
type_: FieldType::ListMulti,
|
||||
label: None,
|
||||
required: false,
|
||||
desc: None,
|
||||
options: vec![],
|
||||
values: vec![],
|
||||
media: vec![],
|
||||
},
|
||||
Field {
|
||||
var: Some(String::from("sales-addresses")),
|
||||
type_: FieldType::ListMulti,
|
||||
label: None,
|
||||
required: false,
|
||||
desc: None,
|
||||
options: vec![],
|
||||
values: vec![],
|
||||
media: vec![],
|
||||
},
|
||||
Field {
|
||||
var: Some(String::from("security-addresses")),
|
||||
type_: FieldType::ListMulti,
|
||||
label: None,
|
||||
required: false,
|
||||
desc: None,
|
||||
options: vec![],
|
||||
values: vec![
|
||||
String::from("xmpp:security@foo.bar"),
|
||||
String::from("mailto:security@foo.bar"),
|
||||
],
|
||||
media: vec![],
|
||||
},
|
||||
Field {
|
||||
var: Some(String::from("support-addresses")),
|
||||
type_: FieldType::ListMulti,
|
||||
label: None,
|
||||
required: false,
|
||||
desc: None,
|
||||
options: vec![],
|
||||
values: vec![String::from("mailto:support@foo.bar")],
|
||||
media: vec![],
|
||||
},
|
||||
],
|
||||
};
|
||||
);
|
||||
|
||||
let server_info = ServerInfo {
|
||||
abuse: vec![],
|
||||
|
|
Loading…
Reference in a new issue