-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add .env file and check db in the /subscriptions happy path test
- Loading branch information
Showing
3 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DATABASE_URL="postgres://postgres:password@localhost:5432/newsletter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
use std::net::TcpListener; | ||
|
||
use sqlx::{Connection, PgConnection}; | ||
use zero2prod::configuration::get_configuration; | ||
|
||
#[tokio::test] | ||
async fn health_check_works() { | ||
// Arrange | ||
|
@@ -22,6 +25,11 @@ async fn health_check_works() { | |
async fn subscribe_returns_a_200_for_valid_form_data() { | ||
// Arrange | ||
let app_address = spawn_app(); | ||
let configuration = get_configuration().expect("Failed to read configuration"); | ||
let connection_string = configuration.database.connection_string(); | ||
let mut connection = PgConnection::connect(&connection_string) | ||
.await | ||
.expect("Failed to connect to Postgres."); | ||
let client = reqwest::Client::new(); | ||
|
||
// Act | ||
|
@@ -36,6 +44,14 @@ async fn subscribe_returns_a_200_for_valid_form_data() { | |
|
||
// Assert | ||
assert_eq!(200, response.status().as_u16()); | ||
|
||
let saved = sqlx::query!("SELECT email, name FROM subscriptions",) | ||
.fetch_one(&mut connection) | ||
.await | ||
.expect("Failed to fetch saved subscription."); | ||
|
||
assert_eq!(saved.email, "[email protected]"); | ||
assert_eq!(saved.name, "le guin"); | ||
} | ||
|
||
#[tokio::test] | ||
|