Basic unsubscribe endpoint

This commit is contained in:
Alphonse Paix
2025-09-21 17:49:31 +02:00
parent 6a963a8c0d
commit 7af07ea0dd
17 changed files with 292 additions and 43 deletions

31
tests/api/unsubscribe.rs Normal file
View File

@@ -0,0 +1,31 @@
use crate::helpers::TestApp;
#[tokio::test]
async fn unsubscribe_works_with_a_valid_token() {
let app = TestApp::spawn().await;
app.create_confirmed_subscriber().await;
let record = sqlx::query!("SELECT unsubscribe_token FROM subscriptions")
.fetch_one(&app.connection_pool)
.await
.expect("Failed to fetch saved token");
let response = app
.get_unsubscribe(
record
.unsubscribe_token
.expect("Confirmed subscriber should have a valid unsubscribe token"),
)
.await;
assert!(response.status().is_success());
let html_fragment = response.text().await.unwrap();
assert!(html_fragment.contains("Good bye, old friend"));
let record = sqlx::query!("SELECT email FROM subscriptions")
.fetch_optional(&app.connection_pool)
.await
.expect("Failed to fetch subscription table");
assert!(record.is_none());
}