use crate::prelude::*;
#[derive(
Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Builder, Getters, WithSetters,
)]
pub struct PostalAddress {
#[getset(get = "pub", set_with = "pub")]
street_address: StreetAddress,
#[getset(get = "pub", set_with = "pub")]
zip: String,
#[getset(get = "pub", set_with = "pub")]
country: String,
#[getset(get = "pub", set_with = "pub")]
city: String,
}
impl HasSample for PostalAddress {
fn sample() -> Self {
Self::sample_client()
}
fn sample_other() -> Self {
Self::sample_vendor()
}
}
impl PostalAddress {
pub fn sample_client() -> Self {
Self::builder()
.city("London".into())
.country("England".into())
.street_address(
StreetAddress::builder()
.line_1("221B Baker Street".into())
.build(),
)
.zip("NW1 6XE".into())
.build()
}
pub fn sample_vendor() -> Self {
Self::builder()
.city("Paris".into())
.country("France".into())
.street_address(
StreetAddress::builder()
.line_1("5 Avenue Henri-Martin".into())
.line_2("Appartement 24".into())
.build(),
)
.zip("75116".into())
.build()
}
}
#[cfg(test)]
mod tests {
use super::*;
use insta::assert_debug_snapshot;
use test_log::test;
type Sut = PostalAddress;
#[test]
fn equality() {
assert_eq!(Sut::sample(), Sut::sample());
assert_eq!(Sut::sample_other(), Sut::sample_other());
}
#[test]
fn inequality() {
assert_ne!(Sut::sample(), Sut::sample_other());
}
#[test]
fn test_debug() {
assert_debug_snapshot!(Sut::sample(), @r###"
PostalAddress {
street_address: StreetAddress {
line_1: "221B Baker Street",
line_2: "",
},
zip: "NW1 6XE",
country: "England",
city: "London",
}
"###);
}
}