create new tests for /cox/trip/<id>

This commit is contained in:
philipp 2023-07-23 14:21:27 +02:00
parent 1d4c5f356d
commit 3259582aab
3 changed files with 117 additions and 3 deletions

View File

@ -90,7 +90,7 @@ user_details
- [x] (join) GET /join/<trip_details_id>
- [x] (remove) GET /remove/<trip_details_id>
- [x] (create) POST /cox/trip
- [ ] (update) POST /cox/trip/<trip_id>
- [x] (update) POST /cox/trip/<trip_id>
- [ ] (join) GET /cox/join/<planned_event_id>
- [ ] (remove) GET /cox/remove/<planned_event_id>
- [ ] (remove_trip) GET /cox/remove/trip/<trip_id>

View File

@ -16,9 +16,9 @@ pub struct Trip {
cox_name: String,
trip_details_id: Option<i64>,
planned_starting_time: String,
max_people: i64,
pub max_people: i64,
day: String,
notes: Option<String>,
pub notes: Option<String>,
pub allow_guests: bool,
trip_type_id: Option<i64>,
}

View File

@ -218,4 +218,118 @@ mod test {
.len()
);
}
#[sqlx::test]
fn test_trip_update_succ() {
let db = testdb!();
let trip = &Trip::get_for_day(&db, NaiveDate::from_ymd_opt(1970, 01, 02).unwrap()).await[0];
assert_eq!(1, trip.trip.max_people);
assert_eq!(
"trip_details for trip from cox",
&trip.trip.notes.clone().unwrap()
);
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=cox&password=cox"); // Add the form data to the request body;
login.dispatch().await;
let req = client
.post("/cox/trip/1")
.header(ContentType::Form)
.body("notes=my-new-notes&max_people=12");
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:successAusfahrt erfolgreich aktualisiert."
);
let trip = &Trip::get_for_day(&db, NaiveDate::from_ymd_opt(1970, 01, 02).unwrap()).await[0];
assert_eq!(12, trip.trip.max_people);
assert_eq!("my-new-notes", &trip.trip.notes.clone().unwrap());
}
#[sqlx::test]
fn test_trip_update_wrong_event() {
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=cox&password=cox"); // Add the form data to the request body;
login.dispatch().await;
let req = client
.post("/cox/trip/9999")
.header(ContentType::Form)
.body("notes=my-new-notes&max_people=12");
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:errorAusfahrt gibt's nicht");
}
#[sqlx::test]
fn test_trip_update_wrong_cox() {
let db = testdb!();
let trip = &Trip::get_for_day(&db, NaiveDate::from_ymd_opt(1970, 01, 02).unwrap()).await[0];
assert_eq!(1, trip.trip.max_people);
assert_eq!(
"trip_details for trip from cox",
&trip.trip.notes.clone().unwrap()
);
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=cox2&password=cox"); // Add the form data to the request body;
login.dispatch().await;
let req = client
.post("/cox/trip/1")
.header(ContentType::Form)
.body("notes=my-new-notes&max_people=12");
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:errorNicht deine Ausfahrt!");
}
}