create tests for /public

Closes #25
This commit is contained in:
philipp 2023-07-31 21:07:01 +02:00
parent 3730940aed
commit 96af3c3b17

View File

@ -47,7 +47,9 @@ async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_
#[get("/join/<trip_details_id>")]
async fn join(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash<Redirect> {
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<SqlitePool>, trip_details_id: i64, user: User) -> Flash
#[get("/remove/<trip_details_id>")]
async fn remove(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Flash<Redirect> {
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);
}
}