@@ -52,3 +52,47 @@ pub async fn regenerate_token_and_send(
5252 } )
5353 . await
5454}
55+
56+ #[ cfg( test) ]
57+ mod tests {
58+ use crate :: tests:: util:: { RequestHelper , TestApp } ;
59+ use http:: StatusCode ;
60+ use insta:: assert_snapshot;
61+
62+ #[ tokio:: test( flavor = "multi_thread" ) ]
63+ async fn test_no_auth ( ) {
64+ let ( app, anon, user) = TestApp :: init ( ) . with_user ( ) ;
65+
66+ let url = format ! ( "/api/v1/users/{}/resend" , user. as_model( ) . id) ;
67+ let response = anon. put :: < ( ) > ( & url, "" ) . await ;
68+ assert_eq ! ( response. status( ) , StatusCode :: FORBIDDEN ) ;
69+ assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"this action requires authentication"}]}"# ) ;
70+
71+ assert_eq ! ( app. emails( ) . len( ) , 0 ) ;
72+ }
73+
74+ #[ tokio:: test( flavor = "multi_thread" ) ]
75+ async fn test_wrong_user ( ) {
76+ let ( app, _anon, user) = TestApp :: init ( ) . with_user ( ) ;
77+ let user2 = app. db_new_user ( "bar" ) ;
78+
79+ let url = format ! ( "/api/v1/users/{}/resend" , user2. as_model( ) . id) ;
80+ let response = user. put :: < ( ) > ( & url, "" ) . await ;
81+ assert_eq ! ( response. status( ) , StatusCode :: BAD_REQUEST ) ;
82+ assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"current user does not match requested user"}]}"# ) ;
83+
84+ assert_eq ! ( app. emails( ) . len( ) , 0 ) ;
85+ }
86+
87+ #[ tokio:: test( flavor = "multi_thread" ) ]
88+ async fn test_happy_path ( ) {
89+ let ( app, _anon, user) = TestApp :: init ( ) . with_user ( ) ;
90+
91+ let url = format ! ( "/api/v1/users/{}/resend" , user. as_model( ) . id) ;
92+ let response = user. put :: < ( ) > ( & url, "" ) . await ;
93+ assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
94+ assert_snapshot ! ( response. text( ) , @r###"{"ok":true}"### ) ;
95+
96+ assert_snapshot ! ( app. emails_snapshot( ) ) ;
97+ }
98+ }
0 commit comments