Fix incorrect database query in test suite

This commit is contained in:
Alphonse Paix
2025-08-22 08:28:22 +02:00
parent 5cc5758097
commit b280f10c40

View File

@@ -1,6 +1,6 @@
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use secrecy::ExposeSecret; use secrecy::ExposeSecret;
use sqlx::{Connection, Executor, PgConnection, PgPool}; use sqlx::{Executor, PgPool};
use tokio::net::TcpListener; use tokio::net::TcpListener;
use uuid::Uuid; use uuid::Uuid;
use zero2prod::{ use zero2prod::{
@@ -39,11 +39,6 @@ async fn health_check_works() {
#[tokio::test] #[tokio::test]
async fn subscribe_returns_a_200_for_valid_form_data() { async fn subscribe_returns_a_200_for_valid_form_data() {
let app = spawn_app().await; let app = spawn_app().await;
let configuration = get_configuration().expect("Failed to read configuration");
let connection_string = configuration.database.connection_string();
let mut connection = PgConnection::connect(connection_string.expose_secret())
.await
.expect("Failed to connect to Postgres");
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let body = "name=alphonse&email=alphonse.paix%40outlook.com"; let body = "name=alphonse&email=alphonse.paix%40outlook.com";
@@ -58,7 +53,7 @@ async fn subscribe_returns_a_200_for_valid_form_data() {
assert_eq!(200, response.status().as_u16()); assert_eq!(200, response.status().as_u16());
let saved = sqlx::query!("SELECT email, name FROM subscriptions") let saved = sqlx::query!("SELECT email, name FROM subscriptions")
.fetch_one(&mut connection) .fetch_one(&app.connection_pool)
.await .await
.expect("Failed to fetch saved subscription"); .expect("Failed to fetch saved subscription");