Share CheckResponse type with contacts

This commit is contained in:
Dirkjan Ochtman 2022-01-27 12:24:47 +01:00 committed by masalachai
parent dd1c9c1e66
commit a5d6643d6f
6 changed files with 19 additions and 58 deletions

View File

@ -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 &lt;name&gt; tag
#[serde(rename = "name")]
#[serde(rename = "name", alias = "id")]
pub resource: Available,
/// The reason for (un)availability
pub reason: Option<StringValue<'static>>,

View File

@ -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 &lt;check&gt; 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 &lt;id&gt; tag for contact check response
#[derive(Deserialize, Debug)]
pub struct ContactAvailable {
/// The text of the &lt;id&gt; tag
#[serde(rename = "$value")]
pub id: StringValue<'static>,
/// The avail attr on the &lt;id&gt; tag
#[serde(rename = "avail")]
pub available: bool,
}
/// Type that represents the &lt;cd&gt; tag for contact check response
#[derive(Deserialize, Debug)]
pub struct ContactCheckResponseDataItem {
/// Data under the &lt;id&gt; tag
#[serde(rename = "id")]
pub contact: ContactAvailable,
/// The reason for (un)availability
pub reason: Option<StringValue<'static>>,
}
/// Type that represents the &lt;chkData&gt; tag for contact check response
#[derive(Deserialize, Debug)]
pub struct ContactCheckResponseData {
/// Data under the &lt;cd&gt; tag
#[serde(rename = "cd")]
pub contact_list: Vec<ContactCheckResponseDataItem>,
}
/// Type that represents the &lt;resData&gt; tag for contact check response
#[derive(Deserialize, Debug)]
pub struct ContactCheckResponse {
/// Data under the &lt;chkData&gt; 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());
}

View File

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

View File

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

View File

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

View File

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