@@ -33,15 +33,42 @@ fn test_hex_arch_ops() {
3333 . unwrap( ) as usize ,
3434 find_all_result. len( )
3535 ) ;
36- // assert_eq!(LeagueHexRepositoryAdapter::<DatabaseConnection>::count_with(binding.deref_mut()).await.unwrap() as usize, find_all_result.len());
37- // The line above works, because we're using binding, but in a better ideal world, our repository would hold an Arc<Mutex<...>> with the connection,
38- // so the user acquire the lock on every query, just cloning the Arc, which if you remember, just increases in one unit the number of active
39- // references pointing to the resource behind the atomic smart pointer
4036}
4137
4238#[ cfg( feature = "postgres" ) ]
4339#[ canyon_sql:: macros:: canyon_tokio_test]
44- fn test_hex_arch_find_insert_ops ( ) {
40+ fn test_hex_arch_insert_entity_ops ( ) {
41+ let default_db_conn = Canyon :: instance ( )
42+ . unwrap ( )
43+ . get_default_connection ( )
44+ . unwrap ( ) ;
45+ let league_service = LeagueHexServiceAdapter {
46+ league_repository : LeagueHexRepositoryAdapter {
47+ db_conn : default_db_conn,
48+ } ,
49+ } ;
50+
51+ let mut other_league: LeagueHex = LeagueHex {
52+ id : Default :: default ( ) ,
53+ ext_id : Default :: default ( ) ,
54+ slug : "leaguehex-slug" . to_string ( ) ,
55+ name : "Test LeagueHex on layered" . to_string ( ) ,
56+ region : "LeagueHex Region" . to_string ( ) ,
57+ image_url : "http://example.com/image.png" . to_string ( ) ,
58+ } ;
59+ league_service. create ( & mut other_league) . await . unwrap ( ) ;
60+
61+ let find_new_league = league_service. get ( & other_league. id ) . await . unwrap ( ) ;
62+ assert ! ( find_new_league. is_some( ) ) ;
63+ assert_eq ! (
64+ find_new_league. as_ref( ) . unwrap( ) . name,
65+ String :: from( "Test LeagueHex on layered" )
66+ ) ;
67+ }
68+
69+ #[ cfg( feature = "postgres" ) ]
70+ #[ canyon_sql:: macros:: canyon_tokio_test]
71+ fn test_hex_arch_update_entity_ops ( ) {
4572 let default_db_conn = Canyon :: instance ( )
4673 . unwrap ( )
4774 . get_default_connection ( )
@@ -61,7 +88,6 @@ fn test_hex_arch_find_insert_ops() {
6188 image_url : "http://example.com/image.png" . to_string ( ) ,
6289 } ;
6390 league_service. create ( & mut other_league) . await . unwrap ( ) ;
64- println ! ( "New league inserted with: {:#?}" , other_league. id) ;
6591
6692 let find_new_league = league_service. get ( & other_league. id ) . await . unwrap ( ) ;
6793 assert ! ( find_new_league. is_some( ) ) ;
@@ -76,7 +102,7 @@ fn test_hex_arch_find_insert_ops() {
76102 assert ! ( r. is_ok( ) ) ;
77103
78104 let updated = league_service. get ( & other_league. id ) . await . unwrap ( ) ;
79- assert_eq ! ( updated. unwrap( ) . ext_id, 5 )
105+ assert_eq ! ( updated. unwrap( ) . ext_id, 5 ) ;
80106}
81107
82108#[ derive( CanyonMapper , Debug ) ]
@@ -167,8 +193,6 @@ impl<T: DbConnection + Send + Sync> LeagueHexRepository for LeagueHexRepositoryA
167193 & self ,
168194 id : & ' a Pk ,
169195 ) -> Result < Option < LeagueHex > , Box < dyn Error + Send + Sync + ' a > > {
170- let r = Self :: find_by_pk ( id) . await ;
171- println ! ( "FIND BY PK ON GET err: {:?}" , r) ;
172- r
196+ Self :: find_by_pk ( id) . await
173197 }
174198}
0 commit comments