32 lines
956 B
Rust
32 lines
956 B
Rust
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());
|
|
}
|