@@ -21,7 +21,7 @@ impl crate::tests::util::MockCookieUser {
2121}
2222
2323#[ tokio:: test( flavor = "multi_thread" ) ]
24- async fn updating_existing_user_doesnt_change_api_token ( ) {
24+ async fn updating_existing_user_doesnt_change_api_token ( ) -> anyhow :: Result < ( ) > {
2525 let ( app, _, user, token) = TestApp :: init ( ) . with_token ( ) . await ;
2626 let mut conn = app. db_conn ( ) . await ;
2727 let gh_id = user. as_model ( ) . gh_id ;
@@ -41,6 +41,8 @@ async fn updating_existing_user_doesnt_change_api_token() {
4141
4242 assert_eq ! ( user. gh_login, "bar" ) ;
4343 assert_eq ! ( user. gh_access_token, "bar_token" ) ;
44+
45+ Ok ( ( ) )
4446}
4547
4648/// Given a GitHub user, check that if the user logs in,
@@ -53,7 +55,7 @@ async fn updating_existing_user_doesnt_change_api_token() {
5355/// send none as the email and we will end up inadvertently
5456/// deleting their email when they sign back in.
5557#[ tokio:: test( flavor = "multi_thread" ) ]
56- async fn github_without_email_does_not_overwrite_email ( ) {
58+ async fn github_without_email_does_not_overwrite_email ( ) -> anyhow :: Result < ( ) > {
5759 let ( app, _) = TestApp :: init ( ) . empty ( ) . await ;
5860 let mut conn = app. db_conn ( ) . await ;
5961
@@ -62,8 +64,7 @@ async fn github_without_email_does_not_overwrite_email() {
6264 // Don't use app.db_new_user because it adds a verified email.
6365 let u = new_user ( "arbitrary_username" )
6466 . create_or_update ( None , & app. as_inner ( ) . emails , & mut conn)
65- . await
66- . unwrap ( ) ;
67+ . await ?;
6768
6869 let user_without_github_email = MockCookieUser :: new ( & app, u) ;
6970 let user_without_github_email_model = user_without_github_email. as_model ( ) ;
@@ -86,18 +87,19 @@ async fn github_without_email_does_not_overwrite_email() {
8687 } ;
8788 let u = u
8889 . create_or_update ( None , & app. as_inner ( ) . emails , & mut conn)
89- . await
90- . unwrap ( ) ;
90+ . await ?;
9191 let again_user_without_github_email = MockCookieUser :: new ( & app, u) ;
9292
9393 let json = again_user_without_github_email. show_me ( ) . await ;
9494 assert_eq ! ( json
. user
. email
. unwrap
( ) , "[email protected] " ) ; 95+
96+ Ok ( ( ) )
9597}
9698
9799/// Given a new user, test that if they sign in with one email, change their email on GitHub, then
98100/// sign in again, that the email in crates.io will remain set to the original email used on GitHub.
99101#[ tokio:: test( flavor = "multi_thread" ) ]
100- async fn github_with_email_does_not_overwrite_email ( ) {
102+ async fn github_with_email_does_not_overwrite_email ( ) -> anyhow :: Result < ( ) > {
101103 use crate :: schema:: emails;
102104
103105 let ( app, _, user) = TestApp :: init ( ) . with_user ( ) . await ;
@@ -108,8 +110,7 @@ async fn github_with_email_does_not_overwrite_email() {
108110 let original_email: String = Email :: belonging_to ( model)
109111 . select ( emails:: email)
110112 . first ( & mut conn)
111- . await
112- . unwrap ( ) ;
113+ . await ?;
113114
114115 let new_github_email =
"[email protected] " ; 115116
@@ -125,20 +126,21 @@ async fn github_with_email_does_not_overwrite_email() {
125126 } ;
126127 let u = u
127128 . create_or_update ( Some ( new_github_email) , & emails, & mut conn)
128- . await
129- . unwrap ( ) ;
129+ . await ?;
130130
131131 let user_with_different_email_in_github = MockCookieUser :: new ( & app, u) ;
132132
133133 let json = user_with_different_email_in_github. show_me ( ) . await ;
134134 assert_eq ! ( json. user. email, Some ( original_email) ) ;
135+
136+ Ok ( ( ) )
135137}
136138
137139/// Given a crates.io user, check that the user's email can be
138140/// updated in the database (PUT /user/:user_id), then check
139141/// that the updated email is sent back to the user (GET /me).
140142#[ tokio:: test( flavor = "multi_thread" ) ]
141- async fn test_email_get_and_put ( ) {
143+ async fn test_email_get_and_put ( ) -> anyhow :: Result < ( ) > {
142144 let ( _app, _anon, user) = TestApp :: init ( ) . with_user ( ) . await ;
143145
144146 let json = user. show_me ( ) . await ;
@@ -150,6 +152,8 @@ async fn test_email_get_and_put() {
150152 assert_eq ! ( json
. user
. email
. unwrap
( ) , "[email protected] " ) ; 151153 assert ! ( !json. user. email_verified) ;
152154 assert ! ( json. user. email_verification_sent) ;
155+
156+ Ok ( ( ) )
153157}
154158
155159/// Given a new user, test that their email can be added
@@ -158,7 +162,7 @@ async fn test_email_get_and_put() {
158162/// requested, check that the response back is ok, and that
159163/// the email_verified field on user is now set to true.
160164#[ tokio:: test( flavor = "multi_thread" ) ]
161- async fn test_confirm_user_email ( ) {
165+ async fn test_confirm_user_email ( ) -> anyhow :: Result < ( ) > {
162166 use crate :: schema:: emails;
163167
164168 let ( app, _) = TestApp :: init ( ) . empty ( ) . await ;
@@ -171,31 +175,31 @@ async fn test_confirm_user_email() {
171175 let emails = app. as_inner ( ) . emails . clone ( ) ;
172176 let u = new_user ( "arbitrary_username" )
173177 . create_or_update ( Some ( email) , & emails, & mut conn)
174- . await
175- . unwrap ( ) ;
178+ . await ?;
176179
177180 let user = MockCookieUser :: new ( & app, u) ;
178181 let user_model = user. as_model ( ) ;
179182
180183 let email_token: String = Email :: belonging_to ( user_model)
181184 . select ( emails:: token)
182185 . first ( & mut conn)
183- . await
184- . unwrap ( ) ;
186+ . await ?;
185187
186188 user. confirm_email ( & email_token) . await ;
187189
188190 let json = user. show_me ( ) . await ;
189191 assert_eq ! ( json
. user
. email
. unwrap
( ) , "[email protected] " ) ; 190192 assert ! ( json. user. email_verified) ;
191193 assert ! ( json. user. email_verification_sent) ;
194+
195+ Ok ( ( ) )
192196}
193197
194198/// Given a user who existed before we added email confirmation,
195199/// test that `email_verification_sent` is false so that we don't
196200/// make the user think we've sent an email when we haven't.
197201#[ tokio:: test( flavor = "multi_thread" ) ]
198- async fn test_existing_user_email ( ) {
202+ async fn test_existing_user_email ( ) -> anyhow :: Result < ( ) > {
199203 use crate :: schema:: emails;
200204 use chrono:: NaiveDateTime ;
201205 use diesel:: update;
@@ -210,20 +214,20 @@ async fn test_existing_user_email() {
210214 let emails = app. as_inner ( ) . emails . clone ( ) ;
211215 let u = new_user ( "arbitrary_username" )
212216 . create_or_update ( Some ( email) , & emails, & mut conn)
213- . await
214- . unwrap ( ) ;
217+ . await ?;
215218
216219 update ( Email :: belonging_to ( & u) )
217220 // Users created before we added verification will have
218221 // `NULL` in the `token_generated_at` column.
219222 . set ( emails:: token_generated_at. eq ( None :: < NaiveDateTime > ) )
220223 . execute ( & mut conn)
221- . await
222- . unwrap ( ) ;
224+ . await ?;
223225 let user = MockCookieUser :: new ( & app, u) ;
224226
225227 let json = user. show_me ( ) . await ;
226228 assert_eq ! ( json
. user
. email
. unwrap
( ) , "[email protected] " ) ; 227229 assert ! ( !json. user. email_verified) ;
228230 assert ! ( !json. user. email_verification_sent) ;
231+
232+ Ok ( ( ) )
229233}
0 commit comments