use instant_xml::ToXml;
use super::{DomainAuthInfo, DomainContact, NameServers, Status, XMLNS};
use crate::{
common::{NoExtension, EPP_XMLNS},
request::{Command, Transaction},
};
impl<'a> Transaction<NoExtension> for DomainUpdate<'a> {}
impl<'a> Command for DomainUpdate<'a> {
type Response = ();
const COMMAND: &'static str = "update";
}
impl<'a> DomainUpdate<'a> {
pub fn new(name: &'a str) -> Self {
Self {
domain: DomainUpdateRequestData {
name,
add: None,
remove: None,
change_info: None,
},
}
}
pub fn info(&mut self, info: DomainChangeInfo<'a>) {
self.domain.change_info = Some(info);
}
pub fn add(&mut self, add: DomainAdd<'a>) {
self.domain.add = Some(add);
}
pub fn remove(&mut self, remove: DomainRemove<'a>) {
self.domain.remove = Some(remove);
}
}
#[derive(Debug, ToXml)]
#[xml(rename = "chg", ns(XMLNS))]
pub struct DomainChangeInfo<'a> {
pub registrant: Option<&'a str>,
pub auth_info: Option<DomainAuthInfo<'a>>,
}
#[derive(Debug, ToXml)]
#[xml(rename = "add", ns(XMLNS))]
pub struct DomainAdd<'a> {
pub ns: Option<NameServers<'a>>,
pub contacts: Option<&'a [DomainContact<'a>]>,
pub statuses: Option<&'a [Status]>,
}
#[derive(Debug, ToXml)]
#[xml(rename = "rem", ns(XMLNS))]
pub struct DomainRemove<'a> {
pub ns: Option<NameServers<'a>>,
pub contacts: Option<&'a [DomainContact<'a>]>,
pub statuses: Option<&'a [Status]>,
}
#[derive(Debug, ToXml)]
#[xml(rename = "update", ns(XMLNS))]
pub struct DomainUpdateRequestData<'a> {
pub name: &'a str,
pub add: Option<DomainAdd<'a>>,
pub remove: Option<DomainRemove<'a>>,
#[xml(rename = "domain:chg")]
pub change_info: Option<DomainChangeInfo<'a>>,
}
#[derive(Debug, ToXml)]
#[xml(rename = "update", ns(EPP_XMLNS))]
pub struct DomainUpdate<'a> {
pub domain: DomainUpdateRequestData<'a>,
}
#[cfg(test)]
mod tests {
use super::{
DomainAdd, DomainAuthInfo, DomainChangeInfo, DomainContact, DomainRemove, DomainUpdate,
};
use crate::domain::Status;
use crate::response::ResultCode;
use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let mut object = DomainUpdate::new("eppdev.com");
let add = DomainAdd {
ns: None,
contacts: None,
statuses: Some(&[Status::ClientDeleteProhibited]),
};
let contacts = &[DomainContact {
contact_type: "billing".into(),
id: "eppdev-contact-2".into(),
}];
let remove = DomainRemove {
ns: None,
contacts: Some(contacts),
statuses: None,
};
let change_info = DomainChangeInfo {
registrant: None,
auth_info: Some(DomainAuthInfo::new("epP5uthd#v")),
};
object.add(add);
object.remove(remove);
object.info(change_info);
assert_serialized("request/domain/update.xml", &object);
}
#[test]
fn response() {
let object = response_from_file::<DomainUpdate>("response/domain/update.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);
}
}