From 569bd86baefbafe8384af357b95d13322ea152aa Mon Sep 17 00:00:00 2001 From: Nicholas Rempel Date: Wed, 5 Jan 2022 12:31:50 -0800 Subject: [PATCH] Add HostInfoResponseData to list of support message poll response types --- src/message/poll.rs | 70 +++++++++++++++---- .../{poll.xml => poll_domain_transfer.xml} | 0 .../response/message/poll_host_info.xml | 38 ++++++++++ 3 files changed, 96 insertions(+), 12 deletions(-) rename tests/resources/response/message/{poll.xml => poll_domain_transfer.xml} (100%) create mode 100644 tests/resources/response/message/poll_host_info.xml diff --git a/src/message/poll.rs b/src/message/poll.rs index 29096d8..018b959 100644 --- a/src/message/poll.rs +++ b/src/message/poll.rs @@ -1,5 +1,6 @@ use crate::common::NoExtension; use crate::domain::transfer::DomainTransferResponseData; +use crate::host::info::HostInfoResponseData; use crate::request::{Command, Transaction}; use serde::{Deserialize, Serialize}; @@ -34,13 +35,16 @@ pub enum MessageData { /// Data under the <domain:trnData> tag #[serde(rename = "domain:trnData")] DomainTransfer(DomainTransferResponseData), + /// Data under the <host:infData> tag + #[serde(rename = "host:infData")] + HostInfo(HostInfoResponseData), } /// Type that represents the <resData> tag for message poll response #[derive(Deserialize, Debug)] pub struct MessagePollResponse { /// Data under the <trnData> tag - #[serde(alias = "trnData")] + #[serde(alias = "trnData", alias = "infData")] pub message_data: MessageData, } @@ -63,8 +67,8 @@ mod tests { } #[test] - fn response() { - let xml = get_xml("response/message/poll.xml").unwrap(); + fn domain_transfer_response() { + let xml = get_xml("response/message/poll_domain_transfer.xml").unwrap(); let object = MessagePoll::deserialize_response(xml.as_str()).unwrap(); let result = object.res_data().unwrap(); @@ -86,18 +90,60 @@ mod tests { "Transfer requested.".into() ); - let MessageData::DomainTransfer(data) = &result.message_data; + if let MessageData::DomainTransfer(tr) = &result.message_data { + assert_eq!(tr.name, "eppdev-transfer.com".into()); + assert_eq!(tr.transfer_status, "pending".into()); + assert_eq!(tr.requester_id, "eppdev".into()); + assert_eq!(tr.requested_at, "2021-07-23T15:31:21.0Z".into()); + assert_eq!(tr.ack_id, "ClientY".into()); + assert_eq!(tr.ack_by, "2021-07-28T15:31:21.0Z".into()); + assert_eq!( + *tr.expiring_at.as_ref().unwrap(), + "2022-07-02T14:53:19.0Z".into() + ); + } else { + panic!("Wrong type"); + } - assert_eq!(data.name, "eppdev-transfer.com".into()); - assert_eq!(data.transfer_status, "pending".into()); - assert_eq!(data.requester_id, "eppdev".into()); - assert_eq!(data.requested_at, "2021-07-23T15:31:21.0Z".into()); - assert_eq!(data.ack_id, "ClientY".into()); - assert_eq!(data.ack_by, "2021-07-28T15:31:21.0Z".into()); + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } + + #[test] + fn host_info_response() { + let xml = get_xml("response/message/poll_host_info.xml").unwrap(); + let object = MessagePoll::deserialize_response(xml.as_str()).unwrap(); + + let result = object.res_data().unwrap(); + let msg = object.message_queue().unwrap(); + + assert_eq!(object.result.code, 1301); assert_eq!( - *data.expiring_at.as_ref().unwrap(), - "2022-07-02T14:53:19.0Z".into() + object.result.message, + "Command completed successfully; ack to dequeue".into() ); + assert_eq!(msg.count, 4); + assert_eq!(msg.id, "12345".to_string()); + assert_eq!(*(msg.date.as_ref().unwrap()), "2022-01-02T11:30:45Z".into()); + assert_eq!( + *(msg.message.as_ref().unwrap()), + "Unused objects policy".into() + ); + + if let MessageData::HostInfo(host) = &result.message_data { + assert_eq!(host.name, "ns.test.com".into()); + + assert_eq!(host.roid, "1234".into()); + assert!(host.statuses.iter().any(|s| s.status == "ok")); + assert!(host.addresses.iter().any(|a| a.address == *"1.1.1.1")); + assert_eq!(host.client_id, "1234".into()); + assert_eq!(host.creator_id, "user".into()); + assert_eq!(host.created_at, "2021-12-01T22:40:48Z".into()); + assert_eq!(host.updater_id, Some("user".into())); + assert_eq!(host.updated_at, Some("2021-12-01T22:40:48Z".into())); + } else { + panic!("Wrong type"); + } assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); diff --git a/tests/resources/response/message/poll.xml b/tests/resources/response/message/poll_domain_transfer.xml similarity index 100% rename from tests/resources/response/message/poll.xml rename to tests/resources/response/message/poll_domain_transfer.xml diff --git a/tests/resources/response/message/poll_host_info.xml b/tests/resources/response/message/poll_host_info.xml new file mode 100644 index 0000000..37bd2f9 --- /dev/null +++ b/tests/resources/response/message/poll_host_info.xml @@ -0,0 +1,38 @@ + + + + + Command completed successfully; ack to dequeue + + + 2022-01-02T11:30:45Z + Unused objects policy + + + + ns.test.com + 1234 + + 1.1.1.1 + 1234 + user + 2021-12-01T22:40:48Z + user + 2021-12-01T22:40:48Z + + + + + delete + 2022-01-02T11:30:45Z + 1234 + regy_batch + Unused objects policy + + + + cltrid:1626454866 + RO-6879-1627224678242975 + + + \ No newline at end of file