diff --git a/src/routes/subscriptions.rs b/src/routes/subscriptions.rs
index 902ecc1..1dc6540 100644
--- a/src/routes/subscriptions.rs
+++ b/src/routes/subscriptions.rs
@@ -43,12 +43,19 @@ pub async fn subscribe(
.await
.map_err(|_| HttpResponse::InternalServerError().finish())?;
// We are swallowing the error for the time being.
+ let confirmation_link = "https://my-api.com/subscriptions/confirm";
let _ = email_client
.send_email(
new_subscriber.email,
"Welcome!",
- "Welcome to our newsletter!",
- "Welcome to our newsletter!",
+ &format!(
+ "Welcome to our newsletter!
Click here to confirm your subscription.",
+ confirmation_link
+ ),
+ &format!(
+ "Welcome to our newsletter!\nVisit {} to confirm your subscription.",
+ confirmation_link
+ ),
)
.await;
Ok(HttpResponse::Ok().finish())
diff --git a/tests/api/subscriptions.rs b/tests/api/subscriptions.rs
index c1b67e4..e132245 100644
--- a/tests/api/subscriptions.rs
+++ b/tests/api/subscriptions.rs
@@ -60,15 +60,22 @@ async fn subscribe_sends_a_confirmation_email_with_a_link() {
// Assert
let email_request = &app.email_server.received_requests().await.unwrap()[0];
- let body = std::str::from_utf8(&email_request.body).unwrap();
- let links: Vec<_> = linkify::LinkFinder::new()
- .links(body)
- .filter(|l| *l.kind() == linkify::LinkKind::Url)
- .collect();
- // One in the HTML version, one in the plain text version
- assert_eq!(links.len(), 2);
+ let body: serde_json::Value = serde_json::from_slice(&email_request.body).unwrap();
+
+ // Extract the link from one of the request fields.
+ let get_link = |s: &str| {
+ let links: Vec<_> = linkify::LinkFinder::new()
+ .links(s)
+ .filter(|l| *l.kind() == linkify::LinkKind::Url)
+ .collect();
+ assert_eq!(links.len(), 1);
+ links[0].as_str().to_owned()
+ };
+
+ let html_link = get_link(&body["HtmlBody"].as_str().unwrap());
+ let text_link = get_link(&body["TextBody"].as_str().unwrap());
// The two links should be identical
- assert_eq!(links[0].as_str(), links[1].as_str());
+ assert_eq!(html_link, text_link);
}
#[actix_rt::test]