diff --git a/src/model/planned_event.rs b/src/model/planned_event.rs index d411744..3028724 100644 --- a/src/model/planned_event.rs +++ b/src/model/planned_event.rs @@ -19,7 +19,7 @@ pub struct PlannedEvent { pub planned_starting_time: String, max_people: i64, pub day: String, - notes: Option, + pub notes: Option, pub allow_guests: bool, trip_type_id: Option, always_show: bool, diff --git a/src/model/triptype.rs b/src/model/triptype.rs index f13e634..f7aaf94 100644 --- a/src/model/triptype.rs +++ b/src/model/triptype.rs @@ -48,7 +48,7 @@ mod test { #[sqlx::test] fn test_find_true() { - let pool = testdb!(); + let _ = testdb!(); } //TODO: write tests diff --git a/src/tera/admin/planned_event.rs b/src/tera/admin/planned_event.rs index bbd7684..9299982 100644 --- a/src/tera/admin/planned_event.rs +++ b/src/tera/admin/planned_event.rs @@ -164,4 +164,75 @@ mod test { let _ = PlannedEvent::find_by_id(&db, 1).await.unwrap(); } + + #[sqlx::test] + fn test_update() { + let db = testdb!(); + + let event = PlannedEvent::find_by_id(&db, 1).await.unwrap(); + assert_eq!(event.notes, Some("trip_details for a planned event".into())); + + 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 + .put("/admin/planned-event") + .header(ContentType::Form) // Set the content type to form + .body("id=1&planned_amount_cox=2&max_people=3¬es=new-planned-event-text"); // Add the form data to the request body; + let response = req.dispatch().await; + + assert_eq!(response.status(), Status::SeeOther); + assert_eq!(response.headers().get("Location").next(), Some("/")); + + let flash_cookie = response + .cookies() + .get("_flash") + .expect("Expected flash cookie"); + + assert_eq!( + flash_cookie.value(), + "7:successSuccessfully edited the event" + ); + + let event = PlannedEvent::find_by_id(&db, 1).await.unwrap(); + assert_eq!(event.notes, Some("new-planned-event-text".into())); + } + + #[sqlx::test] + fn test_update_invalid_id() { + 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 + .put("/admin/planned-event") + .header(ContentType::Form) // Set the content type to form + .body("id=1337&planned_amount_cox=2&max_people=3¬es=new-planned-event-text"); // Add the form data to the request body; + let response = req.dispatch().await; + + assert_eq!(response.status(), Status::SeeOther); + assert_eq!(response.headers().get("Location").next(), Some("/")); + + let flash_cookie = response + .cookies() + .get("_flash") + .expect("Expected flash cookie"); + + assert_eq!(flash_cookie.value(), "5:errorPlanned event id not found"); + } } diff --git a/src/tera/log.rs b/src/tera/log.rs index 1b1bbef..bc8a8df 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -309,7 +309,7 @@ mod test { let client = Client::tracked(rocket).await.unwrap(); let req = client.get("/log/kiosk/ekrv2019"); - let response = req.dispatch().await; + let _ = req.dispatch().await; let req = client.get("/log/show"); let response = req.dispatch().await; @@ -362,7 +362,7 @@ mod test { let client = Client::tracked(rocket).await.unwrap(); let req = client.get("/log/kiosk/ekrv2019"); - let response = req.dispatch().await; + let _ = req.dispatch().await; let req = client .post("/log/1")