Skip to main content

epp_client/contact/
check.rs

1use std::fmt::Debug;
2
3/// Types for EPP contact check request
4use super::XMLNS;
5use crate::common::{CheckResponse, NoExtension, StringValue};
6use crate::request::{Command, Transaction};
7use serde::Serialize;
8
9impl<'a> Transaction<NoExtension> for ContactCheck<'a> {}
10
11impl<'a> Command for ContactCheck<'a> {
12    type Response = CheckResponse;
13    const COMMAND: &'static str = "check";
14}
15
16// Request
17
18/// Type that represents the &lt;check&gt; command for contact transactions
19#[derive(Serialize, Debug)]
20struct ContactList<'a> {
21    /// The XML namespace for the contact &lt;check&gt;
22    #[serde(rename = "xmlns:contact")]
23    xmlns: &'a str,
24    /// The list of contact ids to check for availability
25    #[serde(rename = "contact:id")]
26    contact_ids: Vec<StringValue<'a>>,
27}
28
29#[derive(Serialize, Debug)]
30struct SerializeContactCheck<'a> {
31    /// The &lt;check&gt; tag for the contact check command
32    #[serde(rename = "contact:check")]
33    list: ContactList<'a>,
34}
35
36impl<'a> From<ContactCheck<'a>> for SerializeContactCheck<'a> {
37    fn from(check: ContactCheck<'a>) -> Self {
38        Self {
39            list: ContactList {
40                xmlns: XMLNS,
41                contact_ids: check.contact_ids.iter().map(|&id| id.into()).collect(),
42            },
43        }
44    }
45}
46
47/// The EPP `check` command for contacts
48#[derive(Clone, Debug, Serialize)]
49#[serde(into = "SerializeContactCheck")]
50pub struct ContactCheck<'a> {
51    /// The list of contact IDs to be checked
52    pub contact_ids: &'a [&'a str],
53}
54
55#[cfg(test)]
56mod tests {
57    use super::ContactCheck;
58    use crate::response::ResultCode;
59    use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
60
61    #[test]
62    fn command() {
63        let object = ContactCheck {
64            contact_ids: &["eppdev-contact-1", "eppdev-contact-2"],
65        };
66        assert_serialized("request/contact/check.xml", &object);
67    }
68
69    #[test]
70    fn response() {
71        let object = response_from_file::<ContactCheck>("response/contact/check.xml");
72        let results = object.res_data().unwrap();
73
74        assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
75        assert_eq!(object.result.message, SUCCESS_MSG.into());
76        assert_eq!(results.list[0].id, "eppdev-contact-1");
77        assert!(!results.list[0].available);
78        assert_eq!(results.list[1].id, "eppdev-contact-2");
79        assert!(results.list[1].available);
80        assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
81        assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
82    }
83}