Skip to content

Commit

Permalink
Make contact's organization, province, postal code and voice optional.
Browse files Browse the repository at this point in the history
This changes the signature for `contact::Address::new`,
`contact::ContactCreate::new` and the type of fields
`contact::InfoData::voice` and `contact::ContactCreateRequest::voice`.

Fixes issue djc#13.
  • Loading branch information
kmkaplan committed Apr 3, 2023
1 parent bf5b444 commit 31976fa
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 25 deletions.
31 changes: 26 additions & 5 deletions src/contact/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct ContactCreateRequest<'a> {
/// Contact `<postalInfo>` tag
postal_info: PostalInfo<'a>,
/// Contact `<voice>` tag
voice: Voice<'a>,
voice: Option<Voice<'a>>,
/// Contact `<fax>` tag,]
fax: Option<Fax<'a>>,
/// Contact `<email>` tag
Expand All @@ -47,7 +47,7 @@ impl<'a> ContactCreate<'a> {
id: &'a str,
email: &'a str,
postal_info: PostalInfo<'a>,
voice: Voice<'a>,
voice: Option<Voice<'a>>,
auth_password: &'a str,
) -> Self {
Self {
Expand Down Expand Up @@ -93,8 +93,14 @@ mod tests {
#[test]
fn command() {
let street = &["58", "Orchid Road"];
let address = Address::new(street, "Paris", "Paris", "392374", "FR".parse().unwrap());
let postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address);
let address = Address::new(
street,
"Paris",
Some("Paris"),
Some("392374"),
"FR".parse().unwrap(),
);
let postal_info = PostalInfo::new("int", "John Doe", Some("Acme Widgets"), address);
let mut voice = Voice::new("+33.47237942");
voice.set_extension("123");
let mut fax = Fax::new("+33.86698799");
Expand All @@ -104,14 +110,29 @@ mod tests {
"eppdev-contact-3",
"[email protected]",
postal_info,
voice,
Some(voice),
"eppdev-387323",
);
object.set_fax(fax);

assert_serialized("request/contact/create.xml", &object);
}

#[test]
fn command_minimal() {
let address = Address::new(&[], "Paris", None, None, "FR".parse().unwrap());
let postal_info = PostalInfo::new("int", "John Doe", None, address);
let object = ContactCreate::new(
"eppdev-contact-3",
"[email protected]",
postal_info,
None,
"eppdev-387323",
);

assert_serialized("request/contact/create_minimal.xml", &object);
}

#[test]
fn response() {
let object = response_from_file::<ContactCreate>("response/contact/create.xml");
Expand Down
54 changes: 48 additions & 6 deletions src/contact/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct InfoData {
/// The postal info for the contact
pub postal_info: PostalInfo<'static>,
/// The voice data for the contact
pub voice: Voice<'static>,
pub voice: Option<Voice<'static>>,
/// The fax data for the contact
pub fax: Option<Fax<'static>>,
/// The email for the contact
Expand Down Expand Up @@ -109,7 +109,7 @@ mod tests {

let result = object.res_data().unwrap();
let fax = result.fax.as_ref().unwrap();
let voice_ext = result.voice.extension.as_ref().unwrap();
let voice_ext = result.voice.as_ref().unwrap().extension.as_ref().unwrap();
let fax_ext = fax.extension.as_ref().unwrap();
let auth_info = result.auth_info.as_ref().unwrap();

Expand All @@ -120,14 +120,20 @@ mod tests {
assert_eq!(result.statuses[0], Status::Ok);
assert_eq!(result.postal_info.info_type, "loc");
assert_eq!(result.postal_info.name, "John Doe");
assert_eq!(result.postal_info.organization, "Acme Widgets");
assert_eq!(result.postal_info.organization, Some("Acme Widgets".into()));
assert_eq!(result.postal_info.address.street[0], "58");
assert_eq!(result.postal_info.address.street[1], "Orchid Road");
assert_eq!(result.postal_info.address.city, "Paris");
assert_eq!(result.postal_info.address.province, "Paris");
assert_eq!(result.postal_info.address.postal_code, "392374");
assert_eq!(result.postal_info.address.province, Some("Paris".into()));
assert_eq!(
result.postal_info.address.postal_code,
Some("392374".into())
);
assert_eq!(result.postal_info.address.country.alpha2, "FR");
assert_eq!(result.voice.number, "+33.47237942".to_string());
assert_eq!(
result.voice.as_ref().unwrap().number,
"+33.47237942".to_string()
);
assert_eq!(*voice_ext, "123".to_string());
assert_eq!(fax.number, "+33.86698799".to_string());
assert_eq!(*fax_ext, "243".to_string());
Expand All @@ -147,4 +153,40 @@ mod tests {
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID);
assert_eq!(object.tr_ids.server_tr_id, SVTRID);
}

#[test]
fn response_minimal() {
let object = response_from_file::<ContactInfo>("response/contact/info_minimal.xml");

let result = object.res_data().unwrap();

assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG);
assert_eq!(result.id, "eppdev-contact-3");
assert_eq!(result.roid, "UNDEF-ROID");
assert_eq!(result.statuses[0], Status::Ok);
assert_eq!(result.postal_info.info_type, "loc");
assert_eq!(result.postal_info.name, "John Doe");
assert_eq!(result.postal_info.organization, None);
assert_eq!(result.postal_info.address.street[0], "58");
assert_eq!(result.postal_info.address.street[1], "Orchid Road");
assert_eq!(result.postal_info.address.city, "Paris");
assert_eq!(result.postal_info.address.province, None);
assert_eq!(result.postal_info.address.postal_code, None);
assert_eq!(result.postal_info.address.country.alpha2, "FR");
assert_eq!(result.voice, None);
assert_eq!(result.fax, None);
assert_eq!(result.email, "[email protected]");
assert_eq!(result.client_id, "eppdev");
assert_eq!(result.creator_id, "SYSTEM");
assert_eq!(
result.created_at,
Utc.with_ymd_and_hms(2021, 7, 23, 13, 9, 9).unwrap(),
);
assert_eq!(result.updater_id, None);
assert_eq!(result.updated_at, None);
assert_eq!(result.auth_info, None);
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID);
assert_eq!(object.tr_ids.server_tr_id, SVTRID);
}
}
24 changes: 12 additions & 12 deletions src/contact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl std::ops::Deref for Country {
}

/// The `<authInfo>` tag for domain and contact transactions
#[derive(Debug, Clone, FromXml, ToXml)]
#[derive(Debug, Clone, PartialEq, FromXml, ToXml)]
#[xml(rename = "authInfo", ns(XMLNS))]
pub struct ContactAuthInfo<'a> {
/// The `<pw>` tag under `<authInfo>`
Expand All @@ -93,7 +93,7 @@ impl<'a> ContactAuthInfo<'a> {
}

/// The data for `<voice>` types on domain transactions
#[derive(Debug, Clone, FromXml, ToXml)]
#[derive(Debug, Clone, PartialEq, FromXml, ToXml)]
#[xml(rename = "voice", ns(XMLNS))]
pub struct Voice<'a> {
/// The value of the 'x' attr on `<voice>` and `<fax>` tags
Expand All @@ -120,7 +120,7 @@ impl<'a> Voice<'a> {
}

/// The data for `<voice>` and `<fax>` types on domain transactions
#[derive(Debug, Clone, FromXml, ToXml)]
#[derive(Debug, Clone, FromXml, ToXml, PartialEq)]
#[xml(rename = "fax", ns(XMLNS))]
pub struct Fax<'a> {
/// The value of the 'x' attr on `<voice>` and `<fax>` tags
Expand Down Expand Up @@ -156,10 +156,10 @@ pub struct Address<'a> {
pub city: Cow<'a, str>,
/// The `<sp>` tag under `<addr>`
#[xml(rename = "sp")]
pub province: Cow<'a, str>,
pub province: Option<Cow<'a, str>>,
/// The `<pc>` tag under `<addr>`
#[xml(rename = "pc")]
pub postal_code: Cow<'a, str>,
pub postal_code: Option<Cow<'a, str>>,
/// The `<cc>` tag under `<addr>`
#[xml(rename = "cc")]
pub country: Country,
Expand All @@ -170,17 +170,17 @@ impl<'a> Address<'a> {
pub fn new(
street: &[&'a str],
city: &'a str,
province: &'a str,
postal_code: &'a str,
province: Option<&'a str>,
postal_code: Option<&'a str>,
country: Country,
) -> Self {
let street = street.iter().map(|&s| s.into()).collect();

Self {
street,
city: city.into(),
province: province.into(),
postal_code: postal_code.into(),
province: province.map(|sp| sp.into()),
postal_code: postal_code.map(|pc| pc.into()),
country,
}
}
Expand All @@ -197,7 +197,7 @@ pub struct PostalInfo<'a> {
pub name: Cow<'a, str>,
/// The `<org>` tag under `<postalInfo>`
#[xml(rename = "org")]
pub organization: Cow<'a, str>,
pub organization: Option<Cow<'a, str>>,
/// The `<addr>` tag under `<postalInfo>`
pub address: Address<'a>,
}
Expand All @@ -207,13 +207,13 @@ impl<'a> PostalInfo<'a> {
pub fn new(
info_type: &'a str,
name: &'a str,
organization: &'a str,
organization: Option<&'a str>,
address: Address<'a>,
) -> Self {
Self {
info_type: info_type.into(),
name: name.into(),
organization: organization.into(),
organization: organization.map(|org| org.into()),
address,
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/contact/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,14 @@ mod tests {
let mut object = ContactUpdate::new("eppdev-contact-3");

let street = &["58", "Orchid Road"];
let address = Address::new(street, "Paris", "Paris", "392374", "FR".parse().unwrap());
let postal_info = PostalInfo::new("loc", "John Doe", "Acme Widgets", address);
let address = Address::new(
street,
"Paris",
Some("Paris"),
Some("392374"),
"FR".parse().unwrap(),
);
let postal_info = PostalInfo::new("loc", "John Doe", Some("Acme Widgets"), address);
let voice = Voice::new("+33.47237942");

object.set_info("[email protected]", postal_info, voice, "eppdev-387323");
Expand Down
32 changes: 32 additions & 0 deletions tests/resources/response/contact/info_minimal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<contact:infData xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<contact:id>eppdev-contact-3</contact:id>
<contact:roid>UNDEF-ROID</contact:roid>
<contact:status s="ok"/>
<contact:postalInfo type="loc">
<contact:name>John Doe</contact:name>
<contact:addr>
<contact:street>58</contact:street>
<contact:street>Orchid Road</contact:street>
<contact:city>Paris</contact:city>
<contact:cc>FR</contact:cc>
</contact:addr>
</contact:postalInfo>
<contact:email>[email protected]</contact:email>
<contact:clID>eppdev</contact:clID>
<contact:crID>SYSTEM</contact:crID>
<contact:crDate>2021-07-23T13:09:09.0Z</contact:crDate>
</contact:infData>
</resData>
<trID>
<clTRID>cltrid:1626454866</clTRID>
<svTRID>RO-6879-1627224678242975</svTRID>
</trID>
</response>
</epp>

0 comments on commit 31976fa

Please sign in to comment.