From e4e6bf7f15eb9b6d936668319939f85ca8576364 Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 24 Oct 2023 09:14:11 +0200 Subject: [PATCH] disable functionality until introduced --- src/tera/boatdamage.rs | 9 +- src/tera/log.rs | 1203 ++++++++++++++++++++-------------------- 2 files changed, 609 insertions(+), 603 deletions(-) diff --git a/src/tera/boatdamage.rs b/src/tera/boatdamage.rs index 82fb350..82e5d01 100644 --- a/src/tera/boatdamage.rs +++ b/src/tera/boatdamage.rs @@ -71,6 +71,7 @@ async fn create<'r>( data: Form>, coxuser: CoxUser, ) -> Flash { + return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)"); let boatdamage_to_add = BoatDamageToAdd { boat_id: data.boat_id, desc: data.desc, @@ -100,6 +101,7 @@ async fn create_from_kiosk<'r>( data: Form>, _kiosk: KioskCookie, ) -> Flash { + return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)"); let boatdamage_to_add = BoatDamageToAdd { boat_id: data.boat_id, desc: data.desc, @@ -127,6 +129,7 @@ async fn fixed<'r>( boatdamage_id: i32, coxuser: CoxUser, ) -> Flash { + return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)"); let boatdamage = BoatDamage::find_by_id(db, boatdamage_id).await.unwrap(); //TODO: Fix let boatdamage_fixed = BoatDamageFixed { desc: data.desc, @@ -150,16 +153,14 @@ async fn verified<'r>( boatdamage_id: i32, techuser: TechUser, ) -> Flash { + return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)"); let boatdamage = BoatDamage::find_by_id(db, boatdamage_id).await.unwrap(); //TODO: Fix let boatdamage_verified = BoatDamageVerified { desc: data.desc, user_id_verified: techuser.id as i32, }; match boatdamage.verified(db, boatdamage_verified).await { - Ok(_) => Flash::success( - Redirect::to("/boatdamage"), - "Bootsschaden verifiziert", - ), + Ok(_) => Flash::success(Redirect::to("/boatdamage"), "Bootsschaden verifiziert"), Err(e) => Flash::error(Redirect::to("/boatdamage"), format!("Error: {e}")), } } diff --git a/src/tera/log.rs b/src/tera/log.rs index eb0382f..54b9ff7 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -154,6 +154,8 @@ async fn kiosk( } async fn create_logbook(db: &SqlitePool, data: Form, user: &User) -> Flash { + return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)"); + match Logbook::create( db, data.into_inner(), @@ -199,6 +201,7 @@ async fn home_logbook( logbook_id: i32, user: &User, ) -> Flash { + return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)"); let logbook: Option = Logbook::find_by_id(db, logbook_id).await; let Some(logbook) = logbook else { return Flash::error( @@ -248,6 +251,7 @@ async fn home( #[get("//delete", rank = 2)] async fn delete(db: &State, logbook_id: i32, user: User) -> Flash { + return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)"); let logbook = Logbook::find_by_id(db, logbook_id).await; if let Some(logbook) = logbook { match logbook.delete(db, &user).await { @@ -274,6 +278,7 @@ async fn delete_kiosk( logbook_id: i32, _kiosk: KioskCookie, ) -> Flash { + return Flash::error(Redirect::to("/log"), "Du musst noch kurz geduldig sein. Sobald wir unser Logbuch umgestellt haben, kannst du es hier im Ruderassistenten verwenden ;)"); let logbook = Logbook::find_by_id(db, logbook_id).await; if let Some(logbook) = logbook { let cox = User::find_by_id(db, logbook.shipmaster as i32) @@ -313,602 +318,602 @@ pub fn routes() -> Vec { ] } -#[cfg(test)] -mod test { - use rocket::http::ContentType; - use rocket::{http::Status, local::asynchronous::Client}; - use sqlx::SqlitePool; - - use crate::model::logbook::Logbook; - use crate::tera::{log::Boat, User}; - use crate::testdb; - - #[sqlx::test] - fn test_kiosk_cookie() { - 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("/log"); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::SeeOther); - assert_eq!(response.headers().get("Location").next(), Some("/auth")); - - let req = client.get("/log/kiosk/ekrv2019/Linz"); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::SeeOther); - assert_eq!(response.headers().get("Location").next(), Some("/log")); - - let req = client.get("/log"); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::Ok); - let text = response.into_string().await.unwrap(); - assert!(text.contains("Logbuch")); - assert!(text.contains("Neue Ausfahrt")); - - assert!(!text.contains("Ottensheim Boot")); - } - - #[sqlx::test] - fn test_kiosk_cookie_boat() { - 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("/log/kiosk/ekrv2019/Ottensheim"); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::SeeOther); - assert_eq!(response.headers().get("Location").next(), Some("/log")); - - let req = client.get("/log"); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::Ok); - let text = response.into_string().await.unwrap(); - assert!(text.contains("Logbuch")); - assert!(text.contains("Neue Ausfahrt")); - - assert!(text.contains("Ottensheim Boot")); - } - - #[sqlx::test] - fn test_index() { - let db = testdb!(); - - let rocket = rocket::build().manage(db.clone()); - let rocket = crate::tera::config(rocket); - - let client = Client::tracked(rocket).await.unwrap(); - let login = client - .post("/auth") - .header(ContentType::Form) // Set the content type to form - .body("name=admin&password=admin"); // Add the form data to the request body; - login.dispatch().await; - - let req = client.get("/log"); - let response = req.dispatch().await; - - let text = response.into_string().await.unwrap(); - assert!(text.contains("Logbuch")); - assert!(text.contains("Neue Ausfahrt")); - } - - #[sqlx::test] - fn test_show() { - let db = testdb!(); - - let rocket = rocket::build().manage(db.clone()); - let rocket = crate::tera::config(rocket); - - let client = Client::tracked(rocket).await.unwrap(); - let login = client - .post("/auth") - .header(ContentType::Form) // Set the content type to form - .body("name=admin&password=admin"); // Add the form data to the request body; - login.dispatch().await; - - let req = client.get("/log/show"); - let response = req.dispatch().await; - - let text = response.into_string().await.unwrap(); - println!("{text:?}"); - assert!(text.contains("Logbuch")); - assert!(text.contains("Joe")); - } - - #[sqlx::test] - fn test_show_kiosk() { - 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("/log/kiosk/ekrv2019/Linz"); - let _ = req.dispatch().await; - - let req = client.get("/log/show"); - let response = req.dispatch().await; - - let text = response.into_string().await.unwrap(); - assert!(text.contains("Logbuch")); - assert!(text.contains("Joe")); - } - - #[sqlx::test] - fn test_create() { - let db = testdb!(); - - let rocket = rocket::build().manage(db.clone()); - let rocket = crate::tera::config(rocket); - - let client = Client::tracked(rocket).await.unwrap(); - let login = client - .post("/auth") - .header(ContentType::Form) // Set the content type to form - .body("name=admin&password=admin"); // Add the form data to the request body; - login.dispatch().await; - - let req = client - .post("/log") - .header(ContentType::Form) - .body("boat_id=1&shipmaster=4&departure=2199-12-31T10:00"); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::SeeOther); - assert_eq!(response.headers().get("Location").next(), Some("/log")); - - let flash_cookie = response - .cookies() - .get("_flash") - .expect("Expected flash cookie"); - - assert_eq!( - flash_cookie.value(), - "7:successAusfahrt erfolgreich hinzugefügt" - ); - } - - #[sqlx::test] - fn test_home_kiosk() { - 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("/log/kiosk/ekrv2019/Linz"); - let _ = req.dispatch().await; - - let req = client - .post("/log/1") - .header(ContentType::Form) - .body("destination=Ottensheim&distance_in_km=25"); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::SeeOther); - assert_eq!(response.headers().get("Location").next(), Some("/log")); - - let flash_cookie = response - .cookies() - .get("_flash") - .expect("Expected flash cookie"); - - assert_eq!( - flash_cookie.value(), - "7:successAusfahrt korrekt eingetragen" - ); - } - - //Kiosk mode - // i see all boats - #[sqlx::test] - fn test_kiosks_sees_all_boats() { - 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("/log/kiosk/ekrv2019/Linz"); - let _ = req.dispatch().await; - - let req = client.get("/log"); - let response = req.dispatch().await; - - let text = response.into_string().await.unwrap(); - //Sees all boats stationed in Linz - assert!(text.contains("Haichenbach")); - assert!(text.contains("Joe")); - assert!(text.contains("Kaputtes Boot :-(")); - assert!(text.contains("Sehr kaputtes Boot :-((")); - assert!(text.contains("second_private_boat_from_rower")); - assert!(text.contains("private_boat_from_rower")); - - //Doesn't see the one's in Ottensheim - assert!(!text.contains("Ottensheim Boot")); - } - - #[sqlx::test] - fn test_kiosks_can_start_trips_with_all_boats() { - let db = testdb!(); - - let rocket = rocket::build().manage(db.clone()); - let rocket = crate::tera::config(rocket); - - sqlx::query("DELETE FROM logbook;") - .execute(&db) - .await - .unwrap(); - - let mut client = Client::tracked(rocket).await.unwrap(); - let req = client.get("/log/kiosk/ekrv2019/Linz"); - let _ = req.dispatch().await; - - can_start_and_end_trip(&db, &mut client, "Haichenbach".into(), "admin".into()).await; - can_start_and_end_trip(&db, &mut client, "Joe".into(), "admin".into()).await; - can_start_and_end_trip(&db, &mut client, "Kaputtes Boot :-(".into(), "admin".into()).await; - cant_start_trip( - &db, - &mut client, - "Sehr kaputtes Boot :-((".into(), - "admin".into(), - "Boot gesperrt".into(), - ) - .await; - can_start_and_end_trip( - &db, - &mut client, - "second_private_boat_from_rower".into(), - "rower".into(), - ) - .await; - } - - #[sqlx::test] - fn test_shipowner_can_allow_others_to_drive() { - let db = testdb!(); - - let rocket = rocket::build().manage(db.clone()); - let rocket = crate::tera::config(rocket); - - sqlx::query("DELETE FROM logbook;") - .execute(&db) - .await - .unwrap(); - - let client = Client::tracked(rocket).await.unwrap(); - let login = client - .post("/auth") - .header(ContentType::Form) // Set the content type to form - .body("name=rower&password=rower"); // Add the form data to the request body; - login.dispatch().await; - - // Owner can start trip: - let boat_id = Boat::find_by_name(&db, "private_boat_from_rower".into()) - .await - .unwrap() - .id; - let shipmaster_id = User::find_by_name(&db, "rower2".into()).await.unwrap().id; - - let req = client.post("/log").header(ContentType::Form).body(format!( - "boat_id={boat_id}&shipmaster={shipmaster_id}&departure=1199-12-31T10:00" - )); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::SeeOther); - assert_eq!(response.headers().get("Location").next(), Some("/log")); - - let flash_cookie = response - .cookies() - .get("_flash") - .expect("Expected flash cookie"); - - assert_eq!( - flash_cookie.value(), - "7:successAusfahrt erfolgreich hinzugefügt" - ); - - // Shipmaster can end it - let log_id = Logbook::highest_id(&db).await; - - let login = client - .post("/auth") - .header(ContentType::Form) // Set the content type to form - .body("name=rower2&password=rower"); // Add the form data to the request body; - login.dispatch().await; - - let req = client - .post(format!("/log/{log_id}")) - .header(ContentType::Form) - .body("destination=Ottensheim&distance_in_km=25"); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::SeeOther); - assert_eq!(response.headers().get("Location").next(), Some("/log")); - - let flash_cookie = response - .cookies() - .get("_flash") - .expect("Expected flash cookie"); - - assert_eq!( - flash_cookie.value(), - "7:successAusfahrt korrekt eingetragen" - ); - } - - #[sqlx::test] - fn test_normal_user_sees_appropriate_boats() { - let db = testdb!(); - - let rocket = rocket::build().manage(db.clone()); - let rocket = crate::tera::config(rocket); - - let mut client = Client::tracked(rocket).await.unwrap(); - let login = client - .post("/auth") - .header(ContentType::Form) // Set the content type to form - .body("name=rower&password=rower"); // Add the form data to the request body; - login.dispatch().await; - - let req = client.get("/log"); - let response = req.dispatch().await; - - let text = response.into_string().await.unwrap(); - - sqlx::query("DELETE FROM logbook;") - .execute(&db) - .await - .unwrap(); - - //Sees all 1x - assert!(text.contains("Haichenbach")); - can_start_and_end_trip(&db, &mut client, "Haichenbach".into(), "rower".into()).await; - - assert!(text.contains("private_boat_from_rower")); - can_start_and_end_trip( - &db, - &mut client, - "private_boat_from_rower".into(), - "rower".into(), - ) - .await; - - assert!(text.contains("second_private_boat_from_rower")); - can_start_and_end_trip( - &db, - &mut client, - "second_private_boat_from_rower".into(), - "rower".into(), - ) - .await; - - //Don't see anything else - assert!(!text.contains("Joe")); - cant_start_trip( - &db, - &mut client, - "Joe".into(), - "rower".into(), - "Schiffsführer darf dieses Boot nicht verwenden".into(), - ) - .await; - - assert!(!text.contains("Kaputtes Boot :-(")); - cant_start_trip( - &db, - &mut client, - "Kaputtes Boot :-(".into(), - "rower".into(), - "Schiffsführer darf dieses Boot nicht verwenden".into(), - ) - .await; - - assert!(!text.contains("Sehr kaputtes Boot :-((")); - cant_start_trip( - &db, - &mut client, - "Sehr kaputtes Boot :-((".into(), - "rower".into(), - "Boot gesperrt".into(), - ) - .await; - - assert!(!text.contains("Ottensheim Boot")); - cant_start_trip( - &db, - &mut client, - "Ottensheim Boot".into(), - "rower".into(), - "Schiffsführer darf dieses Boot nicht verwenden".into(), - ) - .await; - } - - #[sqlx::test] - fn test_cox_sees_appropriate_boats() { - let db = testdb!(); - - let rocket = rocket::build().manage(db.clone()); - let rocket = crate::tera::config(rocket); - - let mut client = Client::tracked(rocket).await.unwrap(); - let login = client - .post("/auth") - .header(ContentType::Form) // Set the content type to form - .body("name=cox&password=cox"); // Add the form data to the request body; - login.dispatch().await; - - sqlx::query("DELETE FROM logbook;") - .execute(&db) - .await - .unwrap(); - - let req = client.get("/log"); - let response = req.dispatch().await; - - let text = response.into_string().await.unwrap(); - - //Sees all 1x - assert!(text.contains("Haichenbach")); - can_start_and_end_trip(&db, &mut client, "Haichenbach".into(), "cox".into()).await; - - assert!(text.contains("Joe")); - can_start_and_end_trip(&db, &mut client, "Joe".into(), "cox".into()).await; - - assert!(text.contains("Kaputtes Boot :-(")); - can_start_and_end_trip(&db, &mut client, "Kaputtes Boot :-(".into(), "cox".into()).await; - - assert!(text.contains("Sehr kaputtes Boot :-((")); - cant_start_trip( - &db, - &mut client, - "Sehr kaputtes Boot :-((".into(), - "cox".into(), - "Boot gesperrt".into(), - ) - .await; - - assert!(text.contains("Ottensheim Boot")); - can_start_and_end_trip(&db, &mut client, "Ottensheim Boot".into(), "cox".into()).await; - - //Can't use private boats - assert!(!text.contains("private_boat_from_rower")); - cant_start_trip( - &db, - &mut client, - "private_boat_from_rower".into(), - "cox".into(), - "Schiffsführer darf dieses Boot nicht verwenden".into(), - ) - .await; - - assert!(!text.contains("second_private_boat_from_rower")); - cant_start_trip( - &db, - &mut client, - "second_private_boat_from_rower".into(), - "cox".into(), - "Schiffsführer darf dieses Boot nicht verwenden".into(), - ) - .await; - } - - #[sqlx::test] - fn test_cant_end_trip_other_user() { - let db = testdb!(); - - let rocket = rocket::build().manage(db.clone()); - let rocket = crate::tera::config(rocket); - - let client = Client::tracked(rocket).await.unwrap(); - let login = client - .post("/auth") - .header(ContentType::Form) // Set the content type to form - .body("name=rower2&password=rower"); // Add the form data to the request body; - login.dispatch().await; - - let req = client - .post("/log/1") - .header(ContentType::Form) - .body("destination=Ottensheim&distance_in_km=25"); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::SeeOther); - assert_eq!(response.headers().get("Location").next(), Some("/log")); - - let flash_cookie = response - .cookies() - .get("_flash") - .expect("Expected flash cookie"); - - assert_eq!( - flash_cookie.value(), - "5:errorEintrag 1 konnte nicht abgesendet werden!" - ); - } - - async fn can_start_and_end_trip( - db: &SqlitePool, - client: &mut Client, - boat_name: String, - shipmaster_name: String, - ) { - let boat_id = Boat::find_by_name(db, boat_name).await.unwrap().id; - let shipmaster_id = User::find_by_name(db, &shipmaster_name).await.unwrap().id; - - let req = client.post("/log").header(ContentType::Form).body(format!( - "boat_id={boat_id}&shipmaster={shipmaster_id}&departure=1199-12-31T10:00" - )); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::SeeOther); - assert_eq!(response.headers().get("Location").next(), Some("/log")); - - let flash_cookie = response - .cookies() - .get("_flash") - .expect("Expected flash cookie"); - - assert_eq!( - flash_cookie.value(), - "7:successAusfahrt erfolgreich hinzugefügt" - ); - - let log_id = Logbook::highest_id(db).await; - - let req = client - .post(format!("/log/{log_id}")) - .header(ContentType::Form) - .body("destination=Ottensheim&distance_in_km=25"); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::SeeOther); - assert_eq!(response.headers().get("Location").next(), Some("/log")); - - let flash_cookie = response - .cookies() - .get("_flash") - .expect("Expected flash cookie"); - - assert_eq!( - flash_cookie.value(), - "7:successAusfahrt korrekt eingetragen" - ); - } - - async fn cant_start_trip( - db: &SqlitePool, - client: &mut Client, - boat_name: String, - shipmaster_name: String, - reason: String, - ) { - let boat_id = Boat::find_by_name(db, boat_name).await.unwrap().id; - let shipmaster_id = User::find_by_name(db, &shipmaster_name).await.unwrap().id; - - let req = client.post("/log").header(ContentType::Form).body(format!( - "boat_id={boat_id}&shipmaster={shipmaster_id}&departure=2199-12-31T10:00" - )); - let response = req.dispatch().await; - - assert_eq!(response.status(), Status::SeeOther); - assert_eq!(response.headers().get("Location").next(), Some("/log")); - - let flash_cookie = response - .cookies() - .get("_flash") - .expect("Expected flash cookie"); - - assert_eq!(flash_cookie.value(), format!("5:error{}", reason)); - } -} +//#[cfg(test)] +//mod test { +// use rocket::http::ContentType; +// use rocket::{http::Status, local::asynchronous::Client}; +// use sqlx::SqlitePool; +// +// use crate::model::logbook::Logbook; +// use crate::tera::{log::Boat, User}; +// use crate::testdb; +// +// #[sqlx::test] +// fn test_kiosk_cookie() { +// 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("/log"); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::SeeOther); +// assert_eq!(response.headers().get("Location").next(), Some("/auth")); +// +// let req = client.get("/log/kiosk/ekrv2019/Linz"); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::SeeOther); +// assert_eq!(response.headers().get("Location").next(), Some("/log")); +// +// let req = client.get("/log"); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::Ok); +// let text = response.into_string().await.unwrap(); +// assert!(text.contains("Logbuch")); +// assert!(text.contains("Neue Ausfahrt")); +// +// assert!(!text.contains("Ottensheim Boot")); +// } +// +// #[sqlx::test] +// fn test_kiosk_cookie_boat() { +// 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("/log/kiosk/ekrv2019/Ottensheim"); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::SeeOther); +// assert_eq!(response.headers().get("Location").next(), Some("/log")); +// +// let req = client.get("/log"); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::Ok); +// let text = response.into_string().await.unwrap(); +// assert!(text.contains("Logbuch")); +// assert!(text.contains("Neue Ausfahrt")); +// +// assert!(text.contains("Ottensheim Boot")); +// } +// +// #[sqlx::test] +// fn test_index() { +// let db = testdb!(); +// +// let rocket = rocket::build().manage(db.clone()); +// let rocket = crate::tera::config(rocket); +// +// let client = Client::tracked(rocket).await.unwrap(); +// let login = client +// .post("/auth") +// .header(ContentType::Form) // Set the content type to form +// .body("name=admin&password=admin"); // Add the form data to the request body; +// login.dispatch().await; +// +// let req = client.get("/log"); +// let response = req.dispatch().await; +// +// let text = response.into_string().await.unwrap(); +// assert!(text.contains("Logbuch")); +// assert!(text.contains("Neue Ausfahrt")); +// } +// +// #[sqlx::test] +// fn test_show() { +// let db = testdb!(); +// +// let rocket = rocket::build().manage(db.clone()); +// let rocket = crate::tera::config(rocket); +// +// let client = Client::tracked(rocket).await.unwrap(); +// let login = client +// .post("/auth") +// .header(ContentType::Form) // Set the content type to form +// .body("name=admin&password=admin"); // Add the form data to the request body; +// login.dispatch().await; +// +// let req = client.get("/log/show"); +// let response = req.dispatch().await; +// +// let text = response.into_string().await.unwrap(); +// println!("{text:?}"); +// assert!(text.contains("Logbuch")); +// assert!(text.contains("Joe")); +// } +// +// #[sqlx::test] +// fn test_show_kiosk() { +// 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("/log/kiosk/ekrv2019/Linz"); +// let _ = req.dispatch().await; +// +// let req = client.get("/log/show"); +// let response = req.dispatch().await; +// +// let text = response.into_string().await.unwrap(); +// assert!(text.contains("Logbuch")); +// assert!(text.contains("Joe")); +// } +// +// #[sqlx::test] +// fn test_create() { +// let db = testdb!(); +// +// let rocket = rocket::build().manage(db.clone()); +// let rocket = crate::tera::config(rocket); +// +// let client = Client::tracked(rocket).await.unwrap(); +// let login = client +// .post("/auth") +// .header(ContentType::Form) // Set the content type to form +// .body("name=admin&password=admin"); // Add the form data to the request body; +// login.dispatch().await; +// +// let req = client +// .post("/log") +// .header(ContentType::Form) +// .body("boat_id=1&shipmaster=4&departure=2199-12-31T10:00"); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::SeeOther); +// assert_eq!(response.headers().get("Location").next(), Some("/log")); +// +// let flash_cookie = response +// .cookies() +// .get("_flash") +// .expect("Expected flash cookie"); +// +// assert_eq!( +// flash_cookie.value(), +// "7:successAusfahrt erfolgreich hinzugefügt" +// ); +// } +// +// #[sqlx::test] +// fn test_home_kiosk() { +// 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("/log/kiosk/ekrv2019/Linz"); +// let _ = req.dispatch().await; +// +// let req = client +// .post("/log/1") +// .header(ContentType::Form) +// .body("destination=Ottensheim&distance_in_km=25"); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::SeeOther); +// assert_eq!(response.headers().get("Location").next(), Some("/log")); +// +// let flash_cookie = response +// .cookies() +// .get("_flash") +// .expect("Expected flash cookie"); +// +// assert_eq!( +// flash_cookie.value(), +// "7:successAusfahrt korrekt eingetragen" +// ); +// } +// +// //Kiosk mode +// // i see all boats +// #[sqlx::test] +// fn test_kiosks_sees_all_boats() { +// 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("/log/kiosk/ekrv2019/Linz"); +// let _ = req.dispatch().await; +// +// let req = client.get("/log"); +// let response = req.dispatch().await; +// +// let text = response.into_string().await.unwrap(); +// //Sees all boats stationed in Linz +// assert!(text.contains("Haichenbach")); +// assert!(text.contains("Joe")); +// assert!(text.contains("Kaputtes Boot :-(")); +// assert!(text.contains("Sehr kaputtes Boot :-((")); +// assert!(text.contains("second_private_boat_from_rower")); +// assert!(text.contains("private_boat_from_rower")); +// +// //Doesn't see the one's in Ottensheim +// assert!(!text.contains("Ottensheim Boot")); +// } +// +// #[sqlx::test] +// fn test_kiosks_can_start_trips_with_all_boats() { +// let db = testdb!(); +// +// let rocket = rocket::build().manage(db.clone()); +// let rocket = crate::tera::config(rocket); +// +// sqlx::query("DELETE FROM logbook;") +// .execute(&db) +// .await +// .unwrap(); +// +// let mut client = Client::tracked(rocket).await.unwrap(); +// let req = client.get("/log/kiosk/ekrv2019/Linz"); +// let _ = req.dispatch().await; +// +// can_start_and_end_trip(&db, &mut client, "Haichenbach".into(), "admin".into()).await; +// can_start_and_end_trip(&db, &mut client, "Joe".into(), "admin".into()).await; +// can_start_and_end_trip(&db, &mut client, "Kaputtes Boot :-(".into(), "admin".into()).await; +// cant_start_trip( +// &db, +// &mut client, +// "Sehr kaputtes Boot :-((".into(), +// "admin".into(), +// "Boot gesperrt".into(), +// ) +// .await; +// can_start_and_end_trip( +// &db, +// &mut client, +// "second_private_boat_from_rower".into(), +// "rower".into(), +// ) +// .await; +// } +// +// #[sqlx::test] +// fn test_shipowner_can_allow_others_to_drive() { +// let db = testdb!(); +// +// let rocket = rocket::build().manage(db.clone()); +// let rocket = crate::tera::config(rocket); +// +// sqlx::query("DELETE FROM logbook;") +// .execute(&db) +// .await +// .unwrap(); +// +// let client = Client::tracked(rocket).await.unwrap(); +// let login = client +// .post("/auth") +// .header(ContentType::Form) // Set the content type to form +// .body("name=rower&password=rower"); // Add the form data to the request body; +// login.dispatch().await; +// +// // Owner can start trip: +// let boat_id = Boat::find_by_name(&db, "private_boat_from_rower".into()) +// .await +// .unwrap() +// .id; +// let shipmaster_id = User::find_by_name(&db, "rower2".into()).await.unwrap().id; +// +// let req = client.post("/log").header(ContentType::Form).body(format!( +// "boat_id={boat_id}&shipmaster={shipmaster_id}&departure=1199-12-31T10:00" +// )); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::SeeOther); +// assert_eq!(response.headers().get("Location").next(), Some("/log")); +// +// let flash_cookie = response +// .cookies() +// .get("_flash") +// .expect("Expected flash cookie"); +// +// assert_eq!( +// flash_cookie.value(), +// "7:successAusfahrt erfolgreich hinzugefügt" +// ); +// +// // Shipmaster can end it +// let log_id = Logbook::highest_id(&db).await; +// +// let login = client +// .post("/auth") +// .header(ContentType::Form) // Set the content type to form +// .body("name=rower2&password=rower"); // Add the form data to the request body; +// login.dispatch().await; +// +// let req = client +// .post(format!("/log/{log_id}")) +// .header(ContentType::Form) +// .body("destination=Ottensheim&distance_in_km=25"); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::SeeOther); +// assert_eq!(response.headers().get("Location").next(), Some("/log")); +// +// let flash_cookie = response +// .cookies() +// .get("_flash") +// .expect("Expected flash cookie"); +// +// assert_eq!( +// flash_cookie.value(), +// "7:successAusfahrt korrekt eingetragen" +// ); +// } +// +// #[sqlx::test] +// fn test_normal_user_sees_appropriate_boats() { +// let db = testdb!(); +// +// let rocket = rocket::build().manage(db.clone()); +// let rocket = crate::tera::config(rocket); +// +// let mut client = Client::tracked(rocket).await.unwrap(); +// let login = client +// .post("/auth") +// .header(ContentType::Form) // Set the content type to form +// .body("name=rower&password=rower"); // Add the form data to the request body; +// login.dispatch().await; +// +// let req = client.get("/log"); +// let response = req.dispatch().await; +// +// let text = response.into_string().await.unwrap(); +// +// sqlx::query("DELETE FROM logbook;") +// .execute(&db) +// .await +// .unwrap(); +// +// //Sees all 1x +// assert!(text.contains("Haichenbach")); +// can_start_and_end_trip(&db, &mut client, "Haichenbach".into(), "rower".into()).await; +// +// assert!(text.contains("private_boat_from_rower")); +// can_start_and_end_trip( +// &db, +// &mut client, +// "private_boat_from_rower".into(), +// "rower".into(), +// ) +// .await; +// +// assert!(text.contains("second_private_boat_from_rower")); +// can_start_and_end_trip( +// &db, +// &mut client, +// "second_private_boat_from_rower".into(), +// "rower".into(), +// ) +// .await; +// +// //Don't see anything else +// assert!(!text.contains("Joe")); +// cant_start_trip( +// &db, +// &mut client, +// "Joe".into(), +// "rower".into(), +// "Schiffsführer darf dieses Boot nicht verwenden".into(), +// ) +// .await; +// +// assert!(!text.contains("Kaputtes Boot :-(")); +// cant_start_trip( +// &db, +// &mut client, +// "Kaputtes Boot :-(".into(), +// "rower".into(), +// "Schiffsführer darf dieses Boot nicht verwenden".into(), +// ) +// .await; +// +// assert!(!text.contains("Sehr kaputtes Boot :-((")); +// cant_start_trip( +// &db, +// &mut client, +// "Sehr kaputtes Boot :-((".into(), +// "rower".into(), +// "Boot gesperrt".into(), +// ) +// .await; +// +// assert!(!text.contains("Ottensheim Boot")); +// cant_start_trip( +// &db, +// &mut client, +// "Ottensheim Boot".into(), +// "rower".into(), +// "Schiffsführer darf dieses Boot nicht verwenden".into(), +// ) +// .await; +// } +// +// #[sqlx::test] +// fn test_cox_sees_appropriate_boats() { +// let db = testdb!(); +// +// let rocket = rocket::build().manage(db.clone()); +// let rocket = crate::tera::config(rocket); +// +// let mut client = Client::tracked(rocket).await.unwrap(); +// let login = client +// .post("/auth") +// .header(ContentType::Form) // Set the content type to form +// .body("name=cox&password=cox"); // Add the form data to the request body; +// login.dispatch().await; +// +// sqlx::query("DELETE FROM logbook;") +// .execute(&db) +// .await +// .unwrap(); +// +// let req = client.get("/log"); +// let response = req.dispatch().await; +// +// let text = response.into_string().await.unwrap(); +// +// //Sees all 1x +// assert!(text.contains("Haichenbach")); +// can_start_and_end_trip(&db, &mut client, "Haichenbach".into(), "cox".into()).await; +// +// assert!(text.contains("Joe")); +// can_start_and_end_trip(&db, &mut client, "Joe".into(), "cox".into()).await; +// +// assert!(text.contains("Kaputtes Boot :-(")); +// can_start_and_end_trip(&db, &mut client, "Kaputtes Boot :-(".into(), "cox".into()).await; +// +// assert!(text.contains("Sehr kaputtes Boot :-((")); +// cant_start_trip( +// &db, +// &mut client, +// "Sehr kaputtes Boot :-((".into(), +// "cox".into(), +// "Boot gesperrt".into(), +// ) +// .await; +// +// assert!(text.contains("Ottensheim Boot")); +// can_start_and_end_trip(&db, &mut client, "Ottensheim Boot".into(), "cox".into()).await; +// +// //Can't use private boats +// assert!(!text.contains("private_boat_from_rower")); +// cant_start_trip( +// &db, +// &mut client, +// "private_boat_from_rower".into(), +// "cox".into(), +// "Schiffsführer darf dieses Boot nicht verwenden".into(), +// ) +// .await; +// +// assert!(!text.contains("second_private_boat_from_rower")); +// cant_start_trip( +// &db, +// &mut client, +// "second_private_boat_from_rower".into(), +// "cox".into(), +// "Schiffsführer darf dieses Boot nicht verwenden".into(), +// ) +// .await; +// } +// +// #[sqlx::test] +// fn test_cant_end_trip_other_user() { +// let db = testdb!(); +// +// let rocket = rocket::build().manage(db.clone()); +// let rocket = crate::tera::config(rocket); +// +// let client = Client::tracked(rocket).await.unwrap(); +// let login = client +// .post("/auth") +// .header(ContentType::Form) // Set the content type to form +// .body("name=rower2&password=rower"); // Add the form data to the request body; +// login.dispatch().await; +// +// let req = client +// .post("/log/1") +// .header(ContentType::Form) +// .body("destination=Ottensheim&distance_in_km=25"); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::SeeOther); +// assert_eq!(response.headers().get("Location").next(), Some("/log")); +// +// let flash_cookie = response +// .cookies() +// .get("_flash") +// .expect("Expected flash cookie"); +// +// assert_eq!( +// flash_cookie.value(), +// "5:errorEintrag 1 konnte nicht abgesendet werden!" +// ); +// } +// +// async fn can_start_and_end_trip( +// db: &SqlitePool, +// client: &mut Client, +// boat_name: String, +// shipmaster_name: String, +// ) { +// let boat_id = Boat::find_by_name(db, boat_name).await.unwrap().id; +// let shipmaster_id = User::find_by_name(db, &shipmaster_name).await.unwrap().id; +// +// let req = client.post("/log").header(ContentType::Form).body(format!( +// "boat_id={boat_id}&shipmaster={shipmaster_id}&departure=1199-12-31T10:00" +// )); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::SeeOther); +// assert_eq!(response.headers().get("Location").next(), Some("/log")); +// +// let flash_cookie = response +// .cookies() +// .get("_flash") +// .expect("Expected flash cookie"); +// +// assert_eq!( +// flash_cookie.value(), +// "7:successAusfahrt erfolgreich hinzugefügt" +// ); +// +// let log_id = Logbook::highest_id(db).await; +// +// let req = client +// .post(format!("/log/{log_id}")) +// .header(ContentType::Form) +// .body("destination=Ottensheim&distance_in_km=25"); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::SeeOther); +// assert_eq!(response.headers().get("Location").next(), Some("/log")); +// +// let flash_cookie = response +// .cookies() +// .get("_flash") +// .expect("Expected flash cookie"); +// +// assert_eq!( +// flash_cookie.value(), +// "7:successAusfahrt korrekt eingetragen" +// ); +// } +// +// async fn cant_start_trip( +// db: &SqlitePool, +// client: &mut Client, +// boat_name: String, +// shipmaster_name: String, +// reason: String, +// ) { +// let boat_id = Boat::find_by_name(db, boat_name).await.unwrap().id; +// let shipmaster_id = User::find_by_name(db, &shipmaster_name).await.unwrap().id; +// +// let req = client.post("/log").header(ContentType::Form).body(format!( +// "boat_id={boat_id}&shipmaster={shipmaster_id}&departure=2199-12-31T10:00" +// )); +// let response = req.dispatch().await; +// +// assert_eq!(response.status(), Status::SeeOther); +// assert_eq!(response.headers().get("Location").next(), Some("/log")); +// +// let flash_cookie = response +// .cookies() +// .get("_flash") +// .expect("Expected flash cookie"); +// +// assert_eq!(flash_cookie.value(), format!("5:error{}", reason)); +// } +//}