From 1f7bfddf0b3abf88948a682182b7512189eb49e3 Mon Sep 17 00:00:00 2001 From: "Cody B. Daig" Date: Fri, 14 Aug 2015 15:56:16 -0600 Subject: [PATCH] Make tests pass --- .../client/services/menus.client.service.js | 3 +++ .../tests/client/menus.client.service.tests.js | 17 +++++------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/modules/core/client/services/menus.client.service.js b/modules/core/client/services/menus.client.service.js index fd4411ea25..4273fbe927 100644 --- a/modules/core/client/services/menus.client.service.js +++ b/modules/core/client/services/menus.client.service.js @@ -14,6 +14,9 @@ angular.module('core').service('Menus', [ if (!!~this.roles.indexOf('*')) { return true; } else { + if(!user) { + return false; + } for (var userRoleIndex in user.roles) { for (var roleIndex in this.roles) { if (this.roles[roleIndex] === user.roles[userRoleIndex]) { diff --git a/modules/core/tests/client/menus.client.service.tests.js b/modules/core/tests/client/menus.client.service.tests.js index 68ad871ff7..adb4c76cd6 100644 --- a/modules/core/tests/client/menus.client.service.tests.js +++ b/modules/core/tests/client/menus.client.service.tests.js @@ -17,8 +17,8 @@ expect(Menus.menus.topbar).toBeDefined(); }); - it('should have default roles to *', function() { - expect(Menus.defaultRoles).toEqual(['*']); + it('should have default roles to user and admin', function() { + expect(Menus.defaultRoles).toEqual(['user', 'admin']); }); describe('addMenu', function() { @@ -42,7 +42,7 @@ }); it('should set shouldRender to shouldRender function handle', function() { - expect(menu.shouldRender()).toBeTruthy(); + expect(menu.shouldRender()).toBeFalsy(); }); }); @@ -79,13 +79,6 @@ it('should render if menu is public', function() { expect(menu.shouldRender()).toBeTruthy(); }); - - // it('should not render if menu is private', function() { - // menu = Menus.addMenu('menu1', { - // isPublic: false - // }); - // expect(menu.shouldRender()).toBeFalsy(); - // }); }); describe('when logged in', function() { @@ -259,8 +252,8 @@ expect(menuItem.isPublic).toBeFalsy(); }); - it('should set menu item roles to menu roles', function() { - expect(menuItem.roles).toEqual(menu.roles); + it('should set menu item roles to default roles', function() { + expect(menuItem.roles).toEqual(Menus.defaultRoles); }); it('should set menu item position to 0', function() {