Unsubscribe option available on website

This commit is contained in:
Alphonse Paix
2025-09-22 15:44:02 +02:00
parent 4b5fbc2eb3
commit 6f9d33953c
19 changed files with 397 additions and 91 deletions

View File

@@ -22,16 +22,12 @@ async fn subscriber_can_unsubscribe() {
.expect("Failed to fetch saved token");
let response = app
.get_unsubscribe(
record
.unsubscribe_token
.expect("Confirmed subscriber should have a valid unsubscribe token"),
)
.get_unsubscribe_confirm(&record.unsubscribe_token.unwrap())
.await;
assert_eq!(response.status().as_u16(), 200);
let html_fragment = response.text().await.unwrap();
assert!(html_fragment.contains("Good bye, old friend"));
assert!(html_fragment.contains("Good bye, friend"));
let record = sqlx::query!("SELECT email FROM subscriptions")
.fetch_optional(&app.connection_pool)
@@ -120,9 +116,11 @@ async fn an_invalid_unsubscribe_token_is_rejected() {
let app = TestApp::spawn().await;
app.create_confirmed_subscriber().await;
let response = reqwest::get(format!("{}/unsubscribe?token=invalid", app.address))
.await
.unwrap();
let response = app.get_unsubscribe_confirm("invalid-token").await;
// let response = reqwest::get(format!("{}/unsubscribe?token=invalid", app.address))
// .await
// .unwrap();
assert_eq!(response.status().as_u16(), 404);
}
@@ -139,16 +137,12 @@ async fn subscription_works_after_unsubscribe() {
let email = record.email;
let response = app
.get_unsubscribe(
record
.unsubscribe_token
.expect("Confirmed subscriber should have a valid unsubscribe token"),
)
.get_unsubscribe_confirm(&record.unsubscribe_token.unwrap())
.await;
assert_eq!(response.status().as_u16(), 200);
let html_fragment = response.text().await.unwrap();
assert!(html_fragment.contains("Good bye, old friend"));
assert!(html_fragment.contains("Good bye, friend"));
let record = sqlx::query!("SELECT email, unsubscribe_token FROM subscriptions")
.fetch_optional(&app.connection_pool)