@@ -354,4 +354,89 @@ describe('Accounts', () => {
354
354
// });
355
355
// });
356
356
} ) ;
357
+
358
+ describe ( 'verifyEmail' , ( ) => {
359
+ it ( 'should return an AccountsError' , async ( ) => {
360
+ const error = 'something bad' ;
361
+ Accounts . config ( { } , { verifyEmail : ( ) => Promise . reject ( { message : error } ) } ) ;
362
+ try {
363
+ await Accounts . verifyEmail ( ) ;
364
+ throw new Error ( ) ;
365
+ } catch ( err ) {
366
+ expect ( err . message ) . toEqual ( error ) ;
367
+ }
368
+ } ) ;
369
+
370
+ it ( 'should call transport.verifyEmail' , async ( ) => {
371
+ const mock = jest . fn ( ( ) => Promise . resolve ( ) ) ;
372
+ Accounts . config ( { } , { verifyEmail : mock } ) ;
373
+ await Accounts . verifyEmail ( 'token' ) ;
374
+ expect ( mock . mock . calls . length ) . toEqual ( 1 ) ;
375
+ expect ( mock . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'token' ) ;
376
+ } ) ;
377
+ } ) ;
378
+
379
+ describe ( 'resetPassword' , ( ) => {
380
+ it ( 'should return an AccountsError' , async ( ) => {
381
+ const error = 'something bad' ;
382
+ Accounts . config ( { } , { resetPassword : ( ) => Promise . reject ( { message : error } ) } ) ;
383
+ try {
384
+ await Accounts . resetPassword ( ) ;
385
+ throw new Error ( ) ;
386
+ } catch ( err ) {
387
+ expect ( err . message ) . toEqual ( error ) ;
388
+ }
389
+ } ) ;
390
+
391
+ it ( 'should call transport.resetPassword' , async ( ) => {
392
+ const mock = jest . fn ( ( ) => Promise . resolve ( ) ) ;
393
+ Accounts . config ( { } , { resetPassword : mock } ) ;
394
+ await Accounts . resetPassword ( 'token' , 'newPassword' ) ;
395
+ expect ( mock . mock . calls . length ) . toEqual ( 1 ) ;
396
+ expect ( mock . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'token' ) ;
397
+ expect ( mock . mock . calls [ 0 ] [ 1 ] ) . toEqual ( 'newPassword' ) ;
398
+ } ) ;
399
+ } ) ;
400
+
401
+ describe ( 'requestPasswordReset' , ( ) => {
402
+ it ( 'should return an AccountsError' , async ( ) => {
403
+ const error = 'something bad' ;
404
+ Accounts . config ( { } , { sendResetPasswordEmail : ( ) => Promise . reject ( { message : error } ) } ) ;
405
+ try {
406
+ await Accounts . requestPasswordReset ( ) ;
407
+ throw new Error ( ) ;
408
+ } catch ( err ) {
409
+ expect ( err . message ) . toEqual ( error ) ;
410
+ }
411
+ } ) ;
412
+
413
+ it ( 'should call transport.sendResetPasswordEmail' , async ( ) => {
414
+ const mock = jest . fn ( ( ) => Promise . resolve ( ) ) ;
415
+ Accounts . config ( { } , { sendResetPasswordEmail : mock } ) ;
416
+ await Accounts . requestPasswordReset ( 'email' ) ;
417
+ expect ( mock . mock . calls . length ) . toEqual ( 1 ) ;
418
+ expect ( mock . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'email' ) ;
419
+ } ) ;
420
+ } ) ;
421
+
422
+ describe ( 'requestVerificationEmail' , ( ) => {
423
+ it ( 'should return an AccountsError' , async ( ) => {
424
+ const error = 'something bad' ;
425
+ Accounts . config ( { } , { sendVerificationEmail : ( ) => Promise . reject ( { message : error } ) } ) ;
426
+ try {
427
+ await Accounts . requestVerificationEmail ( ) ;
428
+ throw new Error ( ) ;
429
+ } catch ( err ) {
430
+ expect ( err . message ) . toEqual ( error ) ;
431
+ }
432
+ } ) ;
433
+
434
+ it ( 'should call transport.sendVerificationEmail' , async ( ) => {
435
+ const mock = jest . fn ( ( ) => Promise . resolve ( ) ) ;
436
+ Accounts . config ( { } , { sendVerificationEmail : mock } ) ;
437
+ await Accounts . requestVerificationEmail ( 'email' ) ;
438
+ expect ( mock . mock . calls . length ) . toEqual ( 1 ) ;
439
+ expect ( mock . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'email' ) ;
440
+ } ) ;
441
+ } ) ;
357
442
} ) ;
0 commit comments