@@ -156,7 +156,61 @@ describe("Email Verification", () => {
156156 return user . fetch ( ) ;
157157 } ) . then ( ( ) => {
158158 expect ( user . get ( 'emailVerified' ) ) . toEqual ( false ) ;
159- // Wait as on update emai, we need to fetch the username
159+ // Wait as on update email, we need to fetch the username
160+ setTimeout ( function ( ) {
161+ expect ( emailAdapter . sendVerificationEmail ) . toHaveBeenCalled ( ) ;
162+ done ( ) ;
163+ } , 200 ) ;
164+ } ) ;
165+ } ,
166+ error : function ( userAgain , error ) {
167+ fail ( 'Failed to save user' ) ;
168+ done ( ) ;
169+ }
170+ } ) ;
171+ } ) ;
172+
173+ it ( 'does send a validation email with valid verification link when updating the email' , done => {
174+ var emailAdapter = {
175+ sendVerificationEmail : ( ) => Promise . resolve ( ) ,
176+ sendPasswordResetEmail : ( ) => Promise . resolve ( ) ,
177+ sendMail : ( ) => Promise . resolve ( )
178+ }
179+ setServerConfiguration ( {
180+ serverURL : 'http://localhost:8378/1' ,
181+ appId : 'test' ,
182+ appName : 'unused' ,
183+ javascriptKey : 'test' ,
184+ dotNetKey : 'windows' ,
185+ clientKey : 'client' ,
186+ restAPIKey : 'rest' ,
187+ masterKey : 'test' ,
188+ collectionPrefix : 'test_' ,
189+ fileKey : 'test' ,
190+ verifyUserEmails : true ,
191+ emailAdapter : emailAdapter ,
192+ publicServerURL : "http://localhost:8378/1"
193+ } ) ;
194+ spyOn ( emailAdapter , 'sendVerificationEmail' ) . and . callFake ( ( options ) => {
195+ expect ( options . link ) . not . toBeNull ( ) ;
196+ expect ( options . link ) . not . toMatch ( / t o k e n = u n d e f i n e d / ) ;
197+ Promise . resolve ( ) ;
198+ } ) ;
199+ var user = new Parse . User ( ) ;
200+ user . setPassword ( "asdf" ) ;
201+ user . setUsername ( "zxcv" ) ;
202+ user . signUp ( null , {
203+ success : function ( user ) {
204+ expect ( emailAdapter . sendVerificationEmail ) . not . toHaveBeenCalled ( ) ;
205+ user . fetch ( )
206+ . then ( ( user ) => {
207+ user . set ( "email" , "[email protected] " ) ; 208+ return user . save ( ) ;
209+ } ) . then ( ( user ) => {
210+ return user . fetch ( ) ;
211+ } ) . then ( ( ) => {
212+ expect ( user . get ( 'emailVerified' ) ) . toEqual ( false ) ;
213+ // Wait as on update email, we need to fetch the username
160214 setTimeout ( function ( ) {
161215 expect ( emailAdapter . sendVerificationEmail ) . toHaveBeenCalled ( ) ;
162216 done ( ) ;
0 commit comments