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

111 lines
3.6 KiB
JavaScript

/*** Created by npatil2 .*/
describe('service: authModel', function () {
var $httpBackend, $rootScope, scope, myResult;
beforeEach(module('myitsmApp'));
beforeEach(inject(function ($rootScope, $injector, authService, session, $window, AUTH_EVENTS, systemAlertService, $filter, $q) {
scope = $rootScope.$new();
this.authService = authService;
this.session = session;
this.$window = $window;
this.AUTH_EVENTS = AUTH_EVENTS;
this.systemAlertService = systemAlertService;
this.$filter = $filter;
this.$q = $q;
$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);
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200);
$rootScope = $injector.get('$rootScope');
this.authModel = $injector.get('authModel');
}));
beforeEach(inject(function ($q, $rootScope) {
var deferred = $q.defer();
spyOn(this.authService, 'login').and.callFake(function () {
deferred.resolve('sucess');
return deferred.promise;
});
spyOn(this.authService, 'logout').and.callFake(function () {
deferred.resolve('sucess');
return deferred.promise;
});
spyOn(this.authService, 'isSSOEnabled').and.callFake(function () {
deferred.resolve('sucess');
return deferred.promise;
});
spyOn(this.authService, 'serverState').and.callFake(function () {
deferred.resolve('sucess');
return deferred.promise;
});
spyOn(this.authService, 'sessionStatus').and.callFake(function () {
deferred.resolve('sucess');
return deferred.promise;
});
}));
it('should be defined', function () {
expect(this.authModel).toBeDefined();
});
it('should login', function () {
this.userId = 'Allen';
this.password = 'password';
this.authModel.login(this.userId, this.password).then(function (data) {
myResult = data;
});
scope.$apply();
expect(myResult).toEqual('sucess');
});
it('should logout', function () {
this.authModel.logout().then(function (data) {
myResult = data;
});
scope.$apply();
expect(myResult).toEqual('sucess');
});
it('should is SSOEnabled', function () {
this.authModel.isSSOEnabled().then(function (data) {
myResult = data;
});
scope.$apply();
expect(myResult).toEqual('sucess');
});
it('should is Authorized', function () {
this.authorizedRoles = false;
myResult = this.authModel.isAuthorized(this.authorizedRoles);
expect(myResult).toEqual(false);
this.authorizedRoles=[];
myResult = this.authModel.isAuthorized(this.authorizedRoles);
expect(myResult).toEqual( true);
this.authorizedRoles=['test','test1'];
myResult = this.authModel.isAuthorized(this.authorizedRoles);
expect(myResult).toEqual( false)
});
it('should is check Session Status', function () {
this.session.alive=true;
this.authModel.checkSessionStatus();
scope.$apply();
});
});