From c1a4f5d124661845da06c24985c66ad6e5eca646 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sat, 23 Mar 2024 16:46:36 +0200 Subject: [PATCH] chore: add .env --- .env | 1 + configuration.toml | 8 ++++++++ tests/health_check.rs | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 .env create mode 100644 configuration.toml diff --git a/.env b/.env new file mode 100644 index 0000000..88cfb53 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +DATABASE_URL="postgres://postgres:password@localhost:5432/newsletter" diff --git a/configuration.toml b/configuration.toml new file mode 100644 index 0000000..5830bbe --- /dev/null +++ b/configuration.toml @@ -0,0 +1,8 @@ +application_port = 8000 + +[database] +host = "127.0.0.1" +port = 5432 +username = "postgres" +password = "password" +database_name = "newsletter" diff --git a/tests/health_check.rs b/tests/health_check.rs index 40dadf5..f5e813a 100644 --- a/tests/health_check.rs +++ b/tests/health_check.rs @@ -23,12 +23,12 @@ async fn subscribe_returns_200_for_valid_form_data() { let address = spawn_app().await; let configuration = get_configuration().expect("Failed to read configuration."); let db_url = configuration.database.to_string(); - let connection = PgConnection::connect(&db_url) + let mut connection = PgConnection::connect(&db_url) .await .expect("Failed to connect to Postgres."); let client = Client::new(); - let body = "name=kristofers%20solo&email=dev%40kristofers.solo"; + let body = "name=Kristofers%20Solo&email=dev%40kristofers.solo"; let response = client .post(&format!("{}/subscribtions", &address)) .header("Content-Type", "application/x-www-form-urlencoded") @@ -38,6 +38,18 @@ async fn subscribe_returns_200_for_valid_form_data() { .expect("Failed to execute request."); assert_eq!(200, response.status().as_u16()); + let saved = sqlx::query!( + r#" + SELECT email, name + FROM subscriptions + "# + ) + .fetch_one(&mut connection) + .await + .expect("Failed to fetch saved subscription."); + + assert_eq!(saved.email, "dev@kristofers.solo"); + assert_eq!(saved.name, "Kristofers Solo"); } #[tokio::test]