@@ -369,17 +369,16 @@ mod tests {
369369 }
370370
371371 #[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
372- async fn rolling_stock_list_filters_authorized_rolling_stocks ( ) {
372+ async fn rolling_stock_list_user_only_sees_its_related_rolling_stocks ( ) {
373373 let app = test_app ! ( ) . build ( ) ;
374374 let db_pool = app. db_pool ( ) ;
375- let rolling_stock_grant =
376- create_fast_rolling_stock ( & mut db_pool. get_ok ( ) , "fast_rolling_stock_grant" ) . await ;
377- let rolling_stock_no_grant =
378- create_fast_rolling_stock ( & mut db_pool. get_ok ( ) , "fast_rolling_stock_no_grant" ) . await ;
379- // Regular user with the correct roles should see only the rolling stock he is associated with:
375+ let rs_1 = create_fast_rolling_stock ( & mut db_pool. get_ok ( ) , "rs_1" ) . await ;
376+ let rs_2 = create_fast_rolling_stock ( & mut db_pool. get_ok ( ) , "rs_2" ) . await ;
377+ let _rs_no_grant = create_fast_rolling_stock ( & mut db_pool. get_ok ( ) , "rs_no_grant" ) . await ;
380378 let user = app
381379 . user ( "user_identity" , "user_name" )
382- . with_rolling_stock_grant ( rolling_stock_grant. id , RollingStockGrant :: Reader )
380+ . with_rolling_stock_grant ( rs_1. id , RollingStockGrant :: Reader )
381+ . with_rolling_stock_grant ( rs_2. id , RollingStockGrant :: Reader )
383382 . create ( )
384383 . await ;
385384 let response: LightRollingStockWithLiveriesCountList = app
@@ -394,10 +393,15 @@ mod tests {
394393 . iter( )
395394 . map( |rolling_stock| rolling_stock. rolling_stock. id)
396395 . collect:: <Vec <_>>( ) ,
397- vec![ rolling_stock_grant . id]
396+ vec![ rs_1 . id , rs_2 . id]
398397 ) ;
399- // TODO: separate in two tests (admins_can_list_all_rolling_stocks and user_can_list_their_rolling_stocks)
400- // An admin should see all the rolling stocks:
398+ }
399+
400+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
401+ async fn rolling_stock_list_admin_can_see_unrelated_rolling_stock ( ) {
402+ let app = test_app ! ( ) . build ( ) ;
403+ let db_pool = app. db_pool ( ) ;
404+ let rs_no_grant = create_fast_rolling_stock ( & mut db_pool. get_ok ( ) , "rs_no_grant" ) . await ;
401405 let admin = app
402406 . user ( "admin" , "admin" )
403407 . with_roles ( [ Role :: Admin ] )
@@ -415,7 +419,7 @@ mod tests {
415419 . iter( )
416420 . map( |rolling_stock| rolling_stock. rolling_stock. id)
417421 . collect:: <Vec <_>>( ) ,
418- vec![ rolling_stock_grant . id , rolling_stock_no_grant . id]
422+ vec![ rs_no_grant . id]
419423 ) ;
420424 }
421425
0 commit comments