Share CheckResponse type with contacts
This commit is contained in:
parent
dd1c9c1e66
commit
a5d6643d6f
|
@ -44,7 +44,7 @@ impl Extension for NoExtension {
|
|||
pub struct Available {
|
||||
/// The resource name
|
||||
#[serde(rename = "$value")]
|
||||
pub name: StringValue<'static>,
|
||||
pub id: StringValue<'static>,
|
||||
/// The resource (un)availability
|
||||
#[serde(rename = "avail")]
|
||||
pub available: bool,
|
||||
|
@ -54,7 +54,7 @@ pub struct Available {
|
|||
#[derive(Deserialize, Debug)]
|
||||
pub struct CheckResponseDataItem {
|
||||
/// Data under the <name> tag
|
||||
#[serde(rename = "name")]
|
||||
#[serde(rename = "name", alias = "id")]
|
||||
pub resource: Available,
|
||||
/// The reason for (un)availability
|
||||
pub reason: Option<StringValue<'static>>,
|
||||
|
|
|
@ -2,12 +2,17 @@ use std::fmt::Debug;
|
|||
|
||||
/// Types for EPP contact check request
|
||||
use super::XMLNS;
|
||||
use crate::common::{NoExtension, StringValue};
|
||||
use crate::common::{CheckResponse, NoExtension, StringValue};
|
||||
use crate::request::{Command, Transaction};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
|
||||
impl<'a> Transaction<NoExtension> for ContactCheck<'a> {}
|
||||
|
||||
impl<'a> Command for ContactCheck<'a> {
|
||||
type Response = CheckResponse;
|
||||
const COMMAND: &'static str = "check";
|
||||
}
|
||||
|
||||
// Request
|
||||
|
||||
/// Type that represents the <check> command for contact transactions
|
||||
|
@ -40,50 +45,6 @@ impl<'a> ContactCheck<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Command for ContactCheck<'a> {
|
||||
type Response = ContactCheckResponse;
|
||||
const COMMAND: &'static str = "check";
|
||||
}
|
||||
|
||||
// Response
|
||||
|
||||
/// Type that represents the <id> tag for contact check response
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct ContactAvailable {
|
||||
/// The text of the <id> tag
|
||||
#[serde(rename = "$value")]
|
||||
pub id: StringValue<'static>,
|
||||
/// The avail attr on the <id> tag
|
||||
#[serde(rename = "avail")]
|
||||
pub available: bool,
|
||||
}
|
||||
|
||||
/// Type that represents the <cd> tag for contact check response
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct ContactCheckResponseDataItem {
|
||||
/// Data under the <id> tag
|
||||
#[serde(rename = "id")]
|
||||
pub contact: ContactAvailable,
|
||||
/// The reason for (un)availability
|
||||
pub reason: Option<StringValue<'static>>,
|
||||
}
|
||||
|
||||
/// Type that represents the <chkData> tag for contact check response
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct ContactCheckResponseData {
|
||||
/// Data under the <cd> tag
|
||||
#[serde(rename = "cd")]
|
||||
pub contact_list: Vec<ContactCheckResponseDataItem>,
|
||||
}
|
||||
|
||||
/// Type that represents the <resData> tag for contact check response
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct ContactCheckResponse {
|
||||
/// Data under the <chkData> tag
|
||||
#[serde(rename = "chkData")]
|
||||
pub check_data: ContactCheckResponseData,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ContactCheck;
|
||||
|
@ -114,15 +75,15 @@ mod tests {
|
|||
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
|
||||
assert_eq!(object.result.message, SUCCESS_MSG.into());
|
||||
assert_eq!(
|
||||
results.check_data.contact_list[0].contact.id,
|
||||
results.check_data.list[0].resource.id,
|
||||
"eppdev-contact-1".into()
|
||||
);
|
||||
assert!(!results.check_data.contact_list[0].contact.available);
|
||||
assert!(!results.check_data.list[0].resource.available);
|
||||
assert_eq!(
|
||||
results.check_data.contact_list[1].contact.id,
|
||||
results.check_data.list[1].resource.id,
|
||||
"eppdev-contact-2".into()
|
||||
);
|
||||
assert!(results.check_data.contact_list[1].contact.available);
|
||||
assert!(results.check_data.list[1].resource.available);
|
||||
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
|
||||
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
|
||||
}
|
||||
|
|
|
@ -75,9 +75,9 @@ mod tests {
|
|||
|
||||
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
|
||||
assert_eq!(object.result.message, SUCCESS_MSG.into());
|
||||
assert_eq!(result.check_data.list[0].resource.name, "eppdev.com".into());
|
||||
assert_eq!(result.check_data.list[0].resource.id, "eppdev.com".into());
|
||||
assert!(result.check_data.list[0].resource.available);
|
||||
assert_eq!(result.check_data.list[1].resource.name, "eppdev.net".into());
|
||||
assert_eq!(result.check_data.list[1].resource.id, "eppdev.net".into());
|
||||
assert!(!result.check_data.list[1].resource.available);
|
||||
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
|
||||
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
|
||||
|
|
|
@ -80,12 +80,12 @@ mod tests {
|
|||
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
|
||||
assert_eq!(object.result.message, SUCCESS_MSG.into());
|
||||
assert_eq!(
|
||||
result.check_data.list[0].resource.name,
|
||||
result.check_data.list[0].resource.id,
|
||||
"host1.eppdev-1.com".into()
|
||||
);
|
||||
assert!(result.check_data.list[0].resource.available);
|
||||
assert_eq!(
|
||||
result.check_data.list[1].resource.name,
|
||||
result.check_data.list[1].resource.id,
|
||||
"ns1.testing.com".into()
|
||||
);
|
||||
assert!(!result.check_data.list[1].resource.available);
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
//! // print the availability results
|
||||
//! response.res_data.unwrap().check_data.list
|
||||
//! .iter()
|
||||
//! .for_each(|chk| println!("Domain: {}, Available: {}", chk.resource.name, chk.resource.available));
|
||||
//! .for_each(|chk| println!("Domain: {}, Available: {}", chk.resource.id, chk.resource.available));
|
||||
//!
|
||||
//! // Close the connection
|
||||
//! client.transact(&Logout, "transaction-id").await.unwrap();
|
||||
|
|
|
@ -107,5 +107,5 @@ async fn client() {
|
|||
assert_eq!(rsp.result.code, ResultCode::CommandCompletedSuccessfully);
|
||||
|
||||
let result = rsp.res_data().unwrap();
|
||||
assert_eq!(result.check_data.list[0].resource.name, "eppdev.com".into());
|
||||
assert_eq!(result.check_data.list[0].resource.id, "eppdev.com".into());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue