/*** Created by npatil2.*/ describe('service: knowledgeArticleModel', function () { var $httpBackend, $rootScope, scope, article; beforeEach(module('myitsmApp')); beforeEach(inject(function ($injector, knowledgeArticleService, $q, searchService, configurationModel, metadataModel, $rootScope) { 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); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200); $httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200); $httpBackend.whenGET('/smartit/rest/knowledge/assessment/questions?companyName=test+companyName&organization=test+organization').respond(200); $rootScope = $injector.get('$rootScope'); this.knowledgeArticleModel = $injector.get('knowledgeArticleModel'); this.knowledgeArticleService = knowledgeArticleService; this.$q = $q; this.searchService = searchService; this.configurationModel = configurationModel; this.metadataModel = metadataModel; })); beforeEach(inject(function ($q) { var deferred = $q.defer(), data = 'success'; article = { title: 'email', type: 'knowledge', articleId: 'KBA00000324', status: { value: 'Work In Progress' }, following: true, tags: [], entityLink: '#/knowledge/AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS', uuid: 'AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS', templateId: 'ID005056A6052Buo7VSwQaxSAQO5MB', additionalCategoriesCompanies: [ { name: 'Calbro Services', id: '000000000000204' } ], additionalCategorization: [], articleVisibilityGroup: [ { visibilityGroupName: 'ALL', company: 'Calbro Services', visibilityGroupId: '0', id: '000000000000302' } ], comments: [], hashTags: [], accessMappings: { detailsEditAllowed: true, statusEditAllowed: true, companyEditAllowed: true, assigneeEditAllowed: true, visibilitygroupsEditAllowed: true, attachmentsEditAllowed: true, relationsEditAllowed: true, timelineEditAllowed: true, internaluseEditAllowed: true, flagEditAllowed: true, unflagEditAllowed: true, keywordsEditAllowed: true, categorizationEditAllowed: true, 'assignee-self-assignmentEditAllowed': false, helpfulEditAllowed: true, printEditAllowed: true }, assigneeGroup: { name: 'CA Support 1', company: { name: 'Petramco' }, organization: 'Canada Support', id: 'GGP000000000004' }, supportGroup: { name: 'CA Support 1', company: { name: 'Petramco' }, organization: 'Canada Support', id: 'GGP000000000004' }, allCategories: [] }; spyOn(this.knowledgeArticleService, 'updateQuestionSet').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'createQuestionSet').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'deleteQuestionSetById').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getQuestionSetById').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getQuestionSetList').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'submitAssessment').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getPotentialPrimary').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'updateTemplateStyles').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getKnowledgeArticleTemplates').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'checkEditStatus').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'removeAutoSavedCopy').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'autoSave').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getAutoSavedCopy').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'updateArticle').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'createArticle').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getProblemDraft').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getIncidentDraft').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getKnownErrorDraft').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getWorkorderDraft').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getDraft').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getVisibility').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'incrementViewCount').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getArticleById').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getArticleRevisions').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getVisibilityByText').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'rateArticle').and.callFake(function () { deferred.resolve(article); return deferred.promise; }); spyOn(this.knowledgeArticleService, 'getAssessmentQuestions').and.callFake(function () { deferred.resolve(data); return deferred.promise; }); })); it('should return Knowledge Article By Id', function () { this.knowledgeArticleModel.articles = ['test', 'test1', 'test2']; this.ignoreCache = false; this.preventIncrement = false; this.id = 0; this.myResult = this.knowledgeArticleModel.getKnowledgeArticleById(this.id, this.ignoreCache, this.preventIncrement); scope.$apply(); expect(this.myResult.$$state.value).toEqual('test'); this.ignoreCache = true; this.myResult = this.knowledgeArticleModel.getKnowledgeArticleById(this.id, this.ignoreCache, this.preventIncrement); scope.$apply(); expect(this.myResult.$$state.value).toEqual(article); expect(this.myResult.$$state.value.title).toEqual('email'); expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true); expect(this.myResult.$$state.value.uuid).toBe('AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS'); }); it('should return Article Revisions By Id ', function () { this.id = 0; this.knowledgeArticleModel.articleRevisions = [false, false, false]; this.myResult = this.knowledgeArticleModel.getArticleRevisionsById(this.id); scope.$apply(); expect(this.myResult.$$state.value).toEqual(article); expect(this.myResult.$$state.value.title).toEqual('email'); expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true); expect(this.myResult.$$state.value.uuid).toBe('AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS'); }); it('should return Visibility of Groups By Text ', function () { this.companyName = 'CollabroService'; this.searchText = 'incident'; this.chunkSize = 2; this.myResult = this.knowledgeArticleModel.getVisibilityGroupsByText(this.companyName, this.searchText, this.chunkSize); scope.$apply(); expect(this.myResult.$$state.value).toEqual(article); expect(this.myResult.$$state.value.title).toEqual('email'); expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true); expect(this.myResult.$$state.value.uuid).toBe('AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS'); }); it('should rate Article ', function () { this.articleId = 0; this.vote = 'yes'; this.knowledgeArticleModel.articles = [{ voted: 'no', useCount: 0, recalculateRating: function () { return } }]; this.myResult = this.knowledgeArticleModel.rateArticle(this.articleId, this.vote); scope.$apply(); expect(this.knowledgeArticleModel.articles[0].voted).toEqual('yes'); expect(this.knowledgeArticleModel.articles[0].useCount).toEqual(1); }); it('should update Question Set', function () { this.questionSetId = 1; this.postdata = 'test'; this.myResult = this.knowledgeArticleModel.updateQuestionSet(this.questionSetId, this.postdata); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should create Question Set', function () { this.postdata = 'test post data'; this.myResult = this.knowledgeArticleModel.createQuestionSet(this.postdata); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should remove Question Set By Id ', function () { this.questionSetId = 1234; this.myResult = this.knowledgeArticleModel.deleteQuestionSetById(this.questionSetId); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should return Question Set By Id ', function () { this.questionSetId = 1234; this.myResult = this.knowledgeArticleModel.getQuestionSetById(this.questionSetId); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should return Question Set List ', function () { this.questionSetId = 1234; this.myResult = this.knowledgeArticleModel.getQuestionSetList(this.questionSetId); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should submit Assessment ', function () { this.questionSetId = 1234; this.answers = 'test success'; this.myResult = this.knowledgeArticleModel.submitAssessment(this.questionSetId, this.answers); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should return Assessment Questions', function () { this.companyName = 'test companyName'; this.organization = 'test organization'; this.myResult = this.knowledgeArticleModel.getAssessmentQuestions(this.companyName, this.organization); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should clear Visited Articles For Ticket', function () { this.ticketId = 0; this.knowledgeArticleModel.visitedArticlesCache = ['test', 'test1', 'test3']; this.myResult = this.knowledgeArticleModel.clearVisitedArticlesForTicket(this.ticketId); expect(this.knowledgeArticleModel.visitedArticlesCache).toEqual({}); }); it('should return Visited Articles For Ticket ', function () { this.ticketId = 0; this.knowledgeArticleModel.visitedArticlesCache = ['test', 'test1', 'test3']; this.myResult = this.knowledgeArticleModel.getVisitedArticlesForTicket(this.ticketId); expect(this.myResult).toBe('test'); this.ticketId = 123; this.myResult = this.knowledgeArticleModel.getVisitedArticlesForTicket(this.ticketId); expect(this.myResult).toBe(null); }); it('should mark Visited Article', function () { this.ticketId = 3; this.articleId = 0; this.knowledgeArticleModel.visitedArticlesCache = ['test', 'test1', 'test3']; this.knowledgeArticleModel.markArticleVisited(this.articleId, this.ticketId); expect(this.knowledgeArticleModel.visitedArticlesCache).toBeTruthy(); }); it('should return Primary Potential ', function () { this.params = ['test', 'test1', 'test3']; this.myResult = this.knowledgeArticleModel.getPotentialPrimary(this.params); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should update Template Styles ', function () { this.templateID = 1; this.styles = ['test', 'test1', 'test3']; this.myResult = this.knowledgeArticleModel.updateTemplateStyles(this.templateID, this.styles); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should return Knowledge Article Templates ', function () { this.myResult = this.knowledgeArticleModel.getKnowledgeArticleTemplates(); scope.$apply(); expect(this.knowledgeArticleModel.knowledgeArticleTemplates).toBeTruthy(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should return Visibility By Company Name ', function () { this.companyName = 'test'; this.chunkSize = 2; this.knowledgeArticleModel.visibilities = { 'Calbro Services': { company: 'Calbro Services', id: '000000000000302', visibilityGroupId: '0', visibilityGroupName: 'ALL' } }; this.myResult = this.knowledgeArticleModel.getVisibilityByCompanyName(this.companyName, this.chunkSize); scope.$apply(); expect(this.myResult.$$state.value.title).toEqual('email'); expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true); expect(this.myResult.$$state.value.uuid).toBe('AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS'); this.companyName = 'Calbro Services'; this.myResult = this.knowledgeArticleModel.getVisibilityByCompanyName(this.companyName, this.chunkSize); scope.$apply(); expect(this.myResult.$$state.value.company).toEqual('Calbro Services'); expect(this.myResult.$$state.value.id).toEqual('000000000000302'); expect(this.myResult.$$state.value.visibilityGroupId).toEqual('0'); expect(this.myResult.$$state.value.visibilityGroupName).toEqual('ALL'); }); it('should return Draft ', function () { this.templateId = 1; this.context = { type: 'problem' }; this.myResult = this.knowledgeArticleModel.getDraft(this.templateId, this.context); scope.$apply(); expect(this.myResult.$$state.value).toEqual(article); this.context = { type: 'incident' }; this.myResult = this.knowledgeArticleModel.getDraft(this.templateId, this.context); scope.$apply(); expect(this.myResult.$$state.value).toEqual(article); this.context = { type: 'knownerror' }; this.myResult = this.knowledgeArticleModel.getDraft(this.templateId, this.context); scope.$apply(); expect(this.myResult.$$state.value).toEqual(article); this.context = { type: 'workorder' }; this.myResult = this.knowledgeArticleModel.getDraft(this.templateId, this.context); scope.$apply(); expect(this.myResult.$$state.value).toEqual(article); this.context = { type: 'test' }; this.myResult = this.knowledgeArticleModel.getDraft(this.templateId, this.context); scope.$apply(); expect(this.myResult.$$state.value).toEqual(article); expect(this.myResult.$$state.value.title).toEqual('email'); expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true); expect(this.myResult.$$state.value.uuid).toBe('AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS'); }); it('should merge Article Meta Data', function () { this.oldArticle = { visibility: true, author: 'test', selectedAssignee: 'test selectedAssignee', tags: 'test tag', allSites: 'all sites', allServices: 'all services', allOrganizations: 'all orgnization', linkedItems: 'linkedItems', title: 'title' }; this.article = { visibility: true, author: 'test', selectedAssignee: 'test selectedAssignee', tags: 'test tag', allSites: 'all sites', allServices: 'all services', allOrganizations: 'all orgnization', linkedItems: 'linkedItems', title: 'title' }; this.content = 'test'; this.myResult = this.knowledgeArticleModel.mergeArticleMetaData(this.article, this.oldArticle, this.content); expect(this.myResult).toBe(this.article); }); it('should check Edit Status', function () { this.myResult = this.knowledgeArticleModel.checkEditStatus(); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should create Article', function () { this.loginId = 'abc123'; this.myResult = this.knowledgeArticleModel.createArticle(this.loginId, article); scope.$apply(); expect(this.myResult.$$state.value).toEqual(article); expect(this.myResult.$$state.value.title).toEqual('email'); expect(this.myResult.$$state.value.accessMappings.detailsEditAllowed).toBe(true); expect(this.myResult.$$state.value.uuid).toBe('AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS'); }); it('should remove Auto Saved Copy ', function () { this.myResult = this.knowledgeArticleModel.removeAutoSavedCopy(); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should auto Save ', function () { this.myResult = this.knowledgeArticleModel.autoSave(); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should return Auto Saved Copy ', function () { this.myResult = this.knowledgeArticleModel.getAutoSavedCopy(); scope.$apply(); expect(this.myResult.$$state.value).toEqual('success'); }); it('should update Article Metadata ', function () { this.article = { accessMappings: true, autoAssign: true, tags: { join: function (test) { return } }, uuid: 'AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS' }; this.knowledgeArticleModel.articles = { 'AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS': { title: 'email', isDraft: false, createDate: 1509181556000, updateDate: null, modifiedDate: 1509181558000, desc: '', likePercentage: 0, rating: null, useCount: 0, notUsefulCount: 0, viewCount: 0, type: 'knowledge', articleId: 'KBA00000324', status: { value: 'Work In Progress' }, following: false, tags: [], entityLink: '#/knowledge/AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS', uuid: 'AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS', templateId: 'ID005056A6052Buo7VSwQaxSAQO5MB', templateName: 'How To', version: 1, favorite: false, flagged: false, articleGUID: 'KMGAA5V0HGOHVAOY8ZXJOXMN9ZEKGO', isLastVersion: true, isInApproval: false, attachmentLimit: 25, internalUse: true, perfAssessment: false, hashTags: [], accessMappings: { detailsEditAllowed: true, statusEditAllowed: true, companyEditAllowed: true, assigneeEditAllowed: true, visibilitygroupsEditAllowed: true, attachmentsEditAllowed: true, relationsEditAllowed: true, timelineEditAllowed: true, internaluseEditAllowed: true, flagEditAllowed: true, unflagEditAllowed: true, keywordsEditAllowed: true, categorizationEditAllowed: true, 'assignee-self-assignmentEditAllowed': true, helpfulEditAllowed: false, printEditAllowed: true }, language: '', autoAssign: false, site: {}, businessService: {}, organization: {}, commentCount: 0, allSites: [], allServices: [], allOrganizations: [], approvalProcessName: '', isPasswordEnabled: false, id: 'AGGAA5V0HGOHVAOY8ZXWOXMNKNEKGS', categoriesSet: [], feed: [], noCategories: 0 } }; this.myResult = this.knowledgeArticleModel.updateArticleMetadata(this.article); scope.$apply(); expect(this.myResult.$$state.value).toEqual(article); }); });