@@ -406,4 +406,89 @@ describe('Accounts', () => {
406
406
// });
407
407
// });
408
408
} ) ;
409
+
410
+ describe ( 'verifyEmail' , ( ) => {
411
+ it ( 'should return an AccountsError' , async ( ) => {
412
+ const error = 'something bad' ;
413
+ Accounts . config ( { } , { verifyEmail : ( ) => Promise . reject ( { message : error } ) } ) ;
414
+ try {
415
+ await Accounts . verifyEmail ( ) ;
416
+ throw new Error ( ) ;
417
+ } catch ( err ) {
418
+ expect ( err . message ) . toEqual ( error ) ;
419
+ }
420
+ } ) ;
421
+
422
+ it ( 'should call transport.verifyEmail' , async ( ) => {
423
+ const mock = jest . fn ( ( ) => Promise . resolve ( ) ) ;
424
+ Accounts . config ( { } , { verifyEmail : mock } ) ;
425
+ await Accounts . verifyEmail ( 'token' ) ;
426
+ expect ( mock . mock . calls . length ) . toEqual ( 1 ) ;
427
+ expect ( mock . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'token' ) ;
428
+ } ) ;
429
+ } ) ;
430
+
431
+ describe ( 'resetPassword' , ( ) => {
432
+ it ( 'should return an AccountsError' , async ( ) => {
433
+ const error = 'something bad' ;
434
+ Accounts . config ( { } , { resetPassword : ( ) => Promise . reject ( { message : error } ) } ) ;
435
+ try {
436
+ await Accounts . resetPassword ( ) ;
437
+ throw new Error ( ) ;
438
+ } catch ( err ) {
439
+ expect ( err . message ) . toEqual ( error ) ;
440
+ }
441
+ } ) ;
442
+
443
+ it ( 'should call transport.resetPassword' , async ( ) => {
444
+ const mock = jest . fn ( ( ) => Promise . resolve ( ) ) ;
445
+ Accounts . config ( { } , { resetPassword : mock } ) ;
446
+ await Accounts . resetPassword ( 'token' , 'newPassword' ) ;
447
+ expect ( mock . mock . calls . length ) . toEqual ( 1 ) ;
448
+ expect ( mock . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'token' ) ;
449
+ expect ( mock . mock . calls [ 0 ] [ 1 ] ) . toEqual ( 'newPassword' ) ;
450
+ } ) ;
451
+ } ) ;
452
+
453
+ describe ( 'requestPasswordReset' , ( ) => {
454
+ it ( 'should return an AccountsError' , async ( ) => {
455
+ const error = 'something bad' ;
456
+ Accounts . config ( { } , { sendResetPasswordEmail : ( ) => Promise . reject ( { message : error } ) } ) ;
457
+ try {
458
+ await Accounts . requestPasswordReset ( ) ;
459
+ throw new Error ( ) ;
460
+ } catch ( err ) {
461
+ expect ( err . message ) . toEqual ( error ) ;
462
+ }
463
+ } ) ;
464
+
465
+ it ( 'should call transport.sendResetPasswordEmail' , async ( ) => {
466
+ const mock = jest . fn ( ( ) => Promise . resolve ( ) ) ;
467
+ Accounts . config ( { } , { sendResetPasswordEmail : mock } ) ;
468
+ await Accounts . requestPasswordReset ( 'email' ) ;
469
+ expect ( mock . mock . calls . length ) . toEqual ( 1 ) ;
470
+ expect ( mock . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'email' ) ;
471
+ } ) ;
472
+ } ) ;
473
+
474
+ describe ( 'requestVerificationEmail' , ( ) => {
475
+ it ( 'should return an AccountsError' , async ( ) => {
476
+ const error = 'something bad' ;
477
+ Accounts . config ( { } , { sendVerificationEmail : ( ) => Promise . reject ( { message : error } ) } ) ;
478
+ try {
479
+ await Accounts . requestVerificationEmail ( ) ;
480
+ throw new Error ( ) ;
481
+ } catch ( err ) {
482
+ expect ( err . message ) . toEqual ( error ) ;
483
+ }
484
+ } ) ;
485
+
486
+ it ( 'should call transport.sendVerificationEmail' , async ( ) => {
487
+ const mock = jest . fn ( ( ) => Promise . resolve ( ) ) ;
488
+ Accounts . config ( { } , { sendVerificationEmail : mock } ) ;
489
+ await Accounts . requestVerificationEmail ( 'email' ) ;
490
+ expect ( mock . mock . calls . length ) . toEqual ( 1 ) ;
491
+ expect ( mock . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'email' ) ;
492
+ } ) ;
493
+ } ) ;
409
494
} ) ;
0 commit comments