use std::fmt::Debug;
use super::XMLNS;
use crate::common::{CheckResponse, NoExtension, StringValue};
use crate::request::{Command, Transaction};
use serde::Serialize;
impl<'a> Transaction<NoExtension> for ContactCheck<'a> {}
impl<'a> Command for ContactCheck<'a> {
type Response = CheckResponse;
const COMMAND: &'static str = "check";
}
#[derive(Serialize, Debug)]
struct ContactList<'a> {
#[serde(rename = "xmlns:contact")]
xmlns: &'a str,
#[serde(rename = "contact:id")]
contact_ids: Vec<StringValue<'a>>,
}
#[derive(Serialize, Debug)]
struct SerializeContactCheck<'a> {
#[serde(rename = "contact:check")]
list: ContactList<'a>,
}
impl<'a> From<ContactCheck<'a>> for SerializeContactCheck<'a> {
fn from(check: ContactCheck<'a>) -> Self {
Self {
list: ContactList {
xmlns: XMLNS,
contact_ids: check.contact_ids.iter().map(|&id| id.into()).collect(),
},
}
}
}
#[derive(Clone, Debug, Serialize)]
#[serde(into = "SerializeContactCheck")]
pub struct ContactCheck<'a> {
pub contact_ids: &'a [&'a str],
}
#[cfg(test)]
mod tests {
use super::ContactCheck;
use crate::response::ResultCode;
use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
#[test]
fn command() {
let object = ContactCheck {
contact_ids: &["eppdev-contact-1", "eppdev-contact-2"],
};
assert_serialized("request/contact/check.xml", &object);
}
#[test]
fn response() {
let object = response_from_file::<ContactCheck>("response/contact/check.xml");
let results = object.res_data().unwrap();
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG.into());
assert_eq!(results.list[0].id, "eppdev-contact-1");
assert!(!results.list[0].available);
assert_eq!(results.list[1].id, "eppdev-contact-2");
assert!(results.list[1].available);
assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into());
assert_eq!(object.tr_ids.server_tr_id, SVTRID.into());
}
}