add tests for tera/admin/planned_event

Closes #20
This commit is contained in:
philipp 2023-07-31 21:29:03 +02:00
parent 8fa8e17c5a
commit da6a16cd66
4 changed files with 75 additions and 4 deletions

View File

@ -19,7 +19,7 @@ pub struct PlannedEvent {
pub planned_starting_time: String, pub planned_starting_time: String,
max_people: i64, max_people: i64,
pub day: String, pub day: String,
notes: Option<String>, pub notes: Option<String>,
pub allow_guests: bool, pub allow_guests: bool,
trip_type_id: Option<i64>, trip_type_id: Option<i64>,
always_show: bool, always_show: bool,

View File

@ -48,7 +48,7 @@ mod test {
#[sqlx::test] #[sqlx::test]
fn test_find_true() { fn test_find_true() {
let pool = testdb!(); let _ = testdb!();
} }
//TODO: write tests //TODO: write tests

View File

@ -164,4 +164,75 @@ mod test {
let _ = PlannedEvent::find_by_id(&db, 1).await.unwrap(); 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&notes=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&notes=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");
}
} }

View File

@ -309,7 +309,7 @@ mod test {
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");
let response = req.dispatch().await; let _ = req.dispatch().await;
let req = client.get("/log/show"); let req = client.get("/log/show");
let response = req.dispatch().await; let response = req.dispatch().await;
@ -362,7 +362,7 @@ mod test {
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");
let response = req.dispatch().await; let _ = req.dispatch().await;
let req = client let req = client
.post("/log/1") .post("/log/1")