forked from djc/instant-epp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make contact's organization, province, postal code and voice optional.
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
Showing
5 changed files
with
126 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 { | ||
|
@@ -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,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"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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::<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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |