@@ -2121,6 +2121,43 @@ describe('User', function() {
21212121 } ) ;
21222122 } ) ;
21232123
2124+ describe ( 'password reset with/without email verification' , function ( ) {
2125+ it ( 'allows resetPassword by email if email verification is required and done' ,
2126+ function ( done ) {
2127+ User . settings . emailVerificationRequired = true ;
2128+ var email = validCredentialsEmailVerified . email ;
2129+
2130+ User . resetPassword ( { email : email } , function ( err , info ) {
2131+ if ( err ) return done ( err ) ;
2132+ done ( ) ;
2133+ } ) ;
2134+ } ) ;
2135+
2136+ it ( 'disallows resetPassword by email if email verification is required and not done' ,
2137+ function ( done ) {
2138+ User . settings . emailVerificationRequired = true ;
2139+ var email = validCredentialsEmail ;
2140+
2141+ User . resetPassword ( { email : email } , function ( err ) {
2142+ assert ( err ) ;
2143+ assert . equal ( err . code , 'RESET_FAILED_EMAIL_NOT_VERIFIED' ) ;
2144+ assert . equal ( err . statusCode , 401 ) ;
2145+ done ( ) ;
2146+ } ) ;
2147+ } ) ;
2148+
2149+ it ( 'allows resetPassword by email if email verification is not required' ,
2150+ function ( done ) {
2151+ User . settings . emailVerificationRequired = false ;
2152+ var email = validCredentialsEmail ;
2153+
2154+ User . resetPassword ( { email : email } , function ( err ) {
2155+ if ( err ) return done ( err ) ;
2156+ done ( ) ;
2157+ } ) ;
2158+ } ) ;
2159+ } ) ;
2160+
21242161 describe ( 'ctor' , function ( ) {
21252162 it ( 'exports default Email model' , function ( ) {
21262163 expect ( User . email , 'User.email' ) . to . be . a ( 'function' ) ;
0 commit comments