diff --git a/src/models/agent.rs b/src/models/agent.rs new file mode 100644 index 0000000..cbd5309 --- /dev/null +++ b/src/models/agent.rs @@ -0,0 +1,59 @@ +use std::fmt; +struct Agent { + + pub first_name: String +} + +#[derive(Default)] +struct AgentBuilder { + #[allow(dead_code)] + pub first_name: Option +} + +impl Agent { + pub fn builder() -> AgentBuilder { + AgentBuilder::default() + } +} + +impl AgentBuilder { + #[allow(dead_code)] + pub fn first_name(mut self, first_name: &str) -> Self { + self.first_name = Some(String::from(first_name)); + self + } + + #[allow(dead_code)] + pub fn build(self) -> Result { + Ok(Agent { + first_name: self.first_name.ok_or("_")? + }) + } +} + +impl fmt::Display for Agent { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.first_name) + } +} + + +#[cfg(test)] +mod tests { + use super::Agent; + + #[test] + fn test_agent_name() { + let agent = Agent::builder().first_name("Jason").build(); + + assert!(agent.is_ok()) + } + + #[test] + fn test_agent_name_to_string() { + let agent = Agent::builder().first_name("Jason").build().unwrap(); + + assert_eq!(agent.to_string(), "Jason") + } + +} \ No newline at end of file diff --git a/src/models/contact.rs b/src/models/contact.rs index 80c69cb..37e0c58 100644 --- a/src/models/contact.rs +++ b/src/models/contact.rs @@ -36,11 +36,11 @@ impl Update { } #[derive(Debug)] -pub struct Builder { +pub struct Construct { pub id: i64, pub update: Update, } -impl Builder { +impl Construct { pub fn new( id: i64, first_name: Option, @@ -120,7 +120,7 @@ impl Contact { mod tests { use crate::errors::AppError; - use super::{Builder, Contact}; + use super::{Construct, Contact}; #[test] fn test_display_name() { @@ -131,8 +131,8 @@ mod tests { } #[test] - fn test_contact_update_builder() { - let edits = Builder::new( + fn test_contact_update_construct() { + let edits = Construct::new( 1, None, None, @@ -151,8 +151,8 @@ mod tests { } #[test] - fn test_contact_update_builder_2() { - let edits = Builder::new( + fn test_contact_update_construct_2() { + let edits = Construct::new( 2, Some("Mary".to_string()), Some("Smith".to_string()), @@ -172,13 +172,13 @@ mod tests { #[test] fn test_is_empty() { - let result = Builder::new(1, None, None, None, None, None); + let result = Construct::new(1, None, None, None, None, None); assert!(result.is_err()); } #[test] - fn test_invalid_email_builder() { - let result = Builder::new( + fn test_invalid_email_construct() { + let result = Construct::new( 1, None, None, @@ -191,8 +191,8 @@ mod tests { } #[test] - fn test_invalid_builder_phone_number() { - let result = Builder::new(1, None, None, None, Some("123-123-12345".to_string()), None); + fn test_invalid_construct_phone_number() { + let result = Construct::new(1, None, None, None, Some("123-123-12345".to_string()), None); println!("{result:?}"); assert!(result.is_err()); diff --git a/src/models/mod.rs b/src/models/mod.rs index b4eb7ea..8961aba 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -1,5 +1,6 @@ mod contact; +mod agent; -pub use contact::Builder as ContactBuilder; +pub use contact::Construct as ContactBuilder; pub use contact::Contact; -pub use contact::Indexed as IndexedContact; +pub use contact::Indexed as IndexedContact; \ No newline at end of file