Fault-tolerant delivery system
This commit is contained in:
@@ -9,6 +9,8 @@ use uuid::Uuid;
|
||||
use wiremock::MockServer;
|
||||
use zero2prod::{
|
||||
configuration::{DatabaseSettings, get_configuration},
|
||||
email_client::EmailClient,
|
||||
issue_delivery_worker::{ExecutionOutcome, try_execute_task},
|
||||
startup::Application,
|
||||
telemetry::init_subscriber,
|
||||
};
|
||||
@@ -70,6 +72,7 @@ pub struct TestApp {
|
||||
pub port: u16,
|
||||
pub test_user: TestUser,
|
||||
pub api_client: reqwest::Client,
|
||||
pub email_client: EmailClient,
|
||||
}
|
||||
|
||||
impl TestApp {
|
||||
@@ -85,6 +88,7 @@ impl TestApp {
|
||||
c
|
||||
};
|
||||
let connection_pool = configure_database(&configuration.database).await;
|
||||
let email_client = EmailClient::build(configuration.email_client.clone()).unwrap();
|
||||
let application = Application::build(configuration)
|
||||
.await
|
||||
.expect("Failed to build application");
|
||||
@@ -110,6 +114,7 @@ impl TestApp {
|
||||
port,
|
||||
test_user,
|
||||
api_client,
|
||||
email_client,
|
||||
};
|
||||
|
||||
tokio::spawn(application.run_until_stopped());
|
||||
@@ -117,6 +122,18 @@ impl TestApp {
|
||||
app
|
||||
}
|
||||
|
||||
pub async fn dispatch_all_pending_emails(&self) {
|
||||
loop {
|
||||
if let ExecutionOutcome::EmptyQueue =
|
||||
try_execute_task(&self.connection_pool, &self.email_client)
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_confirmation_links(&self, request: &wiremock::Request) -> ConfirmationLinks {
|
||||
let body: serde_json::Value = serde_json::from_slice(&request.body).unwrap();
|
||||
let get_link = |s: &str| {
|
||||
@@ -218,6 +235,14 @@ impl TestApp {
|
||||
.expect("failed to execute request")
|
||||
}
|
||||
|
||||
pub async fn admin_login(&self) {
|
||||
let login_body = serde_json::json!({
|
||||
"username": self.test_user.username,
|
||||
"password": self.test_user.password
|
||||
});
|
||||
self.post_login(&login_body).await;
|
||||
}
|
||||
|
||||
pub async fn post_logout(&self) -> reqwest::Response {
|
||||
self.api_client
|
||||
.post(format!("{}/admin/logout", self.address))
|
||||
|
||||
Reference in New Issue
Block a user