diff --git a/packages/accounts-password/password_client.js b/packages/accounts-password/password_client.js index bc1478507f..28e2787c4f 100644 --- a/packages/accounts-password/password_client.js +++ b/packages/accounts-password/password_client.js @@ -220,7 +220,12 @@ Accounts.forgotPassword = function(options, callback) { if (!options.email) { return reportError(new Meteor.Error(400, "Must pass options.email"), callback); } - Accounts.connection.call("forgotPassword", options, callback); + + if (callback) { + Accounts.connection.call("forgotPassword", options, callback); + } else { + Accounts.connection.call("forgotPassword", options); + } }; // Resets a password based on a token originally created by diff --git a/packages/accounts-password/password_tests.js b/packages/accounts-password/password_tests.js index 1d9467d6b5..3a3e564f21 100644 --- a/packages/accounts-password/password_tests.js +++ b/packages/accounts-password/password_tests.js @@ -2,7 +2,7 @@ Accounts._noConnectionCloseDelayForTest = true; if (Meteor.isServer) { Accounts.removeDefaultRateLimit(); - + Meteor.methods({ getResetToken: function () { var token = Meteor.users.findOne(this.userId).services.password.reset; @@ -557,8 +557,8 @@ if (Meteor.isClient) (function () { }, 10 * 1000, 100); } ]); - - + + testAsyncMulti("passwords - forgotPassword client return error when empty email", [ function (test, expect) { // setup @@ -578,7 +578,36 @@ if (Meteor.isClient) (function () { }, /Must pass options\.email/); }, ]); - + + Tinytest.add( + 'passwords - forgotPassword only passes callback value to forgotPassword ' + + 'Method if callback is defined (to address issue #5676)', + function (test) { + let methodCallArgumentCount = 0; + const originalMethodCall = Accounts.connection.call; + const stubMethodCall = (...args) => { + methodCallArgumentCount = args.length; + } + Accounts.connection.call = stubMethodCall; + + Accounts.forgotPassword({ email: 'test@meteor.com' }); + test.equal( + methodCallArgumentCount, + 2, + 'Method call should have 2 arguments since no callback is passed in' + ); + + Accounts.forgotPassword({ email: 'test@meteor.com' }, () => {}); + test.equal( + methodCallArgumentCount, + 3, + 'Method call should have 3 arguments since a callback is passed in' + ); + + Accounts.connection.call = originalMethodCall; + } + ); + testAsyncMulti("passwords - verifyEmail client return error when empty token", [ function (test, expect) { // setup @@ -598,7 +627,7 @@ if (Meteor.isClient) (function () { }, /Need to pass token/); }, ]); - + testAsyncMulti("passwords - resetPassword errors", [ function (test, expect) { // setup