diff --git a/src/lib.rs b/src/lib.rs index bd6bd3f..5af8ac6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ pub struct Payload { pub email: String, pub message: String, pub service: Option, - pub company: Option, + pub company: String, } #[event(fetch, respond_with_errors)] @@ -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) diff --git a/tests/send_message.rs b/tests/send_message.rs index 4054ab5..8a20aba 100644 --- a/tests/send_message.rs +++ b/tests/send_message.rs @@ -15,7 +15,7 @@ async fn it_works_for_the_happy_path() { email: String::from("email@domain.tld"), message: String::from("Hi!"), service: Some(String::from("Digital Products & Design")), - company: None, + company: String::from(""), }; let result = send_message(payload, "api_key", "trigger@zapier.com", &request_sendgrid).await; @@ -53,7 +53,7 @@ async fn it_sends_the_right_payload_to_sendgrid() { email: String::from("email@domain.tld"), message: String::from("Hi!"), service: Some(String::from("Digital Products & Design")), - company: None, + company: String::from(""), }; let _result = send_message(payload, "api_key", "trigger@zapier.com", &request_sendgrid).await; } @@ -89,7 +89,7 @@ async fn it_sends_an_empty_message_if_none_is_provided() { email: String::from("email@domain.tld"), message: String::from(""), service: Some(String::from("Digital Products & Design")), - company: None, + company: String::from(""), }; let _result = send_message(payload, "api_key", "trigger@zapier.com", &request_sendgrid).await; } @@ -125,7 +125,7 @@ async fn it_leaves_out_the_service_if_an_empty_one_is_provided() { email: String::from("email@domain.tld"), message: String::from("Hi!"), service: Some(String::from("")), - company: None, + company: String::from(""), }; let _result = send_message(payload, "api_key", "trigger@zapier.com", &request_sendgrid).await; } @@ -161,7 +161,7 @@ async fn it_leaves_out_the_service_if_none_is_provided() { email: String::from("email@domain.tld"), message: String::from("Hi!"), service: None, - company: None, + company: String::from(""), }; let _result = send_message(payload, "api_key", "trigger@zapier.com", &request_sendgrid).await; } @@ -197,7 +197,7 @@ async fn it_leaves_out_the_service_if_other_is_provided() { email: String::from("email@domain.tld"), message: String::from("Hi!"), service: Some(String::from("Other")), - company: None, + company: String::from(""), }; let _result = send_message(payload, "api_key", "trigger@zapier.com", &request_sendgrid).await; } @@ -233,7 +233,7 @@ async fn it_adds_company_to_the_subject_if_one_is_provided() { email: String::from("email@domain.tld"), 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", "trigger@zapier.com", &request_sendgrid).await; } @@ -249,7 +249,7 @@ async fn it_responds_with_502_if_sendgrid_errors() { email: String::from("email@domain.tld"), message: String::from("Hi!"), service: Some(String::from("")), - company: None, + company: String::from(""), }; let result = send_message(payload, "api_key", "trigger@zapier.com", &request_sendgrid).await; @@ -267,7 +267,7 @@ async fn it_responds_with_500_if_calling_sendgrid_errors() { email: String::from("email@domain.tld"), message: String::from("Hi!"), service: Some(String::from("")), - company: None, + company: String::from(""), }; let result = send_message(payload, "api_key", "trigger@zapier.com", &request_sendgrid).await;