Use DateTime types where possible

This commit is contained in:
Dirkjan Ochtman 2022-02-22 18:41:26 +01:00 committed by masalachai
parent f7d76adef3
commit 7e0a51bebb
12 changed files with 120 additions and 72 deletions

View File

@ -13,7 +13,7 @@ default = ["tokio-rustls"]
[dependencies] [dependencies]
async-trait = "0.1.52" async-trait = "0.1.52"
celes = "2.1" celes = "2.1"
chrono = "0.4" chrono = { version = "0.4", features = ["serde"] }
quick-xml = { version = "0.22", features = [ "serialize" ] } quick-xml = { version = "0.22", features = [ "serialize" ] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.0", features = [ "full" ] } tokio = { version = "1.0", features = [ "full" ] }

View File

@ -1,9 +1,11 @@
//! Types for EPP contact create request //! Types for EPP contact create request
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::{ContactAuthInfo, Phone, PostalInfo, XMLNS}; use super::{ContactAuthInfo, Phone, PostalInfo, XMLNS};
use crate::common::{NoExtension, StringValue}; use crate::common::{NoExtension, StringValue};
use crate::request::{Command, Transaction}; use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize};
impl<'a> Transaction<NoExtension> for ContactCreate<'a> {} impl<'a> Transaction<NoExtension> for ContactCreate<'a> {}
@ -84,7 +86,7 @@ pub struct ContactCreateData {
pub id: StringValue<'static>, pub id: StringValue<'static>,
#[serde(rename = "crDate")] #[serde(rename = "crDate")]
/// The contact creation date /// The contact creation date
pub created_at: StringValue<'static>, pub created_at: DateTime<Utc>,
} }
/// Type that represents the &lt;resData&gt; tag for contact create response /// Type that represents the &lt;resData&gt; tag for contact create response
@ -97,6 +99,8 @@ pub struct ContactCreateResponse {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use chrono::{TimeZone, Utc};
use super::{ContactCreate, Phone, PostalInfo}; use super::{ContactCreate, Phone, PostalInfo};
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::contact::Address; use crate::contact::Address;
@ -146,7 +150,7 @@ mod tests {
assert_eq!(results.create_data.id, "eppdev-contact-4".into()); assert_eq!(results.create_data.id, "eppdev-contact-4".into());
assert_eq!( assert_eq!(
results.create_data.created_at, results.create_data.created_at,
"2021-07-25T16:05:32.0Z".into() Utc.ymd(2021, 7, 25).and_hms(16, 5, 32)
); );
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -1,9 +1,11 @@
//! Types for EPP contact info request //! Types for EPP contact info request
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::{ContactAuthInfo, Phone, PostalInfo, XMLNS}; use super::{ContactAuthInfo, Phone, PostalInfo, XMLNS};
use crate::common::{NoExtension, ObjectStatus, StringValue}; use crate::common::{NoExtension, ObjectStatus, StringValue};
use crate::request::{Command, Transaction}; use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize};
impl<'a> Transaction<NoExtension> for ContactInfo<'a> {} impl<'a> Transaction<NoExtension> for ContactInfo<'a> {}
@ -77,16 +79,16 @@ pub struct ContactInfoData<'a> {
pub creator_id: StringValue<'a>, pub creator_id: StringValue<'a>,
/// The creation date /// The creation date
#[serde(rename = "crDate")] #[serde(rename = "crDate")]
pub created_at: StringValue<'a>, pub created_at: DateTime<Utc>,
/// The epp user who last updated the contact /// The epp user who last updated the contact
#[serde(rename = "upID")] #[serde(rename = "upID")]
pub updater_id: Option<StringValue<'a>>, pub updater_id: Option<StringValue<'a>>,
/// The last update date /// The last update date
#[serde(rename = "upDate")] #[serde(rename = "upDate")]
pub updated_at: Option<StringValue<'a>>, pub updated_at: Option<DateTime<Utc>>,
/// The contact transfer date /// The contact transfer date
#[serde(rename = "trDate")] #[serde(rename = "trDate")]
pub transferred_at: Option<StringValue<'a>>, pub transferred_at: Option<DateTime<Utc>>,
/// The contact auth info /// The contact auth info
#[serde(rename = "authInfo")] #[serde(rename = "authInfo")]
pub auth_info: Option<ContactAuthInfo<'a>>, pub auth_info: Option<ContactAuthInfo<'a>>,
@ -102,6 +104,8 @@ pub struct ContactInfoResponse {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use chrono::{TimeZone, Utc};
use super::ContactInfo; use super::ContactInfo;
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
@ -166,14 +170,17 @@ mod tests {
assert_eq!(result.info_data.email, "contact@eppdev.net".into()); assert_eq!(result.info_data.email, "contact@eppdev.net".into());
assert_eq!(result.info_data.client_id, "eppdev".into()); assert_eq!(result.info_data.client_id, "eppdev".into());
assert_eq!(result.info_data.creator_id, "SYSTEM".into()); assert_eq!(result.info_data.creator_id, "SYSTEM".into());
assert_eq!(result.info_data.created_at, "2021-07-23T13:09:09.0Z".into()); assert_eq!(
result.info_data.created_at,
Utc.ymd(2021, 7, 23).and_hms(13, 9, 9)
);
assert_eq!( assert_eq!(
*(result.info_data.updater_id.as_ref().unwrap()), *(result.info_data.updater_id.as_ref().unwrap()),
"SYSTEM".into() "SYSTEM".into()
); );
assert_eq!( assert_eq!(
*(result.info_data.updated_at.as_ref().unwrap()), result.info_data.updated_at,
"2021-07-23T13:09:09.0Z".into() Some(Utc.ymd(2021, 7, 23).and_hms(13, 9, 9))
); );
assert_eq!((*auth_info).password, "eppdev-387323".into()); assert_eq!((*auth_info).password, "eppdev-387323".into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());

View File

@ -1,11 +1,12 @@
//! Types for EPP domain create request //! Types for EPP domain create request
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::{DomainAuthInfo, DomainContact, HostList, Period, XMLNS}; use super::{DomainAuthInfo, DomainContact, HostList, Period, XMLNS};
use crate::common::{NoExtension, StringValue}; use crate::common::{NoExtension, StringValue};
use crate::request::{Command, Transaction}; use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize};
impl<'a> Transaction<NoExtension> for DomainCreate<'a> {} impl<'a> Transaction<NoExtension> for DomainCreate<'a> {}
impl<'a> Command for DomainCreate<'a> { impl<'a> Command for DomainCreate<'a> {
@ -87,10 +88,10 @@ pub struct DomainCreateResponseData {
pub name: StringValue<'static>, pub name: StringValue<'static>,
/// The creation date /// The creation date
#[serde(rename = "crDate")] #[serde(rename = "crDate")]
pub created_at: StringValue<'static>, pub created_at: DateTime<Utc>,
/// The expiry date /// The expiry date
#[serde(rename = "exDate")] #[serde(rename = "exDate")]
pub expiring_at: Option<StringValue<'static>>, pub expiring_at: Option<DateTime<Utc>>,
} }
/// Type that represents the &lt;resData&gt; tag for domain create response /// Type that represents the &lt;resData&gt; tag for domain create response
@ -103,13 +104,16 @@ pub struct DomainCreateResponse {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::net::IpAddr;
use chrono::{TimeZone, Utc};
use super::{DomainContact, DomainCreate, HostList, Period}; use super::{DomainContact, DomainCreate, HostList, Period};
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::domain::{HostAttr, HostAttrList, HostObjList}; use crate::domain::{HostAttr, HostAttrList, HostObjList};
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use std::net::IpAddr;
#[test] #[test]
fn command() { fn command() {
@ -244,11 +248,11 @@ mod tests {
assert_eq!(result.create_data.name, "eppdev-2.com".into()); assert_eq!(result.create_data.name, "eppdev-2.com".into());
assert_eq!( assert_eq!(
result.create_data.created_at, result.create_data.created_at,
"2021-07-25T18:11:35.0Z".into() Utc.ymd(2021, 7, 25).and_hms(18, 11, 35)
); );
assert_eq!( assert_eq!(
*result.create_data.expiring_at.as_ref().unwrap(), *result.create_data.expiring_at.as_ref().unwrap(),
"2022-07-25T18:11:34.0Z".into() Utc.ymd(2022, 7, 25).and_hms(18, 11, 34)
); );
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -1,9 +1,11 @@
//! Types for EPP domain info request //! Types for EPP domain info request
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::{DomainAuthInfo, DomainContact, HostAttr, XMLNS}; use super::{DomainAuthInfo, DomainContact, HostAttr, XMLNS};
use crate::common::{NoExtension, ObjectStatus, StringValue}; use crate::common::{NoExtension, ObjectStatus, StringValue};
use crate::request::{Command, Transaction}; use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize};
impl<'a> Transaction<NoExtension> for DomainInfo<'a> {} impl<'a> Transaction<NoExtension> for DomainInfo<'a> {}
@ -102,19 +104,19 @@ pub struct DomainInfoResponseData {
pub creator_id: Option<StringValue<'static>>, pub creator_id: Option<StringValue<'static>>,
/// The domain creation date /// The domain creation date
#[serde(rename = "crDate")] #[serde(rename = "crDate")]
pub created_at: Option<StringValue<'static>>, pub created_at: Option<DateTime<Utc>>,
/// The domain expiry date /// The domain expiry date
#[serde(rename = "exDate")] #[serde(rename = "exDate")]
pub expiring_at: Option<StringValue<'static>>, pub expiring_at: Option<DateTime<Utc>>,
/// The epp user who last updated the domain /// The epp user who last updated the domain
#[serde(rename = "upID")] #[serde(rename = "upID")]
pub updater_id: Option<StringValue<'static>>, pub updater_id: Option<StringValue<'static>>,
/// The domain last updated date /// The domain last updated date
#[serde(rename = "upDate")] #[serde(rename = "upDate")]
pub updated_at: Option<StringValue<'static>>, pub updated_at: Option<DateTime<Utc>>,
/// The domain transfer date /// The domain transfer date
#[serde(rename = "trDate")] #[serde(rename = "trDate")]
pub transferred_at: Option<StringValue<'static>>, pub transferred_at: Option<DateTime<Utc>>,
/// The domain auth info /// The domain auth info
#[serde(rename = "authInfo")] #[serde(rename = "authInfo")]
pub auth_info: Option<DomainAuthInfo<'static>>, pub auth_info: Option<DomainAuthInfo<'static>>,
@ -135,6 +137,7 @@ mod tests {
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use chrono::{TimeZone, Utc};
#[test] #[test]
fn command() { fn command() {
@ -188,7 +191,7 @@ mod tests {
); );
assert_eq!( assert_eq!(
*result.info_data.created_at.as_ref().unwrap(), *result.info_data.created_at.as_ref().unwrap(),
"2021-07-23T15:31:20.0Z".into() Utc.ymd(2021, 7, 23).and_hms(15, 31, 20)
); );
assert_eq!( assert_eq!(
*result.info_data.updater_id.as_ref().unwrap(), *result.info_data.updater_id.as_ref().unwrap(),
@ -196,11 +199,11 @@ mod tests {
); );
assert_eq!( assert_eq!(
*result.info_data.updated_at.as_ref().unwrap(), *result.info_data.updated_at.as_ref().unwrap(),
"2021-07-23T15:31:21.0Z".into() Utc.ymd(2021, 7, 23).and_hms(15, 31, 21)
); );
assert_eq!( assert_eq!(
*result.info_data.expiring_at.as_ref().unwrap(), *result.info_data.expiring_at.as_ref().unwrap(),
"2023-07-23T15:31:20.0Z".into() Utc.ymd(2023, 7, 23).and_hms(15, 31, 20)
); );
assert_eq!((*auth_info).password, "epP4uthd#v".into()); assert_eq!((*auth_info).password, "epP4uthd#v".into());
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());

View File

@ -1,10 +1,11 @@
//! Types for EPP domain renew request //! Types for EPP domain renew request
use chrono::{DateTime, NaiveDate, Utc};
use serde::{Deserialize, Serialize};
use super::{Period, XMLNS}; use super::{Period, XMLNS};
use crate::common::{NoExtension, StringValue}; use crate::common::{NoExtension, StringValue};
use crate::request::{Command, Transaction}; use crate::request::{Command, Transaction};
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
impl<'a> Transaction<NoExtension> for DomainRenew<'a> {} impl<'a> Transaction<NoExtension> for DomainRenew<'a> {}
@ -63,7 +64,7 @@ pub struct DomainRenewResponseData {
pub name: StringValue<'static>, pub name: StringValue<'static>,
/// The new expiry date after renewal /// The new expiry date after renewal
#[serde(rename = "exDate")] #[serde(rename = "exDate")]
pub expiring_at: Option<StringValue<'static>>, pub expiring_at: Option<DateTime<Utc>>,
} }
/// Type that represents the &lt;resData&gt; tag for domain renew response /// Type that represents the &lt;resData&gt; tag for domain renew response
@ -81,7 +82,8 @@ mod tests {
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
use chrono::NaiveDate;
use chrono::{NaiveDate, TimeZone, Utc};
#[test] #[test]
fn command() { fn command() {
@ -110,7 +112,7 @@ mod tests {
assert_eq!(result.renew_data.name, "eppdev-1.com".into()); assert_eq!(result.renew_data.name, "eppdev-1.com".into());
assert_eq!( assert_eq!(
*result.renew_data.expiring_at.as_ref().unwrap(), *result.renew_data.expiring_at.as_ref().unwrap(),
"2024-07-23T15:31:20.0Z".into() Utc.ymd(2024, 7, 23).and_hms(15, 31, 20)
); );
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -1,9 +1,11 @@
//! Types for EPP domain transfer request //! Types for EPP domain transfer request
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::{DomainAuthInfo, Period, XMLNS}; use super::{DomainAuthInfo, Period, XMLNS};
use crate::common::{NoExtension, StringValue}; use crate::common::{NoExtension, StringValue};
use crate::request::{Command, Transaction}; use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize};
impl<'a> Transaction<NoExtension> for DomainTransfer<'a> {} impl<'a> Transaction<NoExtension> for DomainTransfer<'a> {}
@ -109,16 +111,16 @@ pub struct DomainTransferResponseData {
pub requester_id: StringValue<'static>, pub requester_id: StringValue<'static>,
/// The transfer rquest date /// The transfer rquest date
#[serde(rename = "reDate")] #[serde(rename = "reDate")]
pub requested_at: StringValue<'static>, pub requested_at: DateTime<Utc>,
/// The epp user who should acknowledge the transfer request /// The epp user who should acknowledge the transfer request
#[serde(rename = "acID")] #[serde(rename = "acID")]
pub ack_id: StringValue<'static>, pub ack_id: StringValue<'static>,
/// THe date by which the acknowledgment should be made /// THe date by which the acknowledgment should be made
#[serde(rename = "acDate")] #[serde(rename = "acDate")]
pub ack_by: StringValue<'static>, pub ack_by: DateTime<Utc>,
/// The domain expiry date /// The domain expiry date
#[serde(rename = "exDate")] #[serde(rename = "exDate")]
pub expiring_at: Option<StringValue<'static>>, pub expiring_at: Option<DateTime<Utc>>,
} }
/// Type that represents the &lt;resData&gt; tag for domain transfer response /// Type that represents the &lt;resData&gt; tag for domain transfer response
@ -131,6 +133,8 @@ pub struct DomainTransferResponse {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use chrono::{TimeZone, Utc};
use super::{DomainTransfer, Period}; use super::{DomainTransfer, Period};
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
@ -225,13 +229,16 @@ mod tests {
assert_eq!(result.transfer_data.requester_id, "eppdev".into()); assert_eq!(result.transfer_data.requester_id, "eppdev".into());
assert_eq!( assert_eq!(
result.transfer_data.requested_at, result.transfer_data.requested_at,
"2021-07-23T15:31:21.0Z".into() Utc.ymd(2021, 7, 23).and_hms(15, 31, 21),
); );
assert_eq!(result.transfer_data.ack_id, "ClientY".into()); assert_eq!(result.transfer_data.ack_id, "ClientY".into());
assert_eq!(result.transfer_data.ack_by, "2021-07-28T15:31:21.0Z".into());
assert_eq!( assert_eq!(
*result.transfer_data.expiring_at.as_ref().unwrap(), result.transfer_data.ack_by,
"2022-07-02T14:53:19.0Z".into() Utc.ymd(2021, 7, 28).and_hms(15, 31, 21)
);
assert_eq!(
result.transfer_data.expiring_at,
Some(Utc.ymd(2022, 7, 2).and_hms(14, 53, 19)),
); );
assert_eq!(*object.tr_ids.client_tr_id.as_ref().unwrap(), CLTRID.into()); assert_eq!(*object.tr_ids.client_tr_id.as_ref().unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
@ -292,13 +299,16 @@ mod tests {
assert_eq!(result.transfer_data.requester_id, "eppdev".into()); assert_eq!(result.transfer_data.requester_id, "eppdev".into());
assert_eq!( assert_eq!(
result.transfer_data.requested_at, result.transfer_data.requested_at,
"2021-07-23T15:31:21.0Z".into() Utc.ymd(2021, 7, 23).and_hms(15, 31, 21)
); );
assert_eq!(result.transfer_data.ack_id, "ClientY".into()); assert_eq!(result.transfer_data.ack_id, "ClientY".into());
assert_eq!(result.transfer_data.ack_by, "2021-07-28T15:31:21.0Z".into());
assert_eq!( assert_eq!(
*result.transfer_data.expiring_at.as_ref().unwrap(), result.transfer_data.ack_by,
"2022-07-02T14:53:19.0Z".into() Utc.ymd(2021, 7, 28).and_hms(15, 31, 21)
);
assert_eq!(
result.transfer_data.expiring_at,
Some(Utc.ymd(2022, 7, 2).and_hms(14, 53, 19))
); );
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -1,5 +1,6 @@
use std::fmt::Debug; use std::fmt::Debug;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Deserializer, Serialize};
use crate::common::{Options, ServiceExtension, Services, StringValue, EPP_XMLNS}; use crate::common::{Options, ServiceExtension, Services, StringValue, EPP_XMLNS};
@ -286,7 +287,7 @@ pub struct Greeting {
pub service_id: String, pub service_id: String,
/// The date from the EPP server /// The date from the EPP server
#[serde(rename = "svDate")] #[serde(rename = "svDate")]
pub service_date: String, pub service_date: DateTime<Utc>,
/// Data under the <svcMenu> element /// Data under the <svcMenu> element
#[serde(rename = "svcMenu")] #[serde(rename = "svcMenu")]
pub svc_menu: ServiceMenu, pub svc_menu: ServiceMenu,
@ -305,6 +306,8 @@ impl EppXml for GreetingDocument {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use chrono::{TimeZone, Utc};
use super::{ExpiryType, GreetingDocument, HelloDocument, Relative}; use super::{ExpiryType, GreetingDocument, HelloDocument, Relative};
use crate::tests::get_xml; use crate::tests::get_xml;
use crate::xml::EppXml; use crate::xml::EppXml;
@ -323,7 +326,10 @@ mod tests {
let object = GreetingDocument::deserialize(xml.as_str()).unwrap(); let object = GreetingDocument::deserialize(xml.as_str()).unwrap();
assert_eq!(object.data.service_id, "ISPAPI EPP Server"); assert_eq!(object.data.service_id, "ISPAPI EPP Server");
assert_eq!(object.data.service_date, "2021-07-25T14:51:17.0Z"); assert_eq!(
object.data.service_date,
Utc.ymd(2021, 7, 25).and_hms(14, 51, 17)
);
assert_eq!(object.data.svc_menu.options.version, "1.0".into()); assert_eq!(object.data.svc_menu.options.version, "1.0".into());
assert_eq!(object.data.svc_menu.options.lang, "en".into()); assert_eq!(object.data.svc_menu.options.lang, "en".into());
assert_eq!(object.data.svc_menu.services.obj_uris.len(), 4); assert_eq!(object.data.svc_menu.services.obj_uris.len(), 4);

View File

@ -2,10 +2,12 @@
use std::net::IpAddr; use std::net::IpAddr;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::XMLNS; use super::XMLNS;
use crate::common::{serialize_host_addrs_option, NoExtension, StringValue}; use crate::common::{serialize_host_addrs_option, NoExtension, StringValue};
use crate::request::{Command, Transaction}; use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize};
impl<'a> Transaction<NoExtension> for HostCreate<'a> {} impl<'a> Transaction<NoExtension> for HostCreate<'a> {}
@ -59,7 +61,7 @@ pub struct HostCreateData {
pub name: StringValue<'static>, pub name: StringValue<'static>,
/// The host creation date /// The host creation date
#[serde(rename = "crDate")] #[serde(rename = "crDate")]
pub created_at: StringValue<'static>, pub created_at: DateTime<Utc>,
} }
/// Type that represents the &lt;resData&gt; tag for host check response /// Type that represents the &lt;resData&gt; tag for host check response
@ -72,6 +74,8 @@ pub struct HostCreateResponse {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use chrono::{TimeZone, Utc};
use super::{HostCreate, IpAddr}; use super::{HostCreate, IpAddr};
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
@ -109,7 +113,7 @@ mod tests {
assert_eq!(result.create_data.name, "host2.eppdev-1.com".into()); assert_eq!(result.create_data.name, "host2.eppdev-1.com".into());
assert_eq!( assert_eq!(
result.create_data.created_at, result.create_data.created_at,
"2021-07-26T05:28:55.0Z".into() Utc.ymd(2021, 7, 26).and_hms(5, 28, 55)
); );
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -3,10 +3,12 @@
use std::net::IpAddr; use std::net::IpAddr;
use std::str::FromStr; use std::str::FromStr;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::XMLNS; use super::XMLNS;
use crate::common::{HostAddr, NoExtension, ObjectStatus, StringValue}; use crate::common::{HostAddr, NoExtension, ObjectStatus, StringValue};
use crate::request::{Command, Transaction}; use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize};
impl<'a> Transaction<NoExtension> for HostInfo<'a> {} impl<'a> Transaction<NoExtension> for HostInfo<'a> {}
@ -70,16 +72,16 @@ pub struct HostInfoResponseData {
pub creator_id: StringValue<'static>, pub creator_id: StringValue<'static>,
/// The host creation date /// The host creation date
#[serde(rename = "crDate")] #[serde(rename = "crDate")]
pub created_at: StringValue<'static>, pub created_at: DateTime<Utc>,
/// The epp user that last updated the host /// The epp user that last updated the host
#[serde(rename = "upID")] #[serde(rename = "upID")]
pub updater_id: Option<StringValue<'static>>, pub updater_id: Option<StringValue<'static>>,
/// The host last update date /// The host last update date
#[serde(rename = "upDate")] #[serde(rename = "upDate")]
pub updated_at: Option<StringValue<'static>>, pub updated_at: Option<DateTime<Utc>>,
/// The host transfer date /// The host transfer date
#[serde(rename = "trDate")] #[serde(rename = "trDate")]
pub transferred_at: Option<StringValue<'static>>, pub transferred_at: Option<DateTime<Utc>>,
} }
fn deserialize_host_addrs<'de, D>(de: D) -> Result<Vec<IpAddr>, D::Error> fn deserialize_host_addrs<'de, D>(de: D) -> Result<Vec<IpAddr>, D::Error>
@ -104,6 +106,8 @@ pub struct HostInfoResponse {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use chrono::{TimeZone, Utc};
use super::{HostInfo, IpAddr}; use super::{HostInfo, IpAddr};
use crate::common::NoExtension; use crate::common::NoExtension;
use crate::request::Transaction; use crate::request::Transaction;
@ -146,14 +150,17 @@ mod tests {
); );
assert_eq!(result.info_data.client_id, "eppdev".into()); assert_eq!(result.info_data.client_id, "eppdev".into());
assert_eq!(result.info_data.creator_id, "creator".into()); assert_eq!(result.info_data.creator_id, "creator".into());
assert_eq!(result.info_data.created_at, "2021-07-26T05:28:55.0Z".into()); assert_eq!(
result.info_data.created_at,
Utc.ymd(2021, 7, 26).and_hms(5, 28, 55)
);
assert_eq!( assert_eq!(
*(result.info_data.updater_id.as_ref().unwrap()), *(result.info_data.updater_id.as_ref().unwrap()),
"creator".into() "creator".into()
); );
assert_eq!( assert_eq!(
*(result.info_data.updated_at.as_ref().unwrap()), result.info_data.updated_at,
"2021-07-26T05:28:55.0Z".into() Some(Utc.ymd(2021, 7, 26).and_hms(5, 28, 55))
); );
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());

View File

@ -55,6 +55,8 @@ mod tests {
use crate::request::Transaction; use crate::request::Transaction;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{get_xml, CLTRID, SVTRID}; use crate::tests::{get_xml, CLTRID, SVTRID};
use chrono::{TimeZone, Utc};
use std::net::IpAddr; use std::net::IpAddr;
#[test] #[test]
@ -86,10 +88,7 @@ mod tests {
); );
assert_eq!(msg.count, 5); assert_eq!(msg.count, 5);
assert_eq!(msg.id, "12345".to_string()); assert_eq!(msg.id, "12345".to_string());
assert_eq!( assert_eq!(msg.date, Some(Utc.ymd(2021, 7, 23).and_hms(19, 12, 43)));
*(msg.date.as_ref().unwrap()),
"2021-07-23T19:12:43.0Z".into()
);
assert_eq!( assert_eq!(
*(msg.message.as_ref().unwrap()), *(msg.message.as_ref().unwrap()),
"Transfer requested.".into() "Transfer requested.".into()
@ -99,12 +98,12 @@ mod tests {
assert_eq!(tr.name, "eppdev-transfer.com".into()); assert_eq!(tr.name, "eppdev-transfer.com".into());
assert_eq!(tr.transfer_status, "pending".into()); assert_eq!(tr.transfer_status, "pending".into());
assert_eq!(tr.requester_id, "eppdev".into()); assert_eq!(tr.requester_id, "eppdev".into());
assert_eq!(tr.requested_at, "2021-07-23T15:31:21.0Z".into()); assert_eq!(tr.requested_at, Utc.ymd(2021, 7, 23).and_hms(15, 31, 21));
assert_eq!(tr.ack_id, "ClientY".into()); assert_eq!(tr.ack_id, "ClientY".into());
assert_eq!(tr.ack_by, "2021-07-28T15:31:21.0Z".into()); assert_eq!(tr.ack_by, Utc.ymd(2021, 7, 28).and_hms(15, 31, 21));
assert_eq!( assert_eq!(
*tr.expiring_at.as_ref().unwrap(), tr.expiring_at,
"2022-07-02T14:53:19.0Z".into() Some(Utc.ymd(2022, 7, 2).and_hms(14, 53, 19))
); );
} else { } else {
panic!("Wrong type"); panic!("Wrong type");
@ -132,7 +131,7 @@ mod tests {
); );
assert_eq!(msg.count, 4); assert_eq!(msg.count, 4);
assert_eq!(msg.id, "12345".to_string()); assert_eq!(msg.id, "12345".to_string());
assert_eq!(*(msg.date.as_ref().unwrap()), "2022-01-02T11:30:45Z".into()); assert_eq!(msg.date, Some(Utc.ymd(2022, 1, 2).and_hms(11, 30, 45)));
assert_eq!( assert_eq!(
*(msg.message.as_ref().unwrap()), *(msg.message.as_ref().unwrap()),
"Unused objects policy".into() "Unused objects policy".into()
@ -149,9 +148,12 @@ mod tests {
.any(|a| a == &IpAddr::from([1, 1, 1, 1]))); .any(|a| a == &IpAddr::from([1, 1, 1, 1])));
assert_eq!(host.client_id, "1234".into()); assert_eq!(host.client_id, "1234".into());
assert_eq!(host.creator_id, "user".into()); assert_eq!(host.creator_id, "user".into());
assert_eq!(host.created_at, "2021-12-01T22:40:48Z".into()); assert_eq!(host.created_at, Utc.ymd(2021, 12, 1).and_hms(22, 40, 48));
assert_eq!(host.updater_id, Some("user".into())); assert_eq!(host.updater_id, Some("user".into()));
assert_eq!(host.updated_at, Some("2021-12-01T22:40:48Z".into())); assert_eq!(
host.updated_at,
Some(Utc.ymd(2021, 12, 1).and_hms(22, 40, 48))
);
} else { } else {
panic!("Wrong type"); panic!("Wrong type");
} }
@ -178,10 +180,7 @@ mod tests {
assert_eq!(msg.count, 4); assert_eq!(msg.count, 4);
assert_eq!(msg.id, "12346".to_string()); assert_eq!(msg.id, "12346".to_string());
assert_eq!( assert_eq!(msg.date, Some(Utc.ymd(2000, 6, 8).and_hms(22, 10, 0)));
*(msg.date.as_ref().unwrap()),
"2000-06-08T22:10:00.0Z".into()
);
assert_eq!( assert_eq!(
*(msg.message.as_ref().unwrap()), *(msg.message.as_ref().unwrap()),
"Credit balance low.".into() "Credit balance low.".into()

View File

@ -1,8 +1,10 @@
//! Types for EPP responses //! Types for EPP responses
use serde::{de::DeserializeOwned, Deserialize};
use std::fmt::{self, Debug}; use std::fmt::{self, Debug};
use chrono::{DateTime, Utc};
use serde::{de::DeserializeOwned, Deserialize};
use crate::common::StringValue; use crate::common::StringValue;
use crate::xml::EppXml; use crate::xml::EppXml;
@ -184,7 +186,7 @@ pub struct MessageQueue {
pub id: String, pub id: String,
/// The message date /// The message date
#[serde(rename = "qDate")] #[serde(rename = "qDate")]
pub date: Option<StringValue<'static>>, pub date: Option<DateTime<Utc>>,
/// The message text /// The message text
#[serde(rename = "msg")] #[serde(rename = "msg")]
pub message: Option<StringValue<'static>>, pub message: Option<StringValue<'static>>,