File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -124,3 +124,36 @@ pub fn logout(req: &mut dyn Request) -> CargoResult<Response> {
124
124
req. session ( ) . remove ( & "user_id" . to_string ( ) ) ;
125
125
Ok ( req. json ( & true ) )
126
126
}
127
+
128
+ #[ cfg( test) ]
129
+ mod tests {
130
+ use super :: * ;
131
+ use dotenv:: dotenv;
132
+ use std:: env;
133
+
134
+ fn pg_connection ( ) -> PgConnection {
135
+ let _ = dotenv ( ) ;
136
+ let database_url =
137
+ env:: var ( "TEST_DATABASE_URL" ) . expect ( "TEST_DATABASE_URL must be set to run tests" ) ;
138
+ PgConnection :: establish ( & database_url) . unwrap ( )
139
+ }
140
+
141
+ #[ test]
142
+ fn gh_user_with_invalid_email_doesnt_fail ( ) {
143
+ let conn = pg_connection ( ) ;
144
+ let gh_user = GithubUser {
145
+ email : Some ( "String.Format(\" {0}.{1}@live.com\" , FirstName, LastName)" . into ( ) ) ,
146
+ name : Some ( "My Name" . into ( ) ) ,
147
+ login : "github_user" . into ( ) ,
148
+ id : -1 ,
149
+ avatar_url : None ,
150
+ } ;
151
+ let result = gh_user. save_to_database ( "arbitrary_token" , & conn) ;
152
+
153
+ assert ! (
154
+ result. is_ok( ) ,
155
+ "Creating a User from a GitHub user failed when it shouldn't have, {:?}" ,
156
+ result
157
+ ) ;
158
+ }
159
+ }
You can’t perform that action at this time.
0 commit comments