1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Types for EPP host delete request

use instant_xml::ToXml;

use super::XMLNS;
use crate::common::{NoExtension, EPP_XMLNS};
use crate::request::{Command, Transaction};

impl<'a> Transaction<NoExtension> for HostDelete<'a> {}

impl<'a> Command for HostDelete<'a> {
    type Response = ();
    const COMMAND: &'static str = "delete";
}

impl<'a> HostDelete<'a> {
    pub fn new(name: &'a str) -> Self {
        Self {
            host: HostDeleteRequest { name },
        }
    }
}

/// Type for data under the host `<delete>` tag
#[derive(Debug, ToXml)]
#[xml(rename = "delete", ns(XMLNS))]
pub struct HostDeleteRequest<'a> {
    /// The host to be deleted
    name: &'a str,
}

/// Type for EPP XML `<delete>` command for hosts
#[derive(Debug, ToXml)]
#[xml(rename = "delete", ns(EPP_XMLNS))]
pub struct HostDelete<'a> {
    /// The instance holding the data for the host to be deleted
    host: HostDeleteRequest<'a>,
}

#[cfg(test)]
mod tests {
    use super::HostDelete;
    use crate::response::ResultCode;
    use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};

    #[test]
    fn command() {
        let object = HostDelete::new("ns1.eppdev-1.com");
        assert_serialized("request/host/delete.xml", &object);
    }

    #[test]
    fn response() {
        let object = response_from_file::<HostDelete>("response/host/delete.xml");
        assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
        assert_eq!(object.result.message, SUCCESS_MSG);
        assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID);
        assert_eq!(object.tr_ids.server_tr_id, SVTRID);
    }
}