Basic unsubscribe endpoint
This commit is contained in:
@@ -189,6 +189,17 @@ impl TestApp {
|
||||
ConfirmationLinks { html, text }
|
||||
}
|
||||
|
||||
pub async fn get_unsubscribe(&self, unsubscribe_token: String) -> reqwest::Response {
|
||||
self.api_client
|
||||
.get(format!(
|
||||
"{}/unsubscribe?token={}",
|
||||
&self.address, unsubscribe_token
|
||||
))
|
||||
.send()
|
||||
.await
|
||||
.expect("Failed to execute request")
|
||||
}
|
||||
|
||||
pub async fn get_admin_dashboard(&self) -> reqwest::Response {
|
||||
self.api_client
|
||||
.get(format!("{}/admin/dashboard", &self.address))
|
||||
|
||||
@@ -7,3 +7,4 @@ mod newsletters;
|
||||
mod posts;
|
||||
mod subscriptions;
|
||||
mod subscriptions_confirm;
|
||||
mod unsubscribe;
|
||||
|
||||
31
tests/api/unsubscribe.rs
Normal file
31
tests/api/unsubscribe.rs
Normal 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());
|
||||
}
|
||||
Reference in New Issue
Block a user