SmartIT_Extensions/BMC/smart-it-full/test/app/admin/console-config/admin-console-configuration...

162 lines
6.6 KiB
JavaScript

/**
* Created by mkumar1 on 16-04-2018.
*/
describe('service: adminConsoleConfigurationModel', function () {
var $httpBackend, $rootScope, scope;
beforeEach(module('myitsmApp'));
beforeEach(inject(function ($injector, $rootScope, adminConsoleConfigurationService, $q, systemAlertService, $filter) {
scope = $rootScope.$new();
$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.adminConsoleConfigModel = $injector.get('adminConsoleConfigurationModel');
this.adminConsoleConfigService = adminConsoleConfigurationService;
this.$q = $q;
this.systemAlertService = systemAlertService;
this.$filter = $filter;
}));
beforeEach(inject(function ($q) {
var deferred = $q.defer(),
providers = [{
"id": "e78f14bc-2675-417d-bee3-8cca13e4127d",
"name": "SRM pluggable provider",
"publishedServices": ["CatalogService", "IncidentService", "ApprovalService", "CategoryService", "SrService", "PersonService"],
"settings": [{
"id": "3f9a3c6b-2301-4400-8cde-392cd03d604b",
"key": "mid_tier.base.url",
"value": "http://clm-pun-003257.bmc.com:8080/arsys",
"createDate": null,
"modifiedDate": null
}, {
"id": "b039e824-e110-4915-935b-14e13db870b5",
"key": "obo.enabled.for.all",
"value": "false",
"createDate": null,
"modifiedDate": null
}],
"active": true,
"enabled": true,
"defaultSettings": [{
"id": null,
"key": "connect.arsystem.port",
"value": "0",
"createDate": null,
"modifiedDate": null
}, {
"id": null,
"key": "connect.arsystem.password",
"value": "password",
"createDate": null,
"modifiedDate": null
}],
"instanceName": "srm"
}],
activeUsers = {
"items": [{
"userId": "Allen",
"userFirstName": null,
"userLastName": null,
"userEmail": null,
"lastWebLoginDate": null,
"lastIOsLoginDate": null,
"lastAndroidLoginDate": 1523872886662
}, {
"userId": "ios",
"userFirstName": null,
"userLastName": null,
"userEmail": "ios@bmc.com",
"lastWebLoginDate": null,
"lastIOsLoginDate": null,
"lastAndroidLoginDate": 1523877362611
}, {
"userId": "tuser",
"userFirstName": null,
"userLastName": null,
"userEmail": null,
"lastWebLoginDate": null,
"lastIOsLoginDate": null,
"lastAndroidLoginDate": 1523876131742
}, {
"userId": "vuser",
"userFirstName": null,
"userLastName": null,
"userEmail": null,
"lastWebLoginDate": null,
"lastIOsLoginDate": null,
"lastAndroidLoginDate": 1523865207746
}],
"totalItemCount": 4
},
clientTypes = {
"items": [{
"clientType": "ANDROID",
"activeUserCount": 4
}, {
"clientType": "WEB",
"activeUserCount": 0
}, {
"clientType": "IOS",
"activeUserCount": 0
}]
};
spyOn(this.adminConsoleConfigService, 'getDataByMenuItem').and.callFake(function () {
deferred.resolve(providers);
return deferred.promise;
});
spyOn(this.adminConsoleConfigService, 'getActiveUsers').and.callFake(function () {
deferred.resolve(activeUsers);
return deferred.promise;
});
spyOn(this.adminConsoleConfigService, 'getClientTypesUsage').and.callFake(function () {
deferred.resolve(clientTypes);
return deferred.promise;
});
}));
it(' should return List Of providers ', function () {
this.myResult = this.adminConsoleConfigModel.getDataByMenuItem();
scope.$apply();
expect(this.myResult.$$state.status).toEqual(1);
expect(this.myResult.$$state.value[0].id).toEqual('e78f14bc-2675-417d-bee3-8cca13e4127d');
expect(this.myResult.$$state.value[0].name).toEqual('SRM pluggable provider');
expect(this.myResult.$$state.value[0].settings).toEqual(jasmine.any(Array));
});
it(' should return List Of active users ', function () {
this.myResult = this.adminConsoleConfigModel.getActiveUsers();
scope.$apply();
expect(this.myResult.$$state.status).toEqual(1);
expect(this.myResult.$$state.value.items[0].userId).toEqual('Allen');
expect(this.myResult.$$state.value.items[1].userId).toEqual('ios');
});
it(' should return List Of client types ', function () {
this.myResult = this.adminConsoleConfigModel.getClientTypesUsage();
scope.$apply();
expect(this.myResult.$$state.status).toEqual(1);
expect(this.myResult.$$state.value.items[0].clientType).toEqual('ANDROID');
expect(this.myResult.$$state.value.items[0].activeUserCount).toEqual(4);
expect(this.myResult.$$state.value.items[1].clientType).toEqual('WEB');
expect(this.myResult.$$state.value.items[1].activeUserCount).toEqual(0);
expect(this.myResult.$$state.value.items[2].clientType).toEqual('IOS');
expect(this.myResult.$$state.value.items[2].activeUserCount).toEqual(0);
});
});