tests for link in email & subscription status
This commit is contained in:
@ -1,11 +1,13 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use sqlx::{postgres::PgPoolOptions, Connection, Executor, PgConnection, Pool, Postgres};
|
||||
use uuid::Uuid;
|
||||
use wiremock::MockServer;
|
||||
use zero2prod::{configuration::{get_configuration, DatabaseSettings}, startup::{get_connection_pool, Application}, telemetry::{get_subscriber, init_subscriber}};
|
||||
|
||||
pub struct TestApp {
|
||||
pub address: String,
|
||||
pub connection_pool: Pool<Postgres>,
|
||||
pub email_server: MockServer,
|
||||
}
|
||||
|
||||
impl TestApp {
|
||||
@ -35,23 +37,27 @@ static TRACING: Lazy<()> = Lazy::new(|| {
|
||||
|
||||
pub async fn spawn_app() -> TestApp {
|
||||
Lazy::force(&TRACING);
|
||||
let email_server = MockServer::start().await;
|
||||
|
||||
let config = {
|
||||
let mut c = get_configuration().expect("Failed to read configuration");
|
||||
c.database.database_name = Uuid::new_v4().to_string();
|
||||
c.application.port = 0;
|
||||
c.email_client.base_url = email_server.uri();
|
||||
c
|
||||
};
|
||||
|
||||
configure_database(&config.database).await;
|
||||
|
||||
let app = Application::build(config.clone()).await.expect("Failed to build app.");
|
||||
println!("App built at port: {}", app.port());
|
||||
let address = format!("http://127.0.0.1:{}", app.port());
|
||||
let _fut = tokio::spawn(app.run_until_stopped());
|
||||
|
||||
TestApp {
|
||||
address,
|
||||
connection_pool: get_connection_pool(config.database),
|
||||
email_server,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user