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:
Emmanuel Gil Peyrot 2024-06-18 17:55:15 +02:00
parent 3d52905fe9
commit 2af07f4fc0
3 changed files with 35 additions and 122 deletions

View file

@ -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);

View file

@ -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")],
)),
}),
};

View file

@ -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"),
],
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 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"),
],
};
);
let server_info = ServerInfo {
abuse: vec![],