From c5e27a83ba88eecae00a28283f8ad93bc83916d0 Mon Sep 17 00:00:00 2001 From: Mitar Date: Sun, 2 Oct 2016 12:57:07 -0700 Subject: [PATCH] Test for making sure userIsInRole returns false for unknown roles. See: #204 --- roles/tests/server.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/roles/tests/server.js b/roles/tests/server.js index 45cabbd..e6f6f58 100644 --- a/roles/tests/server.js +++ b/roles/tests/server.js @@ -2589,6 +2589,28 @@ }, /form a cycle/); }); + Tinytest.add( + 'roles - userIsInRole returns false for unknown roles', + function (test) { + reset(); + + Roles.createRole('admin'); + Roles.createRole('user'); + Roles.createRole('editor'); + Roles.addUsersToRoles(users.eve, ['admin', 'user']); + Roles.addUsersToRoles(users.eve, ['editor']); + + test.isFalse(Roles.userIsInRole(users.eve, 'unknown')); + test.isFalse(Roles.userIsInRole(users.eve, [])); + test.isFalse(Roles.userIsInRole(users.eve, null)); + test.isFalse(Roles.userIsInRole(users.eve, undefined)); + + test.isFalse(Roles.userIsInRole(users.eve, 'unknown', {anyScope: true})); + test.isFalse(Roles.userIsInRole(users.eve, [], {anyScope: true})); + test.isFalse(Roles.userIsInRole(users.eve, null, {anyScope: true})); + test.isFalse(Roles.userIsInRole(users.eve, undefined, {anyScope: true})); + }); + function printException (ex) { var tmp = {}; for (var key in ex) {