mirror of
https://github.com/kristoferssolo/zero2prod.git
synced 2025-10-21 20:10:40 +00:00
chore: add .env
This commit is contained in:
parent
938bb7d071
commit
c1a4f5d124
1
.env
Normal file
1
.env
Normal file
@ -0,0 +1 @@
|
||||
DATABASE_URL="postgres://postgres:password@localhost:5432/newsletter"
|
||||
8
configuration.toml
Normal file
8
configuration.toml
Normal file
@ -0,0 +1,8 @@
|
||||
application_port = 8000
|
||||
|
||||
[database]
|
||||
host = "127.0.0.1"
|
||||
port = 5432
|
||||
username = "postgres"
|
||||
password = "password"
|
||||
database_name = "newsletter"
|
||||
@ -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]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user