Skip to main content

epp_client/contact/
delete.rs

1//! Types for EPP contact delete request
2
3use super::XMLNS;
4use crate::common::{NoExtension, StringValue};
5use crate::request::{Command, Transaction};
6use serde::Serialize;
7
8impl<'a> Transaction<NoExtension> for ContactDelete<'a> {}
9
10impl<'a> Command for ContactDelete<'a> {
11    type Response = ();
12    const COMMAND: &'static str = "delete";
13}
14
15/// Type containing the data for the &lt;delete&gt; tag for contacts
16#[derive(Serialize, Debug)]
17pub struct ContactDeleteRequestData<'a> {
18    /// XML namespace for the &lt;delete&gt; command for contacts
19    #[serde(rename = "xmlns:contact")]
20    xmlns: &'a str,
21    /// The id of the contact to be deleted
22    #[serde(rename = "contact:id")]
23    id: StringValue<'a>,
24}
25
26#[derive(Serialize, Debug)]
27/// The &lt;delete&gt; type for the contact delete EPP command
28pub struct ContactDelete<'a> {
29    #[serde(rename = "contact:delete")]
30    /// The data for the &lt;delete&gt; tag for a contact delete command
31    contact: ContactDeleteRequestData<'a>,
32}
33
34impl<'a> ContactDelete<'a> {
35    pub fn new(id: &'a str) -> Self {
36        Self {
37            contact: ContactDeleteRequestData {
38                xmlns: XMLNS,
39                id: id.into(),
40            },
41        }
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::ContactDelete;
48    use crate::response::ResultCode;
49    use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
50
51    #[test]
52    fn command() {
53        let object = ContactDelete::new("eppdev-contact-3");
54        assert_serialized("request/contact/delete.xml", &object);
55    }
56
57    #[test]
58    fn response() {
59        let object = response_from_file::<ContactDelete>("response/contact/delete.xml");
60        assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
61        assert_eq!(object.result.message, SUCCESS_MSG.into());
62        assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
63        assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
64    }
65}