instant_epp/domain/
renew.rs1use chrono::{DateTime, NaiveDate, Utc};
4use instant_xml::{FromXml, ToXml};
5
6use super::{Period, XMLNS};
7use crate::common::{NoExtension, EPP_XMLNS};
8use crate::request::{Command, Transaction};
9
10impl Transaction<NoExtension> for DomainRenew<'_> {}
11
12impl Command for DomainRenew<'_> {
13 type Response = RenewData;
14 const COMMAND: &'static str = "renew";
15}
16
17impl<'a> DomainRenew<'a> {
18 pub fn new(name: &'a str, current_expiry_date: NaiveDate, period: Period) -> Self {
19 Self {
20 domain: DomainRenewRequestData {
21 name,
22 current_expiry_date,
23 period,
24 },
25 }
26 }
27}
28
29#[derive(Debug, ToXml)]
33#[xml(rename = "renew", ns(XMLNS))]
34pub struct DomainRenewRequestData<'a> {
35 name: &'a str,
37 #[xml(rename = "curExpDate")]
39 current_expiry_date: NaiveDate,
40 period: Period,
42}
43
44#[derive(Debug, ToXml)]
45#[xml(rename = "renew", ns(EPP_XMLNS))]
47pub struct DomainRenew<'a> {
48 #[xml(rename = "renew")]
50 domain: DomainRenewRequestData<'a>,
51}
52
53#[derive(Debug, FromXml)]
57#[xml(rename = "renData", ns(XMLNS))]
58pub struct RenewData {
59 pub name: String,
61 #[xml(rename = "exDate")]
63 pub expiring_at: Option<DateTime<Utc>>,
64}
65
66#[cfg(test)]
67mod tests {
68 use super::{DomainRenew, Period};
69 use crate::domain::PeriodLength;
70 use crate::response::ResultCode;
71 use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
72
73 use chrono::{NaiveDate, TimeZone, Utc};
74
75 #[test]
76 fn command() {
77 let exp_date = NaiveDate::from_ymd_opt(2022, 7, 23).unwrap();
78 let object = DomainRenew::new(
79 "eppdev.com",
80 exp_date,
81 Period::Years(PeriodLength::new(1).unwrap()),
82 );
83 assert_serialized("request/domain/renew.xml", &object);
84 }
85
86 #[test]
87 fn response() {
88 let object = response_from_file::<DomainRenew>("response/domain/renew.xml");
89
90 let result = object.res_data().unwrap();
91
92 assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
93 assert_eq!(object.result.message, SUCCESS_MSG);
94 assert_eq!(result.name, "eppdev-1.com");
95 assert_eq!(
96 *result.expiring_at.as_ref().unwrap(),
97 Utc.with_ymd_and_hms(2024, 7, 23, 15, 31, 20).unwrap()
98 );
99 assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID);
100 assert_eq!(object.tr_ids.server_tr_id, SVTRID);
101 }
102}