forked from Ruderverein-Donau-Linz/rowt
update unit tests; add location name in kiosk settting to cookie (to avoid specific redirects)
This commit is contained in:
parent
e459a4e2d9
commit
7309b1f2b2
@ -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 ('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 ('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 ('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 ('Wanderfahrt');
|
||||||
INSERT INTO "logbook_type" (name) VALUES ('Regatta');
|
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');
|
INSERT INTO "logbook" (boat_id, shipmaster, shipmaster_only_steering, departure) VALUES (2, 2, false, '2142-12-24 10:00');
|
||||||
|
@ -63,13 +63,14 @@ pub struct BoatToUpdate<'r> {
|
|||||||
|
|
||||||
impl Boat {
|
impl Boat {
|
||||||
pub async fn find_by_id(db: &SqlitePool, id: i32) -> Option<Self> {
|
pub async fn find_by_id(db: &SqlitePool, id: i32) -> Option<Self> {
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(Self, "SELECT * FROM boat WHERE id like ?", id)
|
||||||
Self,
|
.fetch_one(db)
|
||||||
"SELECT id, name, amount_seats, location_id, owner, year_built, boatbuilder, default_shipmaster_only_steering, skull, external
|
.await
|
||||||
FROM boat
|
.ok()
|
||||||
WHERE id like ?",
|
}
|
||||||
id
|
|
||||||
)
|
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)
|
.fetch_one(db)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
|
@ -239,6 +239,9 @@ mod test {
|
|||||||
|
|
||||||
let rocket = rocket::build().manage(db.clone());
|
let rocket = rocket::build().manage(db.clone());
|
||||||
let rocket = crate::tera::config(rocket);
|
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 client = Client::tracked(rocket).await.unwrap();
|
||||||
let login = client
|
let login = client
|
||||||
@ -266,8 +269,9 @@ mod test {
|
|||||||
|
|
||||||
assert_eq!(flash_cookie.value(), "7:successSuccessfully created boat");
|
assert_eq!(flash_cookie.value(), "7:successSuccessfully created boat");
|
||||||
|
|
||||||
let boat = Boat::find_by_id(&db, 6).await.unwrap();
|
Boat::find_by_name(&db, "completely-new-boat".into())
|
||||||
assert_eq!(boat.name, "completely-new-boat");
|
.await
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sqlx::test]
|
#[sqlx::test]
|
||||||
|
@ -241,7 +241,7 @@ mod test {
|
|||||||
assert_eq!(response.status(), Status::SeeOther);
|
assert_eq!(response.status(), Status::SeeOther);
|
||||||
assert_eq!(response.headers().get("Location").next(), Some("/auth"));
|
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;
|
let response = req.dispatch().await;
|
||||||
|
|
||||||
assert_eq!(response.status(), Status::SeeOther);
|
assert_eq!(response.status(), Status::SeeOther);
|
||||||
@ -254,6 +254,33 @@ mod test {
|
|||||||
let text = response.into_string().await.unwrap();
|
let text = response.into_string().await.unwrap();
|
||||||
assert!(text.contains("Logbuch"));
|
assert!(text.contains("Logbuch"));
|
||||||
assert!(text.contains("Neue Ausfahrt"));
|
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]
|
#[sqlx::test]
|
||||||
@ -308,7 +335,7 @@ mod test {
|
|||||||
let rocket = crate::tera::config(rocket);
|
let rocket = crate::tera::config(rocket);
|
||||||
|
|
||||||
let client = Client::tracked(rocket).await.unwrap();
|
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.dispatch().await;
|
||||||
|
|
||||||
let req = client.get("/log/show");
|
let req = client.get("/log/show");
|
||||||
@ -361,7 +388,7 @@ mod test {
|
|||||||
let rocket = crate::tera::config(rocket);
|
let rocket = crate::tera::config(rocket);
|
||||||
|
|
||||||
let client = Client::tracked(rocket).await.unwrap();
|
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.dispatch().await;
|
||||||
|
|
||||||
let req = client
|
let req = client
|
||||||
|
Loading…
x
Reference in New Issue
Block a user