@@ -168,3 +168,49 @@ async fn test_patch_player_nationality(pool: Pool<Postgres>) {
168
168
assert_eq ! ( result[ "data" ] [ "nation_code" ] , "BE" ) ;
169
169
assert_eq ! ( result[ "data" ] [ "subdivision_code" ] , "ENG" ) ;
170
170
}
171
+
172
+ #[ sqlx:: test( migrations = "../migrations" ) ]
173
+ async fn test_me ( pool : Pool < Postgres > ) {
174
+ let ( client, mut connection) = pointercrate_test:: demonlist:: setup_rocket ( pool) . await ;
175
+
176
+ // Assert 401 without authentication
177
+ client. get ( "/api/v1/players/me" ) . expect_status ( Status :: Unauthorized ) . execute ( ) . await ;
178
+
179
+ let authenticated_user = pointercrate_test:: user:: add_normal_user ( & mut * connection) . await ;
180
+ let user = authenticated_user. user ( ) ;
181
+
182
+ // Assert 404 when authorized, but claim doesn't exist
183
+ client
184
+ . get ( "/api/v1/players/me" )
185
+ . authorize_as ( & authenticated_user)
186
+ . expect_status ( Status :: NotFound )
187
+ . execute ( )
188
+ . await ;
189
+
190
+ // Create claim
191
+ let player = DatabasePlayer :: by_name_or_create ( "stardust1971" , & mut * connection) . await . unwrap ( ) ;
192
+ player
193
+ . initiate_claim ( user. id , & mut * connection)
194
+ . await
195
+ . unwrap ( )
196
+ . set_verified ( true , & mut * connection)
197
+ . await
198
+ . unwrap ( ) ;
199
+ let player = Player :: by_id ( player. id , & mut * connection)
200
+ . await
201
+ . unwrap ( )
202
+ . upgrade ( & mut * connection)
203
+ . await
204
+ . unwrap ( ) ;
205
+
206
+ // Authorized and claim exists
207
+ assert_eq ! (
208
+ client
209
+ . get( "/api/v1/players/me" )
210
+ . authorize_as( & authenticated_user)
211
+ . expect_status( Status :: Ok )
212
+ . get_success_result:: <FullPlayer >( )
213
+ . await ,
214
+ player
215
+ ) ;
216
+ }
0 commit comments