feat!: add `InfoType` enum for PostalInfo.info_type

This commit is contained in:
gibbz00 2024-10-18 17:37:33 +02:00 committed by Dirkjan Ochtman
parent 0048a81b54
commit 8158a80633
5 changed files with 31 additions and 16 deletions

View File

@ -86,7 +86,7 @@ mod tests {
use chrono::{TimeZone, Utc}; use chrono::{TimeZone, Utc};
use super::{ContactCreate, Fax, PostalInfo, Voice}; use super::{ContactCreate, Fax, PostalInfo, Voice};
use crate::contact::Address; use crate::contact::{Address, InfoType};
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
@ -100,7 +100,12 @@ mod tests {
Some("392374"), Some("392374"),
"FR".parse().unwrap(), "FR".parse().unwrap(),
); );
let postal_info = PostalInfo::new("int", "John Doe", Some("Acme Widgets"), address); let postal_info = PostalInfo::new(
InfoType::International,
"John Doe",
Some("Acme Widgets"),
address,
);
let mut voice = Voice::new("+33.47237942"); let mut voice = Voice::new("+33.47237942");
voice.set_extension("123"); voice.set_extension("123");
let mut fax = Fax::new("+33.86698799"); let mut fax = Fax::new("+33.86698799");
@ -121,7 +126,7 @@ mod tests {
#[test] #[test]
fn command_minimal() { fn command_minimal() {
let address = Address::new(&[], "Paris", None, None, "FR".parse().unwrap()); let address = Address::new(&[], "Paris", None, None, "FR".parse().unwrap());
let postal_info = PostalInfo::new("int", "John Doe", None, address); let postal_info = PostalInfo::new(InfoType::International, "John Doe", None, address);
let object = ContactCreate::new( let object = ContactCreate::new(
"eppdev-contact-3", "eppdev-contact-3",
"contact@eppdev.net", "contact@eppdev.net",

View File

@ -93,7 +93,7 @@ mod tests {
use chrono::{TimeZone, Utc}; use chrono::{TimeZone, Utc};
use super::ContactInfo; use super::ContactInfo;
use crate::contact::Status; use crate::contact::{InfoType, Status};
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
@ -118,7 +118,7 @@ mod tests {
assert_eq!(result.id, "eppdev-contact-3"); assert_eq!(result.id, "eppdev-contact-3");
assert_eq!(result.roid, "UNDEF-ROID"); assert_eq!(result.roid, "UNDEF-ROID");
assert_eq!(result.statuses[0], Status::Ok); assert_eq!(result.statuses[0], Status::Ok);
assert_eq!(result.postal_info.info_type, "loc"); assert_eq!(result.postal_info.info_type, InfoType::Local);
assert_eq!(result.postal_info.name, "John Doe"); assert_eq!(result.postal_info.name, "John Doe");
assert_eq!(result.postal_info.organization, Some("Acme Widgets".into())); assert_eq!(result.postal_info.organization, Some("Acme Widgets".into()));
assert_eq!(result.postal_info.address.street[0], "58"); assert_eq!(result.postal_info.address.street[0], "58");
@ -165,7 +165,7 @@ mod tests {
assert_eq!(result.id, "eppdev-contact-3"); assert_eq!(result.id, "eppdev-contact-3");
assert_eq!(result.roid, "UNDEF-ROID"); assert_eq!(result.roid, "UNDEF-ROID");
assert_eq!(result.statuses[0], Status::Ok); assert_eq!(result.statuses[0], Status::Ok);
assert_eq!(result.postal_info.info_type, "loc"); assert_eq!(result.postal_info.info_type, InfoType::Local);
assert_eq!(result.postal_info.name, "John Doe"); assert_eq!(result.postal_info.name, "John Doe");
assert_eq!(result.postal_info.organization, None); assert_eq!(result.postal_info.organization, None);
assert_eq!(result.postal_info.address.street[0], "58"); assert_eq!(result.postal_info.address.street[0], "58");

View File

@ -192,7 +192,7 @@ impl<'a> Address<'a> {
pub struct PostalInfo<'a> { pub struct PostalInfo<'a> {
/// The 'type' attr on `<postalInfo>` /// The 'type' attr on `<postalInfo>`
#[xml(rename = "type", attribute)] #[xml(rename = "type", attribute)]
pub info_type: Cow<'a, str>, pub info_type: InfoType,
/// The `<name>` tag under `<postalInfo>` /// The `<name>` tag under `<postalInfo>`
pub name: Cow<'a, str>, pub name: Cow<'a, str>,
/// The `<org>` tag under `<postalInfo>` /// The `<org>` tag under `<postalInfo>`
@ -205,13 +205,13 @@ pub struct PostalInfo<'a> {
impl<'a> PostalInfo<'a> { impl<'a> PostalInfo<'a> {
/// Creates a new PostalInfo instance /// Creates a new PostalInfo instance
pub fn new( pub fn new(
info_type: &'a str, info_type: InfoType,
name: &'a str, name: &'a str,
organization: Option<&'a str>, organization: Option<&'a str>,
address: Address<'a>, address: Address<'a>,
) -> Self { ) -> Self {
Self { Self {
info_type: info_type.into(), info_type,
name: name.into(), name: name.into(),
organization: organization.map(|org| org.into()), organization: organization.map(|org| org.into()),
address, address,
@ -219,6 +219,15 @@ impl<'a> PostalInfo<'a> {
} }
} }
#[derive(Debug, Clone, Copy, PartialEq, ToXml, FromXml)]
#[xml(scalar)]
pub enum InfoType {
#[xml(rename = "loc")]
Local,
#[xml(rename = "int")]
International,
}
/// The `<status>` type on contact transactions /// The `<status>` type on contact transactions
#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Status { pub enum Status {

View File

@ -105,7 +105,7 @@ pub struct ContactUpdate<'a> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::{ContactUpdate, PostalInfo, Status, Voice}; use super::{ContactUpdate, PostalInfo, Status, Voice};
use crate::contact::Address; use crate::contact::{Address, InfoType};
use crate::response::ResultCode; use crate::response::ResultCode;
use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID}; use crate::tests::{assert_serialized, response_from_file, CLTRID, SUCCESS_MSG, SVTRID};
@ -121,7 +121,8 @@ mod tests {
Some("392374"), Some("392374"),
"FR".parse().unwrap(), "FR".parse().unwrap(),
); );
let postal_info = PostalInfo::new("loc", "John Doe", Some("Acme Widgets"), address); let postal_info =
PostalInfo::new(InfoType::Local, "John Doe", Some("Acme Widgets"), address);
let voice = Voice::new("+33.47237942"); let voice = Voice::new("+33.47237942");
object.set_info("newemail@eppdev.net", postal_info, voice, "eppdev-387323"); object.set_info("newemail@eppdev.net", postal_info, voice, "eppdev-387323");

View File

@ -22,8 +22,8 @@ pub struct Create<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::contact::ContactCreate;
use crate::contact::{Address, PostalInfo, Voice}; use crate::contact::{Address, PostalInfo, Voice};
use crate::contact::{ContactCreate, InfoType};
use crate::extensions::frnic; use crate::extensions::frnic;
use crate::tests::assert_serialized; use crate::tests::assert_serialized;
use frnic::{contact, Ext}; use frnic::{contact, Ext};
@ -36,7 +36,7 @@ mod tests {
"XXX000", "XXX000",
"test@test.fr", "test@test.fr",
PostalInfo::new( PostalInfo::new(
"loc", InfoType::Local,
"Dupont", "Dupont",
None, None,
Address::new( Address::new(
@ -66,7 +66,7 @@ mod tests {
"XXXXXXX", "XXXXXXX",
"test@test.fr", "test@test.fr",
PostalInfo::new( PostalInfo::new(
"loc", InfoType::Local,
"SARL DUPONT", "SARL DUPONT",
None, None,
Address::new( Address::new(
@ -100,7 +100,7 @@ mod tests {
"XXXX0000", "XXXX0000",
"test@test.fr", "test@test.fr",
PostalInfo::new( PostalInfo::new(
"loc", InfoType::Local,
"SARL DUPONT SIREN", "SARL DUPONT SIREN",
None, None,
Address::new( Address::new(
@ -136,7 +136,7 @@ mod tests {
"XXXX0000", "XXXX0000",
"test@test.fr", "test@test.fr",
PostalInfo::new( PostalInfo::new(
"loc", InfoType::Local,
"Dupont JO", "Dupont JO",
None, None,
Address::new( Address::new(