SmartIT_Extensions/BMC/smart-it-full/test/app/person/person-model.spec.js

486 lines
22 KiB
JavaScript

/*** Created by npatil2.*/
describe('service: personModel', function () {
var $httpBackend, $rootScope, scope, response;
beforeEach(module('myitsmApp'));
beforeEach(inject(function ($rootScope, $injector, personService, $q, configurationModel, systemAlertService, userModel) {
scope = $rootScope.$new();
this.personService = personService;
this.configurationModel = configurationModel;
this.systemAlertService = systemAlertService;
this.userModel = userModel;
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);
$rootScope = $injector.get('$rootScope');
this.personModel = $injector.get('personModel');
}));
beforeEach(inject(function ($q) {
var deferred = $q.defer(), data = {
firstName: 'Parul',
lastName: 'Shah',
fullName: 'Parul Shah',
totalMatches: 5,
department: 'Payroll',
email: 'pshah@petramco.com',
company: {
name: 'Petramco'
},
phone: '55 21 5555-0009',
organization: 'Human Resources',
loginId: 'pshah',
manager: {
fullName: 'Matthew M Murdock',
loginId: 'mmurdock',
customFields: {}
},
costCenter: '',
openTickets: 0,
accessMappings: {
detailsEditAllowed: true,
timelineEditAllowed: true,
relationsEditAllowed: false
},
personId: 'GPL000000000145',
id: 'GPL000000000145',
ticketList: ['test', 'email']
}, SummaryStats = [
{
name: 'service-summary',
primaryGroupBy: null,
statsMetrics: [
{
name: 'Number of Ratings',
value: 5
},
{
name: 'Average Rating',
value: 8
},
{
name: 'Number of Escalations',
value: 10
}
]
}
];
spyOn(this.personService, 'getPersonDetailsByID').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'getListOfPersonByName').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'getListOfPersonNamesByName').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'getPersonAssets').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'getKnowledgeArticles').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'getOrganizationList').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'getDepartmentList').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'getSiteList').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'followPerson').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'unfollowPerson').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'createPerson').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'searchPersonInSocialByNameQuery').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'getTickets').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'getAssignedTickets').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'updatePersonInfo').and.callFake(function () {
deferred.resolve(data);
return deferred.promise;
});
spyOn(this.personService, 'getServiceSummaryStats').and.callFake(function () {
deferred.resolve(SummaryStats);
return deferred.promise;
});
spyOn(this.personService, 'getServiceBrokerTickets').and.callFake(function () {
var sbeData = readJSON('mocks/user-sberequest-workitems.json');
deferred.resolve({
ticketList: sbeData[0].items[0].objects,
totalMatches: sbeData[0].items[0].totalMatches
});
return deferred.promise;
});
}));
it('should be defined', function () {
expect(this.personModel).toBeDefined();
});
it('should return Person Details By ID ', function () {
this.personId = 'GPL000000000145';
this.myResult = this.personModel.getPersonDetailsByID(this.personId);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
});
it('should return List Of Person By Name', function () {
this.firstName = 'Parul';
this.lastName = 'Shah';
this.myResult = this.personModel.getListOfPersonByName(this.firstName, this.lastName);
scope.$apply();
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
});
it('should return List Of Persons By Text ', function () {
this.searchText = 'GPL000000000145';
this.myResult = this.personModel.getListOfPersonsByText(this.searchText);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
});
it('should return List Of Change Manager By Text ', function () {
this.searchText = 'GPL000000000145';
this.myResult = this.personModel.getListOfChangeManagerByText(this.searchText);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
});
it('should return List Of Change Coordinator By Text ', function () {
this.searchText = 'GPL000000000145';
this.myResult = this.personModel.getListOfChangeCoordinatorByText(this.searchText);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
});
it('should return List Of Problem Coordinator By Text', function () {
this.searchText = 'GPL000000000145';
this.myResult = this.personModel.getListOfProblemCoordinatorByText(this.searchText);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
});
it('should return List Of Release Coordinator By Text', function () {
this.searchText = 'GPL000000000145';
this.myResult = this.personModel.getListOfReleaseCoordinatorByText(this.searchText);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
});
it('should return List Of Person Names By Text', function () {
this.searchText = 'GPL000000000145';
this.myResult = this.personModel.getListOfPersonNamesByText(this.searchText);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
});
it('should return Person Assets', function () {
this.personId = 'GPL000000000145';
this.showAllAssets = 'testshowAllAssets';
this.myResult = this.personModel.getPersonAssets(this.personId, this.showAllAssets);
scope.$apply();
expect(this.personModel.personAssets.firstName).toBe('Parul');
expect(this.personModel.personAssets.department).toBe('Payroll');
expect(this.personModel.personAssets.organization).toBe('Human Resources');
expect(this.personModel.personAssets.accessMappings.timelineEditAllowed).toBe(true);
expect(this.personModel.personAssets.accessMappings.detailsEditAllowed).toBe(true);
});
it('should return Knowledge Articles', function () {
this.personId = 'GPL000000000145';
this.showAllAssets = 'testshowAllAssets';
this.myResult = this.personModel.getKnowledgeArticles(this.personId, this.showAllAssets);
scope.$apply();
expect(this.personModel.personKnowledgeArticles.firstName).toBe('Parul');
expect(this.personModel.personKnowledgeArticles.department).toBe('Payroll');
expect(this.personModel.personKnowledgeArticles.organization).toBe('Human Resources');
expect(this.personModel.personKnowledgeArticles.accessMappings.timelineEditAllowed).toBe(true);
expect(this.personModel.personKnowledgeArticles.accessMappings.detailsEditAllowed).toBe(true);
});
it('should return Organization List', function () {
this.companyName = 'Petramco';
this.myResult = this.personModel.getOrganizationList(this.companyName);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
});
it('should return Department List', function () {
this.companyName = 'Petramco';
this.organizationName = 'Human Resources';
this.myResult = this.personModel.getDepartmentList(this.companyName, this.organizationName);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
});
it('should return Site List', function () {
this.companyName = 'Petramco';
this.myResult = this.personModel.getSiteList(this.companyName);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
});
it('should follow Person', function () {
this.userLoginId = 'pshah';
this.personId = 'GPL000000000145';
this.myResult = this.personModel.followPerson(this.userLoginId, this.personId);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
});
it('should unfollow Person', function () {
this.userLoginId = 'pshah';
this.personId = 'GPL000000000145';
this.myResult = this.personModel.unfollowPerson(this.userLoginId, this.personId);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
});
it('should create Person', function () {
this.personData = {
firstName: 'Parul',
lastName: 'Shah',
fullName: 'Parul Shah',
department: 'Payroll',
email: 'pshah@petramco.com',
company: {
name: 'Petramco'
},
phone: '55 21 5555-0009',
organization: 'Human Resources',
loginId: 'pshah',
available: 'OFFLINE',
customFields: {},
following: false,
type: 'person',
isVIP: false,
deskLocation: '',
costCenter: '',
openTickets: 0,
accessMappings: {
detailsEditAllowed: true,
timelineEditAllowed: true,
relationsEditAllowed: false
},
personId: 'GPL000000000145',
id: 'pshah'
};
this.myResult = this.personModel.createPerson(this.personData);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
});
it('should unfollow Person', function () {
this.keyword = 'GPL000000000145';
this.myResult = this.personModel.searchPersonInSocialByNameQuery(this.keyword);
scope.$apply();
expect(this.myResult.$$state.value.firstName).toBe('Parul');
expect(this.myResult.$$state.value.department).toBe('Payroll');
expect(this.myResult.$$state.value.organization).toBe('Human Resources');
expect(this.myResult.$$state.value.accessMappings.timelineEditAllowed).toBe(true);
expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true);
this.keyword = null;
this.myResult = this.personModel.searchPersonInSocialByNameQuery(this.keyword);
scope.$apply();
expect(this.myResult.$$state.value).toBeDefined();
});
it('should Open Tickets ', function () {
this.startIndex = 1;
this.personId = 'GPL000000000145';
this.myResult = this.personModel.getOpenTickets(this.personId, this.startIndex);
scope.$apply();
expect(this.personModel.personOpenTickets.totalMatches).toEqual(5);
this.startIndex = -1;
this.myResult = this.personModel.getOpenTickets(this.personId, this.startIndex);
expect(this.personModel.personOpenTickets.ticketList).toBeTruthy();
});
it('should return Closed Tickets ', function () {
this.startIndex = 1;
this.personId = 'GPL000000000145';
this.myResult = this.personModel.getClosedTickets(this.personId, this.startIndex);
scope.$apply();
expect(this.personModel.personClosedTickets.totalMatches).toEqual(5);
this.startIndex = -1;
this.myResult = this.personModel.getClosedTickets(this.personId, this.startIndex);
expect(this.personModel.personClosedTickets.ticketList).toBeTruthy();
});
it('should return Closed Tickets ', function () {
this.startIndex = 1;
this.personId = 'GPL000000000145';
this.myResult = this.personModel.getAllTickets(this.personId, this.startIndex);
scope.$apply();
expect(this.personModel.personAllTickets.totalMatches).toEqual(5);
this.startIndex = -1;
this.myResult = this.personModel.getAllTickets(this.personId, this.startIndex);
expect(this.personModel.personAllTickets.ticketList).toBeTruthy();
});
it('should return Assigned Tickets ', function () {
this.startIndex = 1;
this.personId = 'GPL000000000145';
this.myResult = this.personModel.getAssignedTickets(this.personId, this.startIndex);
scope.$apply();
expect(this.personModel.personAssignedTickets.totalMatches).toEqual(5);
this.startIndex = -1;
this.myResult = this.personModel.getAssignedTickets(this.personId, this.startIndex);
expect(this.personModel.personAssignedTickets.ticketList).toBeTruthy();
});
it('should return update Person Info ', function () {
this.id = 'GPL000000000145';
this.data = {
test: 'data1'
};
this.userModel.userFullData = {
id: 'GPL000000000145'
};
this.myResult = this.personModel.updatePersonInfo(this.id, this.data);
scope.$apply();
expect(this.userModel.userFullData).toBeTruthy();
expect(this.personModel.personDetails.firstName).toBe('Parul');
expect(this.personModel.personDetails.department).toBe('Payroll');
expect(this.personModel.personDetails.organization).toBe('Human Resources');
expect(this.personModel.personDetails.accessMappings.timelineEditAllowed).toBe(true);
expect(this.personModel.personDetails.accessMappings.detailsEditAllowed).toBe(true);
});
it('should return Service Summary Stats ', function () {
this.id = 'Allen';
this.myResult = this.personModel.getServiceSummaryStats(this.id);
scope.$apply();
expect(this.personModel.serviceSummaryRaw).toBeTruthy();
expect(this.personModel.serviceSummary.ratingCount).toEqual(5);
expect(this.personModel.serviceSummary.ratingScore).toEqual(8);
expect(this.personModel.serviceSummary.escalation).toEqual(10);
});
it('should return open service broker records ', function () {
this.id = 'Allen';
this.personModel.getOpenServiceBrokerTickets(this.id);
scope.$apply();
expect(this.personService.getServiceBrokerTickets).toHaveBeenCalled();
expect(this.personModel.personOpenServiceBrokerTickets.ticketList).toBeTruthy();
expect(this.personModel.personOpenServiceBrokerTickets.totalMatches).toBe(5);
});
it('should return closed service broker records ', function () {
this.id = 'Allen';
this.personModel.getClosedServiceBrokerTickets(this.id);
scope.$apply();
expect(this.personService.getServiceBrokerTickets).toHaveBeenCalled();
expect(this.personModel.personClosedServiceBrokerTickets.ticketList).toBeTruthy();
expect(this.personModel.personClosedServiceBrokerTickets.totalMatches).toBe(5);
});
});