Skip to content

Commit

Permalink
Merge pull request #1 from jasonribble/agent
Browse files Browse the repository at this point in the history
Agent object
  • Loading branch information
jasonribble authored Sep 16, 2024
2 parents a3d4362 + 5b89ed1 commit ac03b78
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 14 deletions.
59 changes: 59 additions & 0 deletions src/models/agent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use std::fmt;
struct Agent {

pub first_name: String
}

#[derive(Default)]
struct AgentBuilder {
#[allow(dead_code)]
pub first_name: Option<String>
}

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<Agent, &'static str> {
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")
}

}
24 changes: 12 additions & 12 deletions src/models/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down Expand Up @@ -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() {
Expand All @@ -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,
Expand All @@ -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()),
Expand All @@ -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,
Expand All @@ -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());
Expand Down
5 changes: 3 additions & 2 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit ac03b78

Please sign in to comment.