fix-kiosk-error #885
| @@ -53,6 +53,7 @@ INSERT INTO "planned_event" (name, planned_amount_cox, trip_details_id) VALUES(' | |||||||
| INSERT INTO "trip_details" (planned_starting_time, max_people, day, notes) VALUES('11:00', 1, date('now', '+1 day'), 'trip_details for trip from cox'); | INSERT INTO "trip_details" (planned_starting_time, max_people, day, notes) VALUES('11:00', 1, date('now', '+1 day'), 'trip_details for trip from cox'); | ||||||
| INSERT INTO "trip" (cox_id, trip_details_id) VALUES(4, 2); | INSERT INTO "trip" (cox_id, trip_details_id) VALUES(4, 2); | ||||||
|  |  | ||||||
|  | INSERT INTO "trip_details" (planned_starting_time, max_people, day, notes) VALUES('10:00', 2, date('now'), 'same trip_details as id=1'); | ||||||
| INSERT INTO "trip_type" (name, desc, question, icon) VALUES ('Regatta', 'Regatta!', 'Kein normales Event. Das ist eine Regatta! Willst du wirklich teilnehmen?', '🏅'); | INSERT INTO "trip_type" (name, desc, question, icon) VALUES ('Regatta', 'Regatta!', 'Kein normales Event. Das ist eine Regatta! Willst du wirklich teilnehmen?', '🏅'); | ||||||
| INSERT INTO "trip_type" (name, desc, question, icon) VALUES ('Lange Ausfahrt', 'Lange Ausfahrt!', 'Das ist eine lange Ausfahrt! Willst du wirklich teilnehmen?', '💪'); | INSERT INTO "trip_type" (name, desc, question, icon) VALUES ('Lange Ausfahrt', 'Lange Ausfahrt!', 'Das ist eine lange Ausfahrt! Willst du wirklich teilnehmen?', '💪'); | ||||||
| INSERT INTO "trip_type" (name, desc, question, icon) VALUES ('Wanderfahrt', 'Wanderfahrt!', 'Kein normales Event. Das ist eine Wanderfahrt! Bitte überprüfe ob du alle Anforderungen erfüllst. Willst du wirklich teilnehmen?', '⛱'); | INSERT INTO "trip_type" (name, desc, question, icon) VALUES ('Wanderfahrt', 'Wanderfahrt!', 'Kein normales Event. Das ist eine Wanderfahrt! Bitte überprüfe ob du alle Anforderungen erfüllst. Willst du wirklich teilnehmen?', '⛱'); | ||||||
|   | |||||||
| @@ -292,7 +292,7 @@ mod test { | |||||||
|         assert_eq!(rower_notification.category, "Absage Ausfahrt"); |         assert_eq!(rower_notification.category, "Absage Ausfahrt"); | ||||||
|         assert_eq!( |         assert_eq!( | ||||||
|             rower_notification.action_after_reading.as_deref(), |             rower_notification.action_after_reading.as_deref(), | ||||||
|             Some("remove_user_trip_with_trip_details_id:3") |             Some("remove_user_trip_with_trip_details_id:4") | ||||||
|         ); |         ); | ||||||
|  |  | ||||||
|         // Cox received notification |         // Cox received notification | ||||||
|   | |||||||
| @@ -91,33 +91,31 @@ impl Trip { | |||||||
|             trip_details.planned_starting_time, |             trip_details.planned_starting_time, | ||||||
|         ) |         ) | ||||||
|         .await; |         .await; | ||||||
|         if same_starting_datetime.len() > 1 { |         for notify in same_starting_datetime { | ||||||
|             for notify in same_starting_datetime { |             // don't notify oneself | ||||||
|                 // don't notify oneself |             if notify.id == trip_details.id { | ||||||
|                 if notify.id == trip_details.id { |                 continue; | ||||||
|                     continue; |             } | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 // don't notify people who have cancelled their trip |             // don't notify people who have cancelled their trip | ||||||
|                 if notify.cancelled() { |             if notify.cancelled() { | ||||||
|                     continue; |                 continue; | ||||||
|                 } |             } | ||||||
|  |  | ||||||
|                 if let Some(trip) = Trip::find_by_trip_details(db, notify.id).await { |             if let Some(trip) = Trip::find_by_trip_details(db, notify.id).await { | ||||||
|                     let user_earlier_trip = User::find_by_id(db, trip.cox_id as i32).await.unwrap(); |                 let user_earlier_trip = User::find_by_id(db, trip.cox_id as i32).await.unwrap(); | ||||||
|                     Notification::create( |                 Notification::create( | ||||||
|                         db, |                     db, | ||||||
|                         &user_earlier_trip, |                     &user_earlier_trip, | ||||||
|                         &format!( |                     &format!( | ||||||
|                             "{} hat eine Ausfahrt zur selben Zeit ({} um {}) wie du erstellt", |                         "{} hat eine Ausfahrt zur selben Zeit ({} um {}) wie du erstellt", | ||||||
|                             user.name, trip.day, trip.planned_starting_time |                         user.name, trip.day, trip.planned_starting_time | ||||||
|                         ), |                     ), | ||||||
|                         "Neue Ausfahrt zur selben Zeit", |                     "Neue Ausfahrt zur selben Zeit", | ||||||
|                         None, |                     None, | ||||||
|                         None, |                     None, | ||||||
|                     ) |                 ) | ||||||
|                     .await; |                 .await; | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -486,6 +484,7 @@ mod test { | |||||||
|     use crate::{ |     use crate::{ | ||||||
|         model::{ |         model::{ | ||||||
|             event::Event, |             event::Event, | ||||||
|  |             notification::Notification, | ||||||
|             trip::{self, TripDeleteError}, |             trip::{self, TripDeleteError}, | ||||||
|             tripdetails::TripDetails, |             tripdetails::TripDetails, | ||||||
|             user::{SteeringUser, User}, |             user::{SteeringUser, User}, | ||||||
| @@ -517,6 +516,34 @@ mod test { | |||||||
|         assert!(Trip::find_by_id(&pool, 1).await.is_some()); |         assert!(Trip::find_by_id(&pool, 1).await.is_some()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     #[sqlx::test] | ||||||
|  |     fn test_notification_cox_if_same_datetime() { | ||||||
|  |         let pool = testdb!(); | ||||||
|  |         let cox = SteeringUser::new( | ||||||
|  |             &pool, | ||||||
|  |             User::find_by_name(&pool, "cox".into()).await.unwrap(), | ||||||
|  |         ) | ||||||
|  |         .await | ||||||
|  |         .unwrap(); | ||||||
|  |         let trip_details = TripDetails::find_by_id(&pool, 1).await.unwrap(); | ||||||
|  |         Trip::new_own(&pool, &cox, trip_details).await; | ||||||
|  |  | ||||||
|  |         let cox2 = SteeringUser::new( | ||||||
|  |             &pool, | ||||||
|  |             User::find_by_name(&pool, "cox2".into()).await.unwrap(), | ||||||
|  |         ) | ||||||
|  |         .await | ||||||
|  |         .unwrap(); | ||||||
|  |         let trip_details = TripDetails::find_by_id(&pool, 3).await.unwrap(); | ||||||
|  |         Trip::new_own(&pool, &cox2, trip_details).await; | ||||||
|  |  | ||||||
|  |         let last_notification = &Notification::for_user(&pool, &cox).await[0]; | ||||||
|  |  | ||||||
|  |         assert!(last_notification | ||||||
|  |             .message | ||||||
|  |             .starts_with("cox2 hat eine Ausfahrt zur selben Zeit")); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     #[sqlx::test] |     #[sqlx::test] | ||||||
|     fn test_get_day_cox_trip() { |     fn test_get_day_cox_trip() { | ||||||
|         let pool = testdb!(); |         let pool = testdb!(); | ||||||
|   | |||||||
| @@ -339,7 +339,7 @@ mod test { | |||||||
|                 } |                 } | ||||||
|             ) |             ) | ||||||
|             .await, |             .await, | ||||||
|             3, |             4, | ||||||
|         ); |         ); | ||||||
|         assert_eq!( |         assert_eq!( | ||||||
|             TripDetails::create( |             TripDetails::create( | ||||||
| @@ -354,7 +354,7 @@ mod test { | |||||||
|                 } |                 } | ||||||
|             ) |             ) | ||||||
|             .await, |             .await, | ||||||
|             4, |             5, | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -47,12 +47,13 @@ async fn index(db: &State<SqlitePool>, user: DonauLinzUser, year: Option<i32>) - | |||||||
| async fn index_kiosk(db: &State<SqlitePool>, _kiosk: KioskCookie, year: Option<i32>) -> Template { | async fn index_kiosk(db: &State<SqlitePool>, _kiosk: KioskCookie, year: Option<i32>) -> Template { | ||||||
|     let stat = Stat::people(db, year).await; |     let stat = Stat::people(db, year).await; | ||||||
|     let club_km = Stat::sum_people(db, year).await; |     let club_km = Stat::sum_people(db, year).await; | ||||||
|  |     let club_trips = Stat::trips_people(db, year).await; | ||||||
|     let guest_km = Stat::guest(db, year).await; |     let guest_km = Stat::guest(db, year).await; | ||||||
|     let kiosk = true; |     let kiosk = true; | ||||||
|  |  | ||||||
|     Template::render( |     Template::render( | ||||||
|         "stat.people", |         "stat.people", | ||||||
|         context!(stat, kiosk, show_kiosk_header: true, guest_km, club_km), |         context!(stat, kiosk, show_kiosk_header: true, guest_km, club_km, club_trips), | ||||||
|     ) |     ) | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -61,4 +62,30 @@ pub fn routes() -> Vec<Route> { | |||||||
| } | } | ||||||
|  |  | ||||||
| #[cfg(test)] | #[cfg(test)] | ||||||
| mod test {} | mod test { | ||||||
|  |     use rocket::{http::Status, local::asynchronous::Client}; | ||||||
|  |     use sqlx::SqlitePool; | ||||||
|  |  | ||||||
|  |     use crate::testdb; | ||||||
|  |  | ||||||
|  |     #[sqlx::test] | ||||||
|  |     fn test_kiosk_stat() { | ||||||
|  |         let db = testdb!(); | ||||||
|  |  | ||||||
|  |         let rocket = rocket::build().manage(db.clone()); | ||||||
|  |         let rocket = crate::tera::config(rocket); | ||||||
|  |  | ||||||
|  |         let client = Client::tracked(rocket).await.unwrap(); | ||||||
|  |         // "Log in" | ||||||
|  |         let req = client.get("/log/kiosk/ekrv2019/Linz"); | ||||||
|  |         let _ = req.dispatch().await; | ||||||
|  |  | ||||||
|  |         // `/stat` should be viewable | ||||||
|  |         let req = client.get("/stat"); | ||||||
|  |         let response = req.dispatch().await; | ||||||
|  |  | ||||||
|  |         assert_eq!(response.status(), Status::Ok); | ||||||
|  |         let text = response.into_string().await.unwrap(); | ||||||
|  |         assert!(text.contains("Statistik")); | ||||||
|  |     } | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user