From 3c3540497c4a28148ec5cd1bcefe8257fd86fb1c Mon Sep 17 00:00:00 2001 From: Avital Oliver Date: Mon, 8 Oct 2012 18:32:36 -0700 Subject: [PATCH] accounts: Allow specifying explicit errors in Meteor.validateNewUser --- packages/accounts-password/passwords_tests.js | 13 +++++++++++++ packages/accounts-password/passwords_tests_setup.js | 2 ++ 2 files changed, 15 insertions(+) diff --git a/packages/accounts-password/passwords_tests.js b/packages/accounts-password/passwords_tests.js index a87fb97071..3add07dc33 100644 --- a/packages/accounts-password/passwords_tests.js +++ b/packages/accounts-password/passwords_tests.js @@ -156,6 +156,19 @@ if (Meteor.isClient) (function () { {invalid: true}, // should fail the new user validators expect(function (error) { test.equal(error.error, 403); + test.equal( + error.reason, + "User validation failed"); + })); + }, + logoutStep, + function(test, expect) { + Accounts.createUser({username: username3, password: password3}, + {invalidAndThrowException: true}, // should fail the new user validator with a special exception + expect(function (error) { + test.equal( + error.reason, + "An exception thrown within Accounts.validateNewUser"); })); }, // test Accounts.onCreateUser diff --git a/packages/accounts-password/passwords_tests_setup.js b/packages/accounts-password/passwords_tests_setup.js index 8b1a0d623e..8421f3576a 100644 --- a/packages/accounts-password/passwords_tests_setup.js +++ b/packages/accounts-password/passwords_tests_setup.js @@ -1,4 +1,6 @@ Accounts.validateNewUser(function (user) { + if (user.invalidAndThrowException) + throw new Meteor.Error(403, "An exception thrown within Accounts.validateNewUser"); return !user.invalid; });