instant_epp/extensions/
low_balance.rs1use instant_xml::FromXml;
6
7#[derive(Clone, Debug, FromXml, PartialEq)]
8#[xml(ns(XMLNS), rename = "pollData", rename_all = "camelCase")]
9pub struct LowBalance {
10 pub registrar_name: String,
11 pub credit_limit: String,
12 pub credit_threshold: Threshold,
13 pub available_credit: String,
14}
15
16#[derive(Clone, Debug, FromXml, PartialEq)]
17#[xml(ns(XMLNS), rename = "creditThreshold")]
18pub struct Threshold {
19 #[xml(attribute)]
20 pub r#type: ThresholdType,
21 #[xml(direct)]
22 pub value: String,
23}
24
25#[derive(Clone, Copy, Debug, FromXml, PartialEq)]
26#[xml(scalar, rename_all = "SCREAMING_SNAKE_CASE")]
27pub enum ThresholdType {
28 Fixed,
29 Percent,
30}
31
32const XMLNS: &str = "http://www.verisign.com/epp/lowbalance-poll-1.0";
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37 use crate::poll::{Poll, PollData};
38 use crate::response::ResultCode;
39 use crate::tests::{response_from_file, CLTRID, SVTRID};
40
41 #[test]
42 fn low_balance() {
43 let object = response_from_file::<Poll>("response/poll/poll_low_balance.xml");
44 dbg!(&object);
45
46 let low_balance = match object.res_data() {
47 Some(PollData::LowBalance(low_balance)) => low_balance,
48 _ => panic!("Unexpected message data"),
49 };
50
51 assert_eq!(low_balance.registrar_name, "Foobar, Inc.");
52 assert_eq!(low_balance.credit_limit, "0");
53 assert_eq!(
54 low_balance.credit_threshold,
55 Threshold {
56 r#type: ThresholdType::Fixed,
57 value: "500".into(),
58 }
59 );
60 assert_eq!(low_balance.available_credit, "491.31");
61
62 assert_eq!(
63 object.result.code,
64 ResultCode::CommandCompletedSuccessfullyAckToDequeue
65 );
66 assert_eq!(
67 object.result.message,
68 "Command completed successfully; ack to dequeue"
69 );
70
71 assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID);
72 assert_eq!(object.tr_ids.server_tr_id, SVTRID);
73 }
74}