update unit tests; add location name in kiosk settting to cookie (to avoid specific redirects)

This commit is contained in:
philipp 2023-08-05 13:21:35 +02:00
parent e459a4e2d9
commit 7309b1f2b2
4 changed files with 48 additions and 15 deletions

View File

@ -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');

View File

@ -63,16 +63,17 @@ pub struct BoatToUpdate<'r> {
impl Boat {
pub async fn find_by_id(db: &SqlitePool, id: i32) -> Option<Self> {
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<Self> {
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 {

View File

@ -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]

View File

@ -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