forked from Ruderverein-Donau-Linz/rowt
add test
This commit is contained in:
parent
fdf211c228
commit
c43feb1834
@ -94,7 +94,7 @@ user_details
|
||||
- [x] (remove) GET /remove/<trip_details_id>
|
||||
- [x] (create) POST /cox/trip
|
||||
- [x] (update) POST /cox/trip/<trip_id>
|
||||
- [ ] (join) GET /cox/join/<planned_event_id>
|
||||
- [x] (join) GET /cox/join/<planned_event_id>
|
||||
- [ ] (remove) GET /cox/remove/<planned_event_id>
|
||||
- [ ] (remove_trip) GET /cox/remove/trip/<trip_id>
|
||||
- [ ] (index) GET /auth/
|
||||
|
103
src/tera/cox.rs
103
src/tera/cox.rs
@ -345,4 +345,107 @@ mod test {
|
||||
|
||||
assert_eq!(flash_cookie.value(), "5:errorNicht deine Ausfahrt!");
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_trip_join() {
|
||||
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.get("/cox/join/1");
|
||||
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:successDanke für's helfen!");
|
||||
|
||||
let req = client.get("/cox/join/1");
|
||||
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:errorDu hilfst bereits aus!");
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_trip_join_already_rower() {
|
||||
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.get("/join/1");
|
||||
let response = req.dispatch().await;
|
||||
|
||||
let req = client.get("/cox/join/1");
|
||||
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:errorDu hast dich bereits als Ruderer angemeldet!"
|
||||
);
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_trip_join_invalid_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.get("/cox/join/9999");
|
||||
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:errorEvent gibt's nicht");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user