Merge poll and ack modules

This commit is contained in:
Dirkjan Ochtman 2023-03-02 15:25:51 +01:00
parent f2194c818c
commit 10eedb6045
2 changed files with 51 additions and 7 deletions

View File

@ -63,11 +63,8 @@ pub mod extensions {
} }
pub mod message { pub mod message {
pub mod ack;
pub use ack::MessageAck;
pub mod poll; pub mod poll;
pub use poll::MessagePoll; pub use poll::{MessagePoll, MessageAck};
} }
pub use client::EppClient; pub use client::EppClient;

View File

@ -45,18 +45,65 @@ pub enum MessagePollResponse {
LowBalance(LowBalance), LowBalance(LowBalance),
} }
impl<'a> Transaction<NoExtension> for MessageAck<'a> {}
impl<'a> Command for MessageAck<'a> {
type Response = String;
const COMMAND: &'static str = "poll";
}
#[derive(Debug, ToXml)]
/// Type for EPP XML `<poll>` command for message ack
#[xml(rename = "poll", ns(EPP_XMLNS))]
pub struct MessageAck<'a> {
/// The type of operation to perform
/// The value is "ack" for message acknowledgement
#[xml(attribute)]
op: &'a str,
/// The ID of the message to be acknowledged
#[xml(rename = "msgID", attribute)]
message_id: &'a str,
}
impl<'a> MessageAck<'a> {
pub fn new(message_id: &'a str) -> Self {
Self {
op: "ack",
message_id,
}
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{MessagePoll, MessagePollResponse}; use super::{MessageAck, MessagePoll, MessagePollResponse};
use crate::host::Status; use crate::host::Status;
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{assert_serialized, response_from_file, CLTRID, SVTRID}; use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
use chrono::{TimeZone, Utc}; use chrono::{TimeZone, Utc};
use std::net::IpAddr; use std::net::IpAddr;
#[test] #[test]
fn command() { fn ack_command() {
let object = MessageAck::new("12345");
assert_serialized("request/message/ack.xml", &object);
}
#[test]
fn response() {
let object = response_from_file::<MessageAck>("response/message/ack.xml");
let msg = object.message_queue().unwrap();
assert_eq!(object.result.code, ResultCode::CommandCompletedSuccessfully);
assert_eq!(object.result.message, SUCCESS_MSG);
assert_eq!(msg.count, 4);
assert_eq!(msg.id, "12345".to_string());
assert_eq!(object.tr_ids.server_tr_id, SVTRID);
}
#[test]
fn poll_command() {
let object = MessagePoll::default(); let object = MessagePoll::default();
assert_serialized("request/message/poll.xml", &object); assert_serialized("request/message/poll.xml", &object);
} }