diff --git a/seeds.sql b/seeds.sql index b28cf02..c376a44 100644 --- a/seeds.sql +++ b/seeds.sql @@ -22,6 +22,7 @@ INSERT INTO "boat" (name, amount_seats, location_id, owner) VALUES ('private_boa INSERT INTO "boat" (name, amount_seats, location_id) VALUES ('Joe', 2, 1); INSERT INTO "boat" (name, amount_seats, location_id) VALUES ('Kaputtes Boot :-(', 7, 1); INSERT INTO "boat" (name, amount_seats, location_id) VALUES ('Sehr kaputtes Boot :-((', 7, 1); +INSERT INTO "boat" (name, amount_seats, location_id) VALUES ('Ottensheim Boot', 7, 2); INSERT INTO "logbook_type" (name) VALUES ('Wanderfahrt'); INSERT INTO "logbook_type" (name) VALUES ('Regatta'); INSERT INTO "logbook" (boat_id, shipmaster, shipmaster_only_steering, departure) VALUES (2, 2, false, '2142-12-24 10:00'); diff --git a/src/model/boat.rs b/src/model/boat.rs index 5e2cd5f..ef6755d 100644 --- a/src/model/boat.rs +++ b/src/model/boat.rs @@ -63,16 +63,17 @@ pub struct BoatToUpdate<'r> { impl Boat { pub async fn find_by_id(db: &SqlitePool, id: i32) -> Option { - sqlx::query_as!( - Self, - "SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external - FROM boat - WHERE id like ?", - id - ) - .fetch_one(db) - .await - .ok() + sqlx::query_as!(Self, "SELECT * FROM boat WHERE id like ?", id) + .fetch_one(db) + .await + .ok() + } + + pub async fn find_by_name(db: &SqlitePool, name: String) -> Option { + sqlx::query_as!(Self, "SELECT * FROM boat WHERE name like ?", name) + .fetch_one(db) + .await + .ok() } pub async fn is_locked(&self, db: &SqlitePool) -> bool { diff --git a/src/tera/admin/boat.rs b/src/tera/admin/boat.rs index d57cf19..6405520 100644 --- a/src/tera/admin/boat.rs +++ b/src/tera/admin/boat.rs @@ -239,6 +239,9 @@ mod test { let rocket = rocket::build().manage(db.clone()); let rocket = crate::tera::config(rocket); + assert!(Boat::find_by_name(&db, "completely-new-boat".into()) + .await + .is_none()); let client = Client::tracked(rocket).await.unwrap(); let login = client @@ -266,8 +269,9 @@ mod test { assert_eq!(flash_cookie.value(), "7:successSuccessfully created boat"); - let boat = Boat::find_by_id(&db, 6).await.unwrap(); - assert_eq!(boat.name, "completely-new-boat"); + Boat::find_by_name(&db, "completely-new-boat".into()) + .await + .unwrap(); } #[sqlx::test] diff --git a/src/tera/log.rs b/src/tera/log.rs index 91433bc..3d0cab5 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -241,7 +241,7 @@ mod test { assert_eq!(response.status(), Status::SeeOther); assert_eq!(response.headers().get("Location").next(), Some("/auth")); - let req = client.get("/log/kiosk/ekrv2019"); + let req = client.get("/log/kiosk/ekrv2019/Linz"); let response = req.dispatch().await; assert_eq!(response.status(), Status::SeeOther); @@ -254,6 +254,33 @@ mod test { 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] @@ -308,7 +335,7 @@ mod test { let rocket = crate::tera::config(rocket); let client = Client::tracked(rocket).await.unwrap(); - let req = client.get("/log/kiosk/ekrv2019"); + let req = client.get("/log/kiosk/ekrv2019/Linz"); let _ = req.dispatch().await; let req = client.get("/log/show"); @@ -361,7 +388,7 @@ mod test { let rocket = crate::tera::config(rocket); let client = Client::tracked(rocket).await.unwrap(); - let req = client.get("/log/kiosk/ekrv2019"); + let req = client.get("/log/kiosk/ekrv2019/Linz"); let _ = req.dispatch().await; let req = client