diff --git a/crates/idfoto-core/src/item_types/identity.rs b/crates/idfoto-core/src/item_types/identity.rs index fa89ba2..a7485dc 100644 --- a/crates/idfoto-core/src/item_types/identity.rs +++ b/crates/idfoto-core/src/item_types/identity.rs @@ -1,3 +1,45 @@ +//! Identity: name, address, phone, email, date-of-birth. + +use chrono::NaiveDate; use serde::{Deserialize, Serialize}; + #[derive(Debug, Clone, Serialize, Deserialize, Default)] -pub struct IdentityCore {} +pub struct IdentityCore { + #[serde(skip_serializing_if = "Option::is_none")] + pub full_name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub address: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub phone: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub email: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub date_of_birth: Option, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn identity_full_round_trip() { + let id = IdentityCore { + full_name: Some("Alice Doe".into()), + address: Some("123 Main St\nAnytown".into()), + phone: Some("+1-555-0100".into()), + email: Some("alice@example.com".into()), + date_of_birth: NaiveDate::from_ymd_opt(1990, 4, 18), + }; + let json = serde_json::to_string(&id).unwrap(); + let parsed: IdentityCore = serde_json::from_str(&json).unwrap(); + assert_eq!(parsed.full_name.as_deref(), Some("Alice Doe")); + assert_eq!(parsed.date_of_birth, NaiveDate::from_ymd_opt(1990, 4, 18)); + } + + #[test] + fn empty_identity_omits_all_fields() { + let id = IdentityCore::default(); + let json = serde_json::to_string(&id).unwrap(); + assert_eq!(json, "{}"); + } +}