diff --git a/tests/api/subscriptions.rs b/tests/api/subscriptions.rs index 53045cb..2a470c6 100644 --- a/tests/api/subscriptions.rs +++ b/tests/api/subscriptions.rs @@ -41,6 +41,24 @@ async fn subscribe_persists_the_new_subscriber() { assert_eq!(saved.status, "pending_confirmation"); } +#[actix_rt::test] +async fn subscribe_fails_if_there_is_a_fatal_database_error() { + // Arrange + let app = spawn_app().await; + let body = "name=le%20guin&email=ursula_le_guin%40gmail.com"; + // Sabotage the database + sqlx::query!("ALTER TABLE subscription_tokens DROP COLUMN subscription_token;",) + .execute(&app.db_pool) + .await + .unwrap(); + + // Act + let response = app.post_subscriptions(body.into()).await; + + // Assert + assert_eq!(response.status().as_u16(), 500); +} + #[actix_rt::test] async fn subscribe_sends_a_confirmation_email_for_valid_data() { // Arrange