added test for listing drivers :D (insulting error message)

This commit is contained in:
LinlyBoi
2022-12-31 23:17:39 +02:00
parent 3581a7edef
commit ec7a79b8b6

View File

@@ -1,13 +1,29 @@
use crate::{driver_data::Driver, pog::SqlStruct};
use super::*;
use actix_web::{
http::header::ContentType,
test::{self, init_service},
};
use chrono::NaiveDate;
use sqlx::{PgPool, Row};
//TODO: sqlx offline mode for these tests
#[actix_web::test]
async fn test_list_drivers_ok() {
let app = tests::init_service(App::new().service(driver_data::list_all)).await;
dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("Put a DB url in the .env file dumbass");
let pool = PgPoolOptions::new()
.max_connections(10)
.connect(database_url.as_str())
.await
.expect("No pool connection man :(");
let app = tests::init_service(
App::new()
.app_data(web::Data::new(pool.clone()))
.service(driver_data::list_all),
)
.await;
let req = test::TestRequest::get()
.uri("/api/json/drivers")
.insert_header(ContentType::plaintext())
@@ -15,3 +31,4 @@ async fn test_list_drivers_ok() {
let resp = test::call_service(&app, req).await;
assert!(resp.status().is_success());
}
//TODO: sqlx tests