use crate::Url;
#[derive(
Debug,
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
derive_more::AsRef,
derive_more::Display,
derive_more::From,
derive_more::FromStr,
derive_more::Into,
serde::Serialize,
serde::Deserialize,
)]
pub struct OrganizationUrl(Url);
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
use super::OrganizationUrl;
#[test]
fn from_str() {
assert_eq!(
OrganizationUrl(
"https://oparl.example.org/organization/34"
.parse()
.expect("value must be a parseable url")
),
"https://oparl.example.org/organization/34"
.parse()
.expect("value must be a parseable id")
);
}
}
#[cfg(test)]
mod serde_tests {
use pretty_assertions::assert_eq;
use serde_json::json;
use super::OrganizationUrl;
#[test]
fn serialize() {
assert_eq!(
json!(OrganizationUrl(
"https://oparl.example.org/organization/34"
.parse()
.expect("value must be a parseable url")
)),
json!("https://oparl.example.org/organization/34")
);
}
#[test]
fn deserialize_good() {
let deserialized: OrganizationUrl =
serde_json::from_value(json!("https://oparl.example.org/organization/34"))
.expect("value must be deserializable as OrganizationId");
assert_eq!(
deserialized,
OrganizationUrl(
"https://oparl.example.org/organization/34"
.parse()
.expect("value must be a parseable url")
)
);
}
#[test]
fn deserialize_bad() {
assert!(serde_json::from_value::<OrganizationUrl>(json!("xyzabcd")).is_err());
assert!(serde_json::from_value::<OrganizationUrl>(json!(true)).is_err());
assert!(serde_json::from_value::<OrganizationUrl>(json!(123)).is_err());
}
}