2023-04-04 15:16:21 +02:00
use rocket ::{
form ::Form ,
get , post ,
response ::{ Flash , Redirect } ,
routes , FromForm , Route , State ,
} ;
use sqlx ::SqlitePool ;
2023-04-05 21:49:48 +02:00
use crate ::model ::{
2024-05-28 09:08:48 +02:00
event ::Event ,
2023-04-18 12:10:11 +02:00
log ::Log ,
2024-05-22 00:13:23 +02:00
trip ::{ self , CoxHelpError , Trip , TripDeleteError , TripHelpDeleteError , TripUpdateError } ,
2023-07-25 13:22:11 +02:00
tripdetails ::{ TripDetails , TripDetailsToAdd } ,
2023-04-05 21:49:48 +02:00
user ::CoxUser ,
} ;
2023-04-04 15:16:21 +02:00
#[ post( " /trip " , data = " <data> " ) ]
2023-05-24 12:11:55 +02:00
async fn create (
db : & State < SqlitePool > ,
2023-07-25 13:22:11 +02:00
data : Form < TripDetailsToAdd < '_ > > ,
2023-05-24 12:11:55 +02:00
cox : CoxUser ,
) -> Flash < Redirect > {
2023-07-25 13:22:11 +02:00
let trip_details_id = TripDetails ::create ( db , data . into_inner ( ) ) . await ;
2023-04-26 16:54:53 +02:00
let trip_details = TripDetails ::find_by_id ( db , trip_details_id ) . await . unwrap ( ) ; //Okay, bc just
//created
2023-07-25 13:22:11 +02:00
Trip ::new_own ( db , & cox , trip_details ) . await ; //TODO: fix
2023-04-04 15:16:21 +02:00
2023-07-25 13:22:11 +02:00
//Log::create(
// db,
// format!(
// "Cox {} created trip on {} @ {} for {} rower",
// cox.name, trip_details.day, trip_details.planned_starting_time, trip_details.max_people,
// ),
//)
//.await;
2023-04-18 12:10:11 +02:00
2024-01-22 19:27:22 +01:00
Flash ::success ( Redirect ::to ( " /planned " ) , " Ausfahrt erfolgreich erstellt. " )
2023-04-07 11:54:56 +02:00
}
#[ derive(FromForm) ]
2023-05-24 12:11:55 +02:00
struct EditTripForm < ' r > {
2023-04-07 11:54:56 +02:00
max_people : i32 ,
2023-05-24 12:11:55 +02:00
notes : Option < & ' r str > ,
2023-05-03 16:51:37 +02:00
trip_type : Option < i64 > ,
2023-07-23 19:45:48 +02:00
always_show : bool ,
2023-08-09 11:54:18 +02:00
is_locked : bool ,
2023-04-07 11:54:56 +02:00
}
#[ post( " /trip/<trip_id> " , data = " <data> " ) ]
async fn update (
db : & State < SqlitePool > ,
2023-05-24 12:11:55 +02:00
data : Form < EditTripForm < '_ > > ,
2023-04-07 11:54:56 +02:00
trip_id : i64 ,
cox : CoxUser ,
) -> Flash < Redirect > {
2023-04-26 16:54:53 +02:00
if let Some ( trip ) = Trip ::find_by_id ( db , trip_id ) . await {
2024-05-22 00:13:23 +02:00
let update = trip ::TripUpdate {
cox : & cox ,
trip : & trip ,
max_people : data . max_people ,
notes : data . notes ,
trip_type : data . trip_type ,
always_show : data . always_show ,
is_locked : data . is_locked ,
} ;
match Trip ::update_own ( db , & update ) . await {
2024-01-22 19:27:22 +01:00
Ok ( _ ) = > Flash ::success (
Redirect ::to ( " /planned " ) ,
" Ausfahrt erfolgreich aktualisiert. " ,
) ,
2023-04-26 16:54:53 +02:00
Err ( TripUpdateError ::NotYourTrip ) = > {
2024-01-22 19:27:22 +01:00
Flash ::error ( Redirect ::to ( " /planned " ) , " Nicht deine Ausfahrt! " )
2023-04-26 16:54:53 +02:00
}
Err ( TripUpdateError ::TripDetailsDoesNotExist ) = > {
2024-01-22 19:27:22 +01:00
Flash ::error ( Redirect ::to ( " /planned " ) , " Ausfahrt gibt's nicht " )
2023-04-26 16:54:53 +02:00
}
2023-04-07 11:54:56 +02:00
}
2023-04-26 16:54:53 +02:00
} else {
2024-01-22 19:27:22 +01:00
Flash ::error ( Redirect ::to ( " /planned " ) , " Ausfahrt gibt's nicht " )
2023-04-07 11:54:56 +02:00
}
2023-04-04 15:16:21 +02:00
}
#[ get( " /join/<planned_event_id> " ) ]
async fn join ( db : & State < SqlitePool > , planned_event_id : i64 , cox : CoxUser ) -> Flash < Redirect > {
2024-05-28 09:08:48 +02:00
if let Some ( planned_event ) = Event ::find_by_id ( db , planned_event_id ) . await {
2023-04-26 16:54:53 +02:00
match Trip ::new_join ( db , & cox , & planned_event ) . await {
Ok ( _ ) = > {
Log ::create (
db ,
format! (
" Cox {} helps at planned_event.id={} " ,
cox . name , planned_event_id ,
) ,
)
. await ;
2024-01-22 19:27:22 +01:00
Flash ::success ( Redirect ::to ( " /planned " ) , " Danke für's helfen! " )
2023-04-26 16:54:53 +02:00
}
2024-05-21 22:16:42 +02:00
Err ( CoxHelpError ::CanceledEvent ) = > {
Flash ::error ( Redirect ::to ( " /planned " ) , " Die Ausfahrt wurde leider abgesagt... " )
}
2023-04-26 16:54:53 +02:00
Err ( CoxHelpError ::AlreadyRegisteredAsCox ) = > {
2024-01-22 19:27:22 +01:00
Flash ::error ( Redirect ::to ( " /planned " ) , " Du hilfst bereits aus! " )
2023-04-26 16:54:53 +02:00
}
Err ( CoxHelpError ::AlreadyRegisteredAsRower ) = > Flash ::error (
2024-01-22 19:27:22 +01:00
Redirect ::to ( " /planned " ) ,
2023-04-26 16:54:53 +02:00
" Du hast dich bereits als Ruderer angemeldet! " ,
) ,
2023-08-09 11:54:18 +02:00
Err ( CoxHelpError ::DetailsLocked ) = > {
2024-04-19 08:45:56 +02:00
Flash ::error ( Redirect ::to ( " /planned " ) , " Die Bootseinteilung wurde bereits gemacht. Wenn du noch steuern möchtest, frag bitte bei einer bereits angemeldeten Steuerperson nach, ob das noch möglich ist. " )
2023-08-09 11:54:18 +02:00
}
2023-04-18 12:10:11 +02:00
}
2023-04-26 16:54:53 +02:00
} else {
2024-01-22 19:27:22 +01:00
Flash ::error ( Redirect ::to ( " /planned " ) , " Event gibt's nicht " )
2023-04-04 15:16:21 +02:00
}
}
2023-04-07 11:16:39 +02:00
#[ get( " /remove/trip/<trip_id> " ) ]
async fn remove_trip ( db : & State < SqlitePool > , trip_id : i64 , cox : CoxUser ) -> Flash < Redirect > {
2023-04-26 16:54:53 +02:00
let trip = Trip ::find_by_id ( db , trip_id ) . await ;
match trip {
2024-01-22 19:27:22 +01:00
None = > Flash ::error ( Redirect ::to ( " /planned " ) , " Trip gibt's nicht! " ) ,
2023-04-26 16:54:53 +02:00
Some ( trip ) = > match trip . delete ( db , & cox ) . await {
Ok ( _ ) = > {
Log ::create ( db , format! ( " Cox {} deleted trip.id= {} " , cox . name , trip_id ) ) . await ;
2024-01-22 19:27:22 +01:00
Flash ::success ( Redirect ::to ( " /planned " ) , " Erfolgreich gelöscht! " )
2023-04-26 16:54:53 +02:00
}
Err ( TripDeleteError ::SomebodyAlreadyRegistered ) = > Flash ::error (
2024-01-22 19:27:22 +01:00
Redirect ::to ( " /planned " ) ,
2023-04-26 16:54:53 +02:00
" Ausfahrt kann nicht gelöscht werden, da bereits jemand registriert ist! " ,
) ,
Err ( TripDeleteError ::NotYourTrip ) = > {
2024-01-22 19:27:22 +01:00
Flash ::error ( Redirect ::to ( " /planned " ) , " Nicht deine Ausfahrt! " )
2023-04-26 16:54:53 +02:00
}
} ,
2023-04-07 11:16:39 +02:00
}
}
2023-04-04 15:16:21 +02:00
#[ get( " /remove/<planned_event_id> " ) ]
async fn remove ( db : & State < SqlitePool > , planned_event_id : i64 , cox : CoxUser ) -> Flash < Redirect > {
2024-05-28 09:08:48 +02:00
if let Some ( planned_event ) = Event ::find_by_id ( db , planned_event_id ) . await {
2023-08-09 11:54:18 +02:00
match Trip ::delete_by_planned_event ( db , & cox , & planned_event ) . await {
Ok ( _ ) = > {
Log ::create (
db ,
format! (
" Cox {} deleted registration for planned_event.id={} " ,
cox . name , planned_event_id
) ,
)
. await ;
2023-07-31 13:34:02 +02:00
2024-01-22 19:27:22 +01:00
Flash ::success ( Redirect ::to ( " /planned " ) , " Erfolgreich abgemeldet! " )
2023-08-09 11:54:18 +02:00
}
Err ( TripHelpDeleteError ::DetailsLocked ) = > {
2024-04-19 08:45:56 +02:00
Flash ::error ( Redirect ::to ( " /planned " ) , " Die Bootseinteilung wurde bereits gemacht. Wenn du doch nicht steuern kannst, melde dich bitte unbedingt schnellstmöglich bei einer anderen Steuerperson! " )
2023-08-09 11:54:18 +02:00
}
Err ( TripHelpDeleteError ::CoxNotHelping ) = > {
2024-01-22 19:27:22 +01:00
Flash ::error ( Redirect ::to ( " /planned " ) , " Steuermann hilft nicht aus... " )
2023-08-09 11:54:18 +02:00
}
2023-07-31 13:34:02 +02:00
}
2023-04-26 16:54:53 +02:00
} else {
2024-01-22 19:27:22 +01:00
Flash ::error ( Redirect ::to ( " /planned " ) , " Planned_event does not exist. " )
2023-04-26 16:54:53 +02:00
}
2023-04-04 15:16:21 +02:00
}
pub fn routes ( ) -> Vec < Route > {
2023-04-07 11:54:56 +02:00
routes! [ create , join , remove , remove_trip , update ]
2023-04-04 15:16:21 +02:00
}
2023-07-21 10:26:50 +02:00
#[ cfg(test) ]
mod test {
use chrono ::NaiveDate ;
use rocket ::{
http ::{ ContentType , Status } ,
local ::asynchronous ::Client ,
} ;
use sqlx ::SqlitePool ;
use crate ::{ model ::trip ::Trip , testdb } ;
#[ sqlx::test ]
fn test_trip_create ( ) {
let db = testdb! ( ) ;
assert_eq! (
0 ,
Trip ::get_for_day ( & db , NaiveDate ::from_ymd_opt ( 2999 , 12 , 30 ) . unwrap ( ) )
. await
. len ( )
) ;
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 " )
. header ( ContentType ::Form )
. body ( " day=2999-12-30&planned_starting_time=12:34&max_people=42&allow_guests=false " ) ;
let response = req . dispatch ( ) . await ;
assert_eq! ( response . status ( ) , Status ::SeeOther ) ;
2024-01-22 19:27:22 +01:00
assert_eq! ( response . headers ( ) . get ( " Location " ) . next ( ) , Some ( " /planned " ) ) ;
2023-07-21 10:26:50 +02:00
let flash_cookie = response
. cookies ( )
. get ( " _flash " )
. expect ( " Expected flash cookie " ) ;
assert_eq! (
flash_cookie . value ( ) ,
" 7:successAusfahrt erfolgreich erstellt. "
) ;
assert_eq! (
1 ,
Trip ::get_for_day ( & db , NaiveDate ::from_ymd_opt ( 2999 , 12 , 30 ) . unwrap ( ) )
. await
. len ( )
) ;
}
2023-07-23 14:21:27 +02:00
#[ 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 ) ;
2024-01-22 19:27:22 +01:00
assert_eq! ( response . headers ( ) . get ( " Location " ) . next ( ) , Some ( " /planned " ) ) ;
2023-07-23 14:21:27 +02:00
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 ) ;
2024-01-22 19:27:22 +01:00
assert_eq! ( response . headers ( ) . get ( " Location " ) . next ( ) , Some ( " /planned " ) ) ;
2023-07-23 14:21:27 +02:00
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 ) ;
2024-01-22 19:27:22 +01:00
assert_eq! ( response . headers ( ) . get ( " Location " ) . next ( ) , Some ( " /planned " ) ) ;
2023-07-23 14:21:27 +02:00
let flash_cookie = response
. cookies ( )
. get ( " _flash " )
. expect ( " Expected flash cookie " ) ;
assert_eq! ( flash_cookie . value ( ) , " 5:errorNicht deine Ausfahrt! " ) ;
}
2023-07-24 09:40:28 +02:00
#[ 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 ) ;
2024-01-22 19:27:22 +01:00
assert_eq! ( response . headers ( ) . get ( " Location " ) . next ( ) , Some ( " /planned " ) ) ;
2023-07-24 09:40:28 +02:00
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 ) ;
2024-01-22 19:27:22 +01:00
assert_eq! ( response . headers ( ) . get ( " Location " ) . next ( ) , Some ( " /planned " ) ) ;
2023-07-24 09:40:28 +02:00
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 ;
2024-01-10 14:08:15 +01:00
let req = client . get ( " /planned/join/1 " ) ;
2023-07-25 13:22:11 +02:00
let _ = req . dispatch ( ) . await ;
2023-07-24 09:40:28 +02:00
let req = client . get ( " /cox/join/1 " ) ;
let response = req . dispatch ( ) . await ;
assert_eq! ( response . status ( ) , Status ::SeeOther ) ;
2024-01-22 19:27:22 +01:00
assert_eq! ( response . headers ( ) . get ( " Location " ) . next ( ) , Some ( " /planned " ) ) ;
2023-07-24 09:40:28 +02:00
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 ) ;
2024-01-22 19:27:22 +01:00
assert_eq! ( response . headers ( ) . get ( " Location " ) . next ( ) , Some ( " /planned " ) ) ;
2023-07-24 09:40:28 +02:00
let flash_cookie = response
. cookies ( )
. get ( " _flash " )
. expect ( " Expected flash cookie " ) ;
assert_eq! ( flash_cookie . value ( ) , " 5:errorEvent gibt's nicht " ) ;
}
2023-07-31 13:34:02 +02:00
#[ sqlx::test ]
fn test_remove ( ) {
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 ;
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 " ) ;
2023-07-31 16:59:15 +02:00
let _ = req . dispatch ( ) . await ;
2023-07-31 13:34:02 +02:00
let req = client . get ( " /cox/remove/1 " ) ;
let response = req . dispatch ( ) . await ;
assert_eq! ( response . status ( ) , Status ::SeeOther ) ;
2024-01-22 19:27:22 +01:00
assert_eq! ( response . headers ( ) . get ( " Location " ) . next ( ) , Some ( " /planned " ) ) ;
2023-07-31 13:34:02 +02:00
let flash_cookie = response
. cookies ( )
. get ( " _flash " )
. expect ( " Expected flash cookie " ) ;
assert_eq! ( flash_cookie . value ( ) , " 7:successErfolgreich abgemeldet! " ) ;
}
#[ sqlx::test ]
fn test_remove_wrong_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=cox&password=cox " ) ; // Add the form data to the request body;
login . dispatch ( ) . await ;
let req = client . get ( " /cox/remove/999 " ) ;
let response = req . dispatch ( ) . await ;
assert_eq! ( response . status ( ) , Status ::SeeOther ) ;
2024-01-22 19:27:22 +01:00
assert_eq! ( response . headers ( ) . get ( " Location " ) . next ( ) , Some ( " /planned " ) ) ;
2023-07-31 13:34:02 +02:00
let flash_cookie = response
. cookies ( )
. get ( " _flash " )
. expect ( " Expected flash cookie " ) ;
assert_eq! ( flash_cookie . value ( ) , " 5:errorPlanned_event does not exist. " ) ;
}
#[ sqlx::test ]
fn test_remove_cox_not_participating ( ) {
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/remove/1 " ) ;
let response = req . dispatch ( ) . await ;
assert_eq! ( response . status ( ) , Status ::SeeOther ) ;
2024-01-22 19:27:22 +01:00
assert_eq! ( response . headers ( ) . get ( " Location " ) . next ( ) , Some ( " /planned " ) ) ;
2023-07-31 13:34:02 +02:00
let flash_cookie = response
. cookies ( )
. get ( " _flash " )
. expect ( " Expected flash cookie " ) ;
assert_eq! ( flash_cookie . value ( ) , " 5:errorSteuermann hilft nicht aus... " ) ;
}
2023-07-21 10:26:50 +02:00
}