Error handling with thiserror and anyhow

This commit is contained in:
Alphonse Paix
2025-08-26 12:47:22 +02:00
parent 4ce25a8136
commit 9193f2020d
5 changed files with 133 additions and 49 deletions

View File

@@ -122,3 +122,19 @@ async fn subscribe_sends_a_confirmation_email_with_a_link() {
let confirmation_links = app.get_confirmation_links(email_request);
assert_eq!(confirmation_links.html, confirmation_links.text);
}
#[tokio::test]
async fn subscribe_fails_if_there_is_a_fatal_database_error() {
let app = TestApp::spawn().await;
let body = "name=Alphonse&email=alphonse.paix%40outlook.com";
sqlx::query!("ALTER TABLE subscriptions DROP COLUMN email")
.execute(&app.connection_pool)
.await
.unwrap();
let response = app.post_subscriptions(body.into()).await;
assert_eq!(response.status().as_u16(), 500);
}