Refactor.

This commit is contained in:
LukeMathWalker 2021-03-09 21:12:58 +00:00
parent 28fc5612ae
commit 6e049bab9e

View file

@ -13,14 +13,6 @@ async fn subscribe_returns_a_200_for_valid_form_data() {
// Assert // Assert
assert_eq!(200, response.status().as_u16()); assert_eq!(200, response.status().as_u16());
let saved = sqlx::query!("SELECT email, name FROM subscriptions",)
.fetch_one(&app.db_pool)
.await
.expect("Failed to fetch saved subscription.");
assert_eq!(saved.email, "ursula_le_guin@gmail.com");
assert_eq!(saved.name, "le guin");
} }
#[actix_rt::test] #[actix_rt::test]
@ -30,16 +22,17 @@ async fn subscribe_persists_the_new_subscriber() {
let body = "name=le%20guin&email=ursula_le_guin%40gmail.com"; let body = "name=le%20guin&email=ursula_le_guin%40gmail.com";
// Act // Act
let response = app.post_subscriptions(body.into()).await; app.post_subscriptions(body.into()).await;
// Assert // Assert
let saved = sqlx::query!("SELECT email, name FROM subscriptions",) let saved = sqlx::query!("SELECT email, name, status FROM subscriptions",)
.fetch_one(&app.db_pool) .fetch_one(&app.db_pool)
.await .await
.expect("Failed to fetch saved subscription."); .expect("Failed to fetch saved subscription.");
assert_eq!(saved.email, "ursula_le_guin@gmail.com"); assert_eq!(saved.email, "ursula_le_guin@gmail.com");
assert_eq!(saved.name, "le guin"); assert_eq!(saved.name, "le guin");
assert_eq!(saved.status, "pending_confirmation");
} }
#[actix_rt::test] #[actix_rt::test]