diff --git a/src/contact/create.rs b/src/contact/create.rs index 9692c7a..4c77256 100644 --- a/src/contact/create.rs +++ b/src/contact/create.rs @@ -25,7 +25,7 @@ pub struct ContactCreateRequest<'a> { /// Contact `` tag postal_info: PostalInfo<'a>, /// Contact `` tag - voice: Voice<'a>, + voice: Option>, /// Contact `` tag,] fax: Option>, /// Contact `` tag @@ -47,7 +47,7 @@ impl<'a> ContactCreate<'a> { id: &'a str, email: &'a str, postal_info: PostalInfo<'a>, - voice: Voice<'a>, + voice: Option>, auth_password: &'a str, ) -> Self { Self { @@ -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"); @@ -104,7 +110,7 @@ mod tests { "eppdev-contact-3", "contact@eppdev.net", postal_info, - voice, + Some(voice), "eppdev-387323", ); object.set_fax(fax); @@ -112,6 +118,21 @@ mod tests { 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", + "contact@eppdev.net", + postal_info, + None, + "eppdev-387323", + ); + + assert_serialized("request/contact/create_minimal.xml", &object); + } + #[test] fn response() { let object = response_from_file::("response/contact/create.xml"); diff --git a/src/contact/info.rs b/src/contact/info.rs index 25e0d8a..609428c 100644 --- a/src/contact/info.rs +++ b/src/contact/info.rs @@ -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>, /// The fax data for the contact pub fax: Option>, /// The email for the contact @@ -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(); @@ -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()); @@ -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::("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, "contact@eppdev.net"); + 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); + } } diff --git a/src/contact/mod.rs b/src/contact/mod.rs index e717282..3727e0d 100644 --- a/src/contact/mod.rs +++ b/src/contact/mod.rs @@ -75,7 +75,7 @@ impl std::ops::Deref for Country { } /// The `` 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 `` tag under `` @@ -93,7 +93,7 @@ impl<'a> ContactAuthInfo<'a> { } /// The data for `` 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 `` and `` tags @@ -120,7 +120,7 @@ impl<'a> Voice<'a> { } /// The data for `` and `` 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 `` and `` tags @@ -156,10 +156,10 @@ pub struct Address<'a> { pub city: Cow<'a, str>, /// The `` tag under `` #[xml(rename = "sp")] - pub province: Cow<'a, str>, + pub province: Option>, /// The `` tag under `` #[xml(rename = "pc")] - pub postal_code: Cow<'a, str>, + pub postal_code: Option>, /// The `` tag under `` #[xml(rename = "cc")] pub country: Country, @@ -170,8 +170,8 @@ 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(); @@ -179,8 +179,8 @@ impl<'a> Address<'a> { 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, } } @@ -197,7 +197,7 @@ pub struct PostalInfo<'a> { pub name: Cow<'a, str>, /// The `` tag under `` #[xml(rename = "org")] - pub organization: Cow<'a, str>, + pub organization: Option>, /// The `` tag under `` pub address: Address<'a>, } @@ -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, } } diff --git a/src/contact/update.rs b/src/contact/update.rs index c0ab021..0a978a4 100644 --- a/src/contact/update.rs +++ b/src/contact/update.rs @@ -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("newemail@eppdev.net", postal_info, voice, "eppdev-387323"); diff --git a/tests/resources/request/contact/create_minimal.xml b/tests/resources/request/contact/create_minimal.xml new file mode 100644 index 0000000..18a5ffd --- /dev/null +++ b/tests/resources/request/contact/create_minimal.xml @@ -0,0 +1,22 @@ + + + + + + eppdev-contact-3 + + John Doe + + Paris + FR + + + contact@eppdev.net + + eppdev-387323 + + + + cltrid:1626454866 + + diff --git a/tests/resources/response/contact/info_minimal.xml b/tests/resources/response/contact/info_minimal.xml new file mode 100644 index 0000000..3902a0f --- /dev/null +++ b/tests/resources/response/contact/info_minimal.xml @@ -0,0 +1,32 @@ + + + + + Command completed successfully + + + + eppdev-contact-3 + UNDEF-ROID + + + John Doe + + 58 + Orchid Road + Paris + FR + + + contact@eppdev.net + eppdev + SYSTEM + 2021-07-23T13:09:09.0Z + + + + cltrid:1626454866 + RO-6879-1627224678242975 + + +