diff --git a/tests/api/subscriptions.rs b/tests/api/subscriptions.rs index e132245..da4c2b2 100644 --- a/tests/api/subscriptions.rs +++ b/tests/api/subscriptions.rs @@ -23,6 +23,25 @@ async fn subscribe_returns_a_200_for_valid_form_data() { assert_eq!(saved.name, "le guin"); } +#[actix_rt::test] +async fn subscribe_persists_the_new_subscriber() { + // Arrange + let app = spawn_app().await; + let body = "name=le%20guin&email=ursula_le_guin%40gmail.com"; + + // Act + let response = app.post_subscriptions(body.into()).await; + + // Assert + 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] async fn subscribe_sends_a_confirmation_email_for_valid_data() { // Arrange