SmartIT_Extensions/BMC/smart-it-full/test/security/permission-model.spec.js

72 lines
2.6 KiB
JavaScript

/*** Created by npatil2.*/
describe('service: permissionModel', function () {
var $httpBackend, $rootScope, scope, response;
beforeEach(module('myitsmApp'));
beforeEach(inject(function ($rootScope, $injector,events, AUTH_EVENTS, roles) {
scope = $rootScope.$new();
this.events = events;
this.AUTH_EVENTS = AUTH_EVENTS;
this.roles = roles;
$httpBackend = $injector.get('$httpBackend');
var getLocale = function () {
return readJSON('scripts/app/i18n/resources-locale_en.json');
};
$httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(getLocale());
$httpBackend.whenGET('/smartit/rest/serverstates').respond(200);
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
$httpBackend.whenGET('views/dashboard/index.html').respond(200);
$rootScope = $injector.get('$rootScope');
this.permissionModel = $injector.get('permissionModel');
}));
it('should be defined', function () {
expect(this.permissionModel).toBeDefined();
});
it('should set Permissions', function () {
this.permissions='write';
this.permissionModel.setPermissions(this.permissions);
});
it('should set Permissions', function () {
this.permissions='write';
this.myResult=this.permissionModel.hasPermission(this.permissions);
});
it('should set Permissions', function () {
this.myResult=this.permissionModel.hasAdminOnlyRole();
console.log(this.myResult);
expect( this.myResult).toBe(false);
});
it('should has Knowledge Only Role', function () {
this.myResult=this.permissionModel.hasKnowledgeOnlyRole();
expect( this.myResult).toBe(false);
});
it('should trigger PERSON_PERMISSION_DATA_LOADED',inject( function ($rootScope) {
$rootScope.$broadcast(this.events.PERSON_PERMISSION_DATA_LOADED,'test');
}));
it('should give task ticket edit permission if user is Problem user', inject(function ($rootScope) {
var rolesList = [
{"id":"galileo-admin-access","permission":"write"},
{"id":"galileo-knowledge-access","permission":"read"},
{"id":"galileo-problem-access","permission":"write"},
{"id":"galileo-asset-access","permission":"read"}
];
$rootScope.$broadcast(this.events.PERSON_PERMISSION_DATA_LOADED, rolesList);
var result = this.permissionModel.hasPermissionForTicket(EntityVO.TYPE_TASK);
expect(result).toBe(true);
result = this.permissionModel.hasPermissionForTicket(EntityVO.TYPE_CHANGE);
expect(result).toBe(false);
}));
});