@@ -4,6 +4,7 @@ use crates_io::models::NewUser;
44use crates_io:: schema:: users;
55use crates_io:: views:: EncodablePublicUser ;
66use diesel_async:: RunQueryDsl ;
7+ use insta:: assert_snapshot;
78use serde:: Deserialize ;
89
910#[ derive( Deserialize ) ]
@@ -19,9 +20,14 @@ async fn show() {
1920 let json: UserShowPublicResponse = anon. get ( "/api/v1/users/foo" ) . await . good ( ) ;
2021 assert_eq ! ( json. user. login, "foo" ) ;
2122
23+ // Lookup by username is case insensitive; returned data uses capitalization in database
2224 let json: UserShowPublicResponse = anon. get ( "/api/v1/users/bAr" ) . await . good ( ) ;
2325 assert_eq ! ( json. user. login, "Bar" ) ;
2426 assert_eq ! ( json. user. url, "https://github.com/Bar" ) ;
27+
28+ // Username not in database results in 404
29+ let response = anon. get :: < ( ) > ( "/api/v1/users/not_a_user" ) . await ;
30+ assert_snapshot ! ( response. status( ) , @"404 Not Found" ) ;
2531}
2632
2733#[ tokio:: test( flavor = "multi_thread" ) ]
@@ -64,3 +70,24 @@ async fn show_latest_user_case_insensitively() {
6470 json. user. name. unwrap( )
6571 ) ;
6672}
73+
74+ #[ tokio:: test( flavor = "multi_thread" ) ]
75+ async fn user_without_github_account ( ) {
76+ let ( app, anon) = TestApp :: init ( ) . empty ( ) . await ;
77+ let mut conn = app. db_conn ( ) . await ;
78+
79+ let new_user = NewUser :: builder ( )
80+ // The gh_id column will eventually be removed; there are currently records in production
81+ // that have `-1` for their `gh_id` because the associated GitHub accounts have been deleted
82+ . gh_id ( -1 )
83+ . gh_login ( "foobar" )
84+ . name ( "I deleted my github account" )
85+ . gh_encrypted_token ( & [ ] )
86+ . build ( ) ;
87+ new_user. insert ( & mut conn) . await . unwrap ( ) ;
88+ // This user doesn't have a linked record in `oauth_github`
89+
90+ // The crates.io username still exists
91+ let json: UserShowPublicResponse = anon. get ( "/api/v1/users/fOObAr" ) . await . good ( ) ;
92+ assert_eq ! ( "I deleted my github account" , json. user. name. unwrap( ) ) ;
93+ }
0 commit comments