feat(core): flesh out IdentityCore
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,45 @@
|
|||||||
|
//! Identity: name, address, phone, email, date-of-birth.
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
pub struct IdentityCore {}
|
pub struct IdentityCore {
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub full_name: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub address: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub phone: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub email: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub date_of_birth: Option<NaiveDate>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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, "{}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user