Skip to content

Commit

Permalink
Merge pull request #38 from mainmatter/fix-company-handling
Browse files Browse the repository at this point in the history
fix handling of company name
  • Loading branch information
marcoow authored Aug 7, 2024
2 parents 6035960 + 998fad0 commit cb4bc7c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct Payload {
pub email: String,
pub message: String,
pub service: Option<String>,
pub company: Option<String>,
pub company: String,
}

#[event(fetch, respond_with_errors)]
Expand Down Expand Up @@ -82,7 +82,8 @@ where
"Mainmatter inquiry".to_owned()
};

let name = if let Some(company) = payload.company {
let company = payload.company.trim();
let name = if !company.is_empty() {
format!("{} ({}) via mainmatter.com", payload.name, company)
} else {
format!("{} via mainmatter.com", payload.name)
Expand Down
18 changes: 9 additions & 9 deletions tests/send_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn it_works_for_the_happy_path() {
email: String::from("[email protected]"),
message: String::from("Hi!"),
service: Some(String::from("Digital Products & Design")),
company: None,
company: String::from(""),
};
let result = send_message(payload, "api_key", "[email protected]", &request_sendgrid).await;

Expand Down Expand Up @@ -53,7 +53,7 @@ async fn it_sends_the_right_payload_to_sendgrid() {
email: String::from("[email protected]"),
message: String::from("Hi!"),
service: Some(String::from("Digital Products & Design")),
company: None,
company: String::from(""),
};
let _result = send_message(payload, "api_key", "[email protected]", &request_sendgrid).await;
}
Expand Down Expand Up @@ -89,7 +89,7 @@ async fn it_sends_an_empty_message_if_none_is_provided() {
email: String::from("[email protected]"),
message: String::from(""),
service: Some(String::from("Digital Products & Design")),
company: None,
company: String::from(""),
};
let _result = send_message(payload, "api_key", "[email protected]", &request_sendgrid).await;
}
Expand Down Expand Up @@ -125,7 +125,7 @@ async fn it_leaves_out_the_service_if_an_empty_one_is_provided() {
email: String::from("[email protected]"),
message: String::from("Hi!"),
service: Some(String::from("")),
company: None,
company: String::from(""),
};
let _result = send_message(payload, "api_key", "[email protected]", &request_sendgrid).await;
}
Expand Down Expand Up @@ -161,7 +161,7 @@ async fn it_leaves_out_the_service_if_none_is_provided() {
email: String::from("[email protected]"),
message: String::from("Hi!"),
service: None,
company: None,
company: String::from(""),
};
let _result = send_message(payload, "api_key", "[email protected]", &request_sendgrid).await;
}
Expand Down Expand Up @@ -197,7 +197,7 @@ async fn it_leaves_out_the_service_if_other_is_provided() {
email: String::from("[email protected]"),
message: String::from("Hi!"),
service: Some(String::from("Other")),
company: None,
company: String::from(""),
};
let _result = send_message(payload, "api_key", "[email protected]", &request_sendgrid).await;
}
Expand Down Expand Up @@ -233,7 +233,7 @@ async fn it_adds_company_to_the_subject_if_one_is_provided() {
email: String::from("[email protected]"),
message: String::from("Hi!"),
service: Some(String::from("Other")),
company: Some(String::from("Company")),
company: String::from("Company"),
};
let _result = send_message(payload, "api_key", "[email protected]", &request_sendgrid).await;
}
Expand All @@ -249,7 +249,7 @@ async fn it_responds_with_502_if_sendgrid_errors() {
email: String::from("[email protected]"),
message: String::from("Hi!"),
service: Some(String::from("")),
company: None,
company: String::from(""),
};
let result = send_message(payload, "api_key", "[email protected]", &request_sendgrid).await;

Expand All @@ -267,7 +267,7 @@ async fn it_responds_with_500_if_calling_sendgrid_errors() {
email: String::from("[email protected]"),
message: String::from("Hi!"),
service: Some(String::from("")),
company: None,
company: String::from(""),
};
let result = send_message(payload, "api_key", "[email protected]", &request_sendgrid).await;

Expand Down

0 comments on commit cb4bc7c

Please sign in to comment.