From 96af3c3b176c5db3d7c6c5b27871c54dc1ead603 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 31 Jul 2023 21:07:01 +0200 Subject: [PATCH] create tests for /public Closes #25 --- src/tera/mod.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/tera/mod.rs b/src/tera/mod.rs index fea7fe8..b14b70c 100644 --- a/src/tera/mod.rs +++ b/src/tera/mod.rs @@ -47,7 +47,9 @@ async fn index(db: &State, user: User, flash: Option")] async fn join(db: &State, trip_details_id: i64, user: User) -> Flash { - let Some(trip_details) = TripDetails::find_by_id(db, trip_details_id).await else { return Flash::error(Redirect::to("/"), "Trip_details do not exist.") }; + let Some(trip_details) = TripDetails::find_by_id(db, trip_details_id).await else { + return Flash::error(Redirect::to("/"), "Trip_details do not exist."); + }; match UserTrip::create(db, &user, &trip_details).await { Ok(_) => { @@ -84,8 +86,8 @@ async fn join(db: &State, trip_details_id: i64, user: User) -> Flash #[get("/remove/")] async fn remove(db: &State, trip_details_id: i64, user: User) -> Flash { let Some(trip_details) = TripDetails::find_by_id(db, trip_details_id).await else { - return Flash::error(Redirect::to("/"), "TripDetailsId does not exist"); - }; + return Flash::error(Redirect::to("/"), "TripDetailsId does not exist"); + }; UserTrip::delete(db, &user, &trip_details).await; @@ -243,4 +245,22 @@ mod test { assert_eq!(flash_cookie.value(), "5:errorTrip_details do not exist."); } + + #[sqlx::test] + fn test_public() { + let db = testdb!(); + + let rocket = rocket::build().manage(db.clone()); + let rocket = crate::tera::config(rocket); + + let client = Client::tracked(rocket).await.unwrap(); + + let req = client.get("/public/main.css"); + let response = req.dispatch().await; + assert_eq!(response.status(), Status::Ok); + + let req = client.get("/public/main.js"); + let response = req.dispatch().await; + assert_eq!(response.status(), Status::Ok); + } }