Documenting a known issue
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / controller / aaiSubscriberController.test.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 require('./aaiSubscriberController');
22 require('../services/dataService');
23
24 const jestMock = require('jest-mock');
25
26 describe('TreeCtrl testing', () => {
27     var window;
28
29     let $scope;
30     beforeEach(
31         angular.mock.module('app')
32     );
33
34     beforeEach(inject(function (_$controller_) {
35         $scope = {};
36         _$controller_('TreeCtrl', {
37             $scope: $scope
38         });
39     }));
40
41     test('Verify expandAll calls broadcast with expand-all parameter', () => {
42         // given
43         const broadcast = jestMock.fn();
44         $scope.$broadcast = broadcast;
45         FIELD = {
46             ID: {
47                 ANGULAR_UI_TREE_EXPANDALL: "angular-ui-tree:expand-all"
48             }
49         };
50         // when
51         $scope.expandAll();
52         // then
53         expect(broadcast).toHaveBeenCalledWith("angular-ui-tree:expand-all");
54     });
55
56     test('Verify collapseAll calls broadcast with collapse-all parameter', () => {
57         // given
58         const broadcast = jestMock.fn();
59         $scope.$broadcast = broadcast;
60         FIELD = {
61             ID: {
62                 ANGULAR_UI_TREE_COLLAPSEALL: "angular-ui-tree:collapse-all"
63             }
64         };
65         // when
66         $scope.collapseAll();
67         // then
68         expect(broadcast).toHaveBeenCalledWith("angular-ui-tree:collapse-all");
69     });
70
71     test('Verify toggle calls toggle in given scope', () => {
72         // given
73         const testScope = {};
74         testScope.toggle = jestMock.fn();
75         // when
76         $scope.toggle(testScope);
77         // then
78         expect(testScope.toggle).toHaveBeenCalled();
79     });
80
81     test('Verify remove calls remove in given scope', () => {
82         // given
83         const testScope = {};
84         testScope.remove = jestMock.fn();
85         // when
86         $scope.remove(testScope);
87         // then
88         expect(testScope.remove).toHaveBeenCalled();
89     });
90
91     test('Verify moveLastToTheBeginning pops last element from data and puts it on the beginning', () => {
92         // given
93         $scope.data = [ 'a', 'b', 'c' ];
94         const expectedResult = [ 'c', 'a', 'b' ];
95
96         // when
97         $scope.moveLastToTheBeginning();
98         // then
99         expect($scope.data).toMatchObject(expectedResult);
100     });
101
102     test('Verify newSubItem pushes new item into given scope', () => {
103         // given
104         const testScope = {};
105         const testModel = {};
106
107         testModel.id = 2;
108         testModel.nodes = [];
109         testModel.title = 'testObject';
110
111         const expectedResult = {
112             id: 20,
113             title: 'testObject.1',
114             nodes: []
115         };
116
117         testScope.$modelValue = testModel;
118
119         // when
120         $scope.newSubItem(testScope);
121         // then
122         expect(testModel.nodes.length).toBe(1);
123         expect(testModel.nodes[0]).toMatchObject(expectedResult);
124     });
125 });
126
127 describe('aaiSubscriberController testing', () => {
128
129     beforeEach(
130         angular.mock.module('app')
131     );
132
133     let $scope;
134     let $any;
135
136     let mockFIELD = {
137         PROMPT: {
138             SELECT_SERVICE: 'testService'
139         },
140         NAME: {
141             SERVICE_INSTANCE_ID: 'testID',
142             SERVICE_INSTANCE_NAME: 'testName'
143         },
144         ID: {
145             INVENTORY_RESPONSE_ITEMS: 0,
146             INVENTORY_RESPONSE_ITEM: 0
147         },
148         STYLE: {
149             MSO_CTRL_BTN: 'testButtonStyle',
150         },
151         STATUS: {
152             DONE: 'done',
153         },
154         ERROR: {
155             AAI: 'testAAIError',
156             FETCHING_SERVICE_TYPES: 'testServiceType',
157             SELECT: 'testAlertError',
158         },
159
160     };
161
162     let mockCOMPONENT = {
163         SHOW_COMPONENT_DETAILS: 'testComponentDetails',
164         VNF: 'testComponentVNF',
165         WELCOME_PATH: 'http://test/welcome/',
166         CREATE_INSTANCE_PATH: 'testInstancePath',
167         FEATURE_FLAGS:{},
168     };
169
170     let mockAaiService = {
171         getSubscriptionServiceTypeList(customerId,successFunction,failFunction){},
172         getServiceModelsByServiceType(queryId,customerId,serviceType,successFunction,failFunction){},
173         searchServiceInstances(query){},
174     };
175
176     let mockAsdcService = {
177         isMacro(item){},
178         shouldTakeTheAsyncInstantiationFlow(serviceModel){},
179     };
180
181     let mockPropertyService = {
182         retrieveMsoMaxPollingIntervalMsec(){return 1000},
183         setMsoMaxPollingIntervalMsec(msecs){},
184         retrieveMsoMaxPolls(){return 1000},
185         setMsoMaxPolls(polls){},
186     };
187
188     let mockUtilityService = {
189     };
190
191     let mockVidService = {
192         setModel(model){},
193     };
194
195     let dataService;
196
197     let mockLocation = {
198         path(path){},
199     };
200
201     let mockHttp = {
202         get(){},
203     };
204
205     let mockOwningEntityService = {
206         getOwningEntityProperties(callBack){}
207     };
208
209     let mockQ = {
210
211     };
212
213     $ = (selector) => {return mockSelector};
214     let mockSelector = {
215         addClass(){return this},
216         removeClass(){return this},
217         attr(){},
218     };
219
220     let mock_ = {
221         reduce(service,iterateeFunction,accumulatorFunction){},
222         forEach(services,iteratedFunction){},
223         includes(array, status){
224             return array.includes(status);
225         },
226         isEmpty(something) {return true;},
227     };
228
229     let mockedLog = {};
230
231     let mockFeatureFlags = {};
232
233     let mockVIDCONFIGURATION = {};
234
235     let mockRoute = {};
236
237     let mockUibModal = {};
238
239     let timeout;
240
241     beforeEach(inject(function (_$controller_,DataService,$timeout) {
242         $scope = {
243             $on(request,toDoFunction){}
244         };
245         $any = {};
246         dataService = DataService;
247         timeout = $timeout;
248         _$controller_('aaiSubscriberController', {
249             $scope: $scope,
250             COMPONENT: mockCOMPONENT,
251             FIELD: mockFIELD,
252             PARAMETER: $any,
253             DataService: DataService,
254             PropertyService: mockPropertyService,
255             $http: mockHttp,
256             $timeout: timeout,
257             $location: mockLocation,
258             $log: mockedLog,
259             $route: mockRoute,
260             $uibModal: mockUibModal,
261             VIDCONFIGURATION: mockVIDCONFIGURATION,
262             UtilityService: mockUtilityService,
263             vidService: mockVidService,
264             AaiService: mockAaiService,
265             MsoService: $any,
266             OwningEntityService: mockOwningEntityService,
267             AsdcService: mockAsdcService,
268             featureFlags: mockFeatureFlags,
269             $q: mockQ,
270             _: mock_
271         });
272     }));
273
274     test('Verify showVnfDetails calls proper broadcast methots with proper parameters', () => {
275         // given
276         const broadcast = jestMock.fn();
277         $scope.$broadcast = broadcast;
278
279         aaiResult = [[['test']]];
280
281         // when
282         $scope.showVnfDetails('testVNF');
283
284         // then
285         expect(broadcast).toHaveBeenCalledWith(mockCOMPONENT.SHOW_COMPONENT_DETAILS, { componentId: mockCOMPONENT.VNF,callbackFunction: expect.any(Function) } );
286     });
287
288     test('Verify getSubs will call fetchSubs and fetchServices and gets gets customer list from AaiService on success', () => {
289         // given
290         mockAaiService.getSubList = (successFunction,failFunction) => {
291             successFunction(['testCustomer1', 'testCustomer2']);
292         };
293         mockAaiService.getServices2 = (successFunction,failFunction) => {
294             successFunction('testListId');
295         };
296
297         // when
298         $scope.getSubs();
299
300         // then
301         expect( $scope.customerList ).toContain('testCustomer1','testCustomer2');
302         expect( dataService.getServiceIdList() ).toEqual('testListId');
303     });
304
305     test('Verify getSubs will call fetchSubs and fetchServices and return error message from AaiService on fail', () => {
306         // given
307         mockAaiService.getSubList = (successFunction,failFunction) => {
308             failFunction({status: 404, data: 'getSubListTestErrorMessage'} );
309         };
310         mockAaiService.getServices2 = (successFunction,failFunction) => {
311             failFunction({status: 404, data: 'getServices02TestErrorMessage'} );
312         };
313
314         // when
315         $scope.getSubs();
316
317         // then
318         expect( $scope.errorDetails ).toEqual('getServices02TestErrorMessage');
319     });
320
321     test('Verify refreshServiceTypes will call getServiceTypesList and gets service type list from AaiService, with proper customerID ', () => {
322         // given
323         dataService.setGlobalCustomerId('testCustomerID');
324         dataService.setServiceIdList(['testServiceId1','testServiceId2']);
325
326         mockAaiService.getSubscriptionServiceTypeList = (customerId, successFunction,failFunction) => {
327             if (customerId === 'testCustomerID'){
328                 successFunction(['testServiceType1', 'testServiceType2']);
329             }
330         };
331
332         // when
333         $scope.refreshServiceTypes('testCustomerID');
334
335         // then
336         expect( $scope.serviceTypeList ).toContain('testServiceType1','testServiceType2');
337     });
338
339     test('Verify refreshServiceTypes will call getServiceTypesList and return error message with wrong customerID ', () => {
340         // given
341         mockAaiService.getSubscriptionServiceTypeList = (customerId, successFunction,failFunction) => {
342             if (customerId === 'testWrongCustomerID'){
343                 failFunction( {status: 404, data: 'testErrorMessage'} );
344             }
345         };
346
347         // when
348         $scope.refreshServiceTypes('testWrongCustomerID');
349
350         // then
351         expect( $scope.errorDetails ).toEqual('testErrorMessage');
352     });
353
354     test('Verify refreshServiceTypes will call getServiceTypesList and calls alert with no customerID ', () => {
355         // given
356         alert = jestMock.fn();
357
358         // when
359         $scope.refreshServiceTypes('');
360
361         // then
362         expect( alert ).toHaveBeenCalledWith(mockFIELD.ERROR.SELECT);
363     });
364
365     test('Verify getAaiServiceModels will set correct location ', () => {
366         // given
367         mockLocation.path = jestMock.fn();
368
369         // when
370         $scope.getAaiServiceModels('testServiceType','testSubName');
371
372         // then
373         expect(mockLocation.path).toHaveBeenCalledWith(mockCOMPONENT.CREATE_INSTANCE_PATH);
374     });
375
376     test('Verify getAaiServiceModels wont set correct location if service type is empty', () => {
377         // given
378         mockLocation.path = jestMock.fn();
379
380         // when
381         $scope.getAaiServiceModels('','testSubName');
382
383         // then
384         expect(mockLocation.path).not.toHaveBeenCalled();
385     });
386
387     test('Verify getAaiServiceModelsList will call AaiService getServiceModelsByServiceType and will set wholeData ', () => {
388         // given
389
390         mockAaiService.getServiceModelsByServiceType = (queryId,customerId,serviceType,successFunction,failFunction) => {
391             let response = {};
392             response.data = {};
393             response.data['inventory-response-item'] = [[],[]];
394             response.data['inventory-response-item'][0]['inventory-response-items'] = [];
395             response.data['inventory-response-item'][0]['service-subscription'] = [];
396
397             let testItem = [];
398             testItem['extra-properties'] = [];
399             testItem['extra-properties']['extra-property'] = [[],[],[],[],[],[],[]];
400             testItem['extra-properties']['extra-property'][6]["property-value"] = 1.546;
401
402             testItem['extra-properties']['extra-property'][4]['property-value'] = 0;
403
404             response.data['inventory-response-item'][0]['service-subscription']['service-type'] = 'testServiceType';
405             response.data['inventory-response-item'][0]['inventory-response-items']['inventory-response-item'] = testItem;
406
407
408             successFunction(response);
409         };
410
411         mock_.reduce = (service,iterateeFunction,accumulatorFunction) => {
412             return iterateeFunction([],service);
413         };
414         mock_.forEach = (service,iterateeFunction) => {
415             iterateeFunction(service);
416         };
417         mock_.maxBy = (item,maxFunction) => {
418             return maxFunction( item[0][0] )
419         };
420
421         dataService.setServiceIdList(['testService1','testService2','testService3','testService4']);
422         dataService.setSubscribers([{subscriberName:'testSubscriber1'},{subscriberName:'testSubscriber2'},{subscriberName:'testSubscriber3'},{subscriberName:'testSubscriber4'}]);
423         dataService.setGlobalCustomerId(2);
424         dataService.setSubscriberName('testSubscriber1');
425
426         // when
427         $scope.getAaiServiceModelsList();
428
429         // then
430         expect($scope.services[0]).toEqual(1.546);
431         expect($scope.serviceType).toEqual('testServiceType');
432     });
433
434     test('Verify getAaiServiceModelsList will call AaiService getServiceModelsByServiceType and will return error data on fail ', () => {
435         // given
436         dataService.setServiceIdList([['testServiceId1','testServiceId2']]);
437         dataService.setSubscribers(['testSubscriber1,testSubscriber2']);
438
439         mockAaiService.getServiceModelsByServiceType = (queryId,customerId,serviceType,successFunction,failFunction) => {
440             failFunction( {status: 404, data: 'testErrorMessage'})
441         };
442
443         // when
444         $scope.getAaiServiceModelsList();
445
446         // then
447         expect($scope.errorDetails).toEqual('testErrorMessage');
448     });
449
450     test('Verify getAaiServiceModelsList will call AaiService getServiceModelsByServiceType and will return error data if respose data is empty ', () => {
451         // given
452         dataService.setServiceIdList([['testServiceId1','testServiceId2']]);
453         dataService.setSubscribers(['testSubscriber1,testSubscriber2']);
454
455         mockAaiService.getServiceModelsByServiceType = (queryId,customerId,serviceType,successFunction,failFunction) => {
456             let response = {};
457             response.data = {};
458             response.data['inventory-response-item'] = [];
459             successFunction(response);
460         };
461
462         // when
463         $scope.getAaiServiceModelsList();
464
465         // then
466         expect($scope.status).toEqual('Failed to get service models from SDC.');
467     });
468
469     test('Verify deployService will call http get method to rest model service', () => {
470         // given
471         mockedLog.error = jestMock.fn();
472         mockAsdcService.isMacro = (item) => { return true };
473         mockAsdcService.shouldTakeTheAsyncInstantiationFlow = (serviceModel) => {return 'testModel'};
474         mockUtilityService.convertModel = (serviceModel)=>{return serviceModel};
475         $scope.$broadcast = (broadcastType, broadcastObject) => {broadcastObject.callbackFunction(
476             {
477                 isSuccessful:true,
478                 control:
479                     [
480                         {id:"subscriberName",value:"testSubscriber"},
481                         {id:"serviceType",value:"testService"}
482                         ],
483                 instanceId:"testInstance"
484             })};
485
486         let service = {
487             "service-instance":{
488                 "model-version-id": 101
489             }
490         };
491
492         $scope.refreshSubs = jestMock.fn();
493
494         let mockedGetPromise = Promise.resolve({data: {service: {name: 'testServiceName' }}});
495         mockHttp.get = () => mockedGetPromise;
496
497         // when
498         $scope.deployService(service,true);
499     });
500
501     test('Verify deployService will log error if get fails ', () => {
502         // given
503
504         let mockedGetPromise = Promise.reject({code: 404});
505         mockHttp.get = () => mockedGetPromise;
506
507         let service = {
508             "service-instance":{
509                 "model-version-id": 101
510             }
511         };
512
513         // when
514         $scope.deployService(service,false);
515     });
516
517     test('Verify refreshSubs fetches Subs and Services', () => {
518         // given
519         $scope.fetchSubs = jestMock.fn();
520         $scope.fetchServices = jestMock.fn();
521         $scope.init = jestMock.fn();
522
523         mockFIELD.PROMPT.REFRESH_SUB_LIST = 'testRefreshMock';
524
525         // when
526         $scope.refreshSubs();
527
528         // then
529         expect($scope.init).toHaveBeenCalled();
530         expect($scope.fetchSubs).toHaveBeenCalledWith(mockFIELD.PROMPT.REFRESH_SUB_LIST);
531         expect($scope.fetchServices).toHaveBeenCalled();
532
533     });
534
535     test('Verify loadOwningEntity gets owning entity properties', () => {
536         // given
537         mockOwningEntityService.getOwningEntityProperties = (callBack) => {
538           callBack({owningEntity:'testOwner',project:'testProject'});
539         };
540
541         // when
542         $scope.loadOwningEntity();
543
544         // then
545         expect($scope.owningEntities).toEqual('testOwner');
546         expect($scope.projects).toEqual('testProject');
547     });
548
549     test('Verify getPermitted returns items permission', () => {
550         // given
551         mockFIELD.ID.IS_PERMITTED = 'testPermission';
552
553         // when
554         expect(
555             $scope.getPermitted({})
556         ).toEqual(undefined);
557
558         expect(
559             $scope.getPermitted({isPermitted:true})
560         ).toEqual(true);
561
562         expect(
563             $scope.getPermitted({isPermitted:false})
564         ).toEqual(undefined);
565
566         expect(
567             $scope.getPermitted({isPermitted:false,testPermission:true})
568         ).toEqual(true);
569
570         expect(
571             $scope.getPermitted({testPermission:false,testPermission:false})
572         ).toEqual(false);
573
574         expect(
575             $scope.getPermitted({isPermitted:true,testPermission:false})
576         ).toEqual(true);
577     });
578
579     test('Verify getSubDetails calls to aaiService for service instance', () => {
580         // given
581         let aaiPromise = Promise.resolve(
582             {
583                 displayData:[
584                     {globalCustomerId:"testCustomerId01",subscriberName:"testCustomer1"},
585                     {globalCustomerId:"testCustomerId02",subscriberName:"testCustomer2"},
586                 ]
587             });
588
589         mockLocation.url = () => {return ""};
590
591         mockAaiService.searchServiceInstances = (query)=>aaiPromise;
592
593         // when
594         $scope.getSubDetails();
595     });
596
597     test('Verify getSubDetails catches bad response', () => {
598         // given
599         let aaiPromise = Promise.reject(
600             {data:'testError',status:404});
601
602         mockLocation.url = () => {return ""};
603
604         mockAaiService.searchServiceInstances = (query)=>aaiPromise;
605
606         // when
607         $scope.getSubDetails();
608     });
609
610     test('Verify getComponentList returns list of components if query is correct', () => {
611         // given
612         mockLocation.search = () => {
613             return {
614                 subscriberId: 'testSubscriberID',
615                 serviceType: 'testService',
616                 serviceInstanceId: "testServiceInstanceID",
617                 subscriberName: "testSubscriber",
618                 aaiModelVersionId: "testModelVersion"
619             }
620         };
621
622         mockVidService.getModel = () => {
623             return {
624                 service:{
625                     uuid: "testModelVersion",
626                 },
627             }
628         };
629
630         mockUtilityService.hasContents = (content) => {
631             if (content==="testModelVersion") {
632                 return true;
633             }
634             return false;
635         };
636
637         mockQ.resolve = (item) => {return Promise.resolve("testModelVersion")};
638
639         $scope.prepareScopeWithModel = () => {return Promise.resolve()};
640
641         mockAaiService.getVlansByNetworksMapping = (globalCustomerId, serviceType, serviceInstanceId, modelServiceUuid) => {
642             return Promise.resolve({serviceNetworks:true});
643         };
644
645         $scope.service ={
646             model:{
647                 service:{
648                     uuid: 'testModelServiceUuid'
649                 }
650             }
651         };
652
653         mockedLog.debug = () => {};
654         mockUtilityService.isObjectEmpty = () => {
655             return false;
656         };
657
658         mockFIELD.ID.INVENTORY_RESPONSE_ITEM = "testResponseItems";
659         mockFIELD.ID.SERVICE_SUBSCRIPTION = 0;
660         mockFIELD.ID.SERVICE_INSTANCES = 0;
661         mockFIELD.ID.SERVICE_INSTANCE = 0;
662         mockFIELD.ID.SERVICE_INSTANCE_ID = 'testServiceInstanceID';
663         mockFIELD.STATUS.ASSIGNED = 'teststatus';
664
665         mockAaiService.runNamedQuery = (namedQueryId,globalCustomerId,serviceType,serviceInstanceId,successFunction,failureFunction) => {
666             successFunction({
667                 data:{
668                     testResponseItems:[
669                         "testItem1",
670                         "testItem2",
671                         "testItem3",
672                     ]
673                 },
674             });
675             return Promise.resolve("testComponentList");
676         };
677
678         mockAaiService.getPortMirroringData = (portMirroringConfigurationIds) => {
679             return Promise.resolve({data:[8080,9090]});
680         };
681
682         mockAaiService.getPortMirroringSourcePorts = (portMirroringConfigurationIds) => {
683           return Promise.resolve({data:[8888,9999]})
684         };
685
686         mockAaiService.getSubscriberName = (customerId, successFunction) => {
687             successFunction({subscriberName:"testSubscriber1",serviceSubscriptions:[[
688                     [[[{'testServiceInstanceID':'testServiceInstanceID','orchestration-status':'testStatus'},{'testServiceInstanceID':'','orchestration-status':''}]]],
689                     [[[{'testServiceInstanceID':'','orchestration-status':''}]]]
690                 ]],
691             });
692         };
693
694         mock_.map = (serviceNetworkVlans, networkId) => {
695             return ["aaiNetworkId1","aaiNetworkId2"];
696         };
697
698         // when
699         return $scope.getComponentList('','').
700         then(components =>{
701             expect(components).toEqual("testComponentList")
702         });
703
704     });
705
706     test('Verify handleServerError sets proper  $scope.error and $scope.status', () => {
707         // given
708         mockUtilityService.getHttpErrorMessage = (response) => {return response.statusText};
709         mockFIELD.ERROR.SYSTEM_ERROR = "testSystemError";
710         mockFIELD.STATUS.ERROR = "testStatusError";
711
712         // when
713         $scope.handleServerError({statusText:'testStatusError'},'');
714
715         // then
716         expect($scope.error).toEqual("testSystemError (testStatusError)");
717         expect($scope.status).toEqual("testStatusError");
718     });
719
720     test('Verify showContentError sets proper $scope.error and $scope.status if UtilityService has that content', () => {
721         // given
722         mockFIELD.STATUS.ERROR = "testStatusError";
723
724         mockUtilityService.hasContents = (content) => {
725           return content === 'testContentError';
726
727         };
728
729         // when
730         $scope.showContentError('testContentError');
731
732         // then
733         expect($scope.error).toEqual("System failure (testContentError)");
734         expect($scope.status).toEqual("testStatusError");
735     });
736
737     test('Verify showContentError sets proper $scope.error and $scope.status if UtilityService has not that content', () => {
738         // given
739         mockFIELD.ERROR.SYSTEM_ERROR = "testSystemError";
740         mockFIELD.STATUS.ERROR = "testStatusError";
741
742         mockUtilityService.hasContents = (content) => {
743             return false;
744         };
745
746         // when
747         $scope.showContentError('testContentError');
748
749         // then
750         expect($scope.error).toEqual("testSystemError");
751         expect($scope.status).toEqual("testStatusError");
752     });
753
754     test('Verify handleInitialResponse shows error for response codes other then 200,201,202', ()  => {
755         // given
756         let response = {
757             data:{
758                 status:404,
759             }
760         };
761
762         mockFIELD.ERROR.MSO = "testSystemError";
763         mockFIELD.ERROR.AAI_FETCHING_CUST_DATA = "testStatusError:";
764
765         $scope.showError = jestMock.fn();
766
767         // when
768         $scope.handleInitialResponse(response);
769
770         // then
771         expect($scope.showError).toHaveBeenCalledWith("testSystemError");
772         expect($scope.status).toEqual("testStatusError:404");
773     });
774
775     test('Verify handleInitialResponse updates customer list with response code 202', ()  => {
776         // given
777         let customer ={
778             'globalCustomerId':'testCustomerID',
779             "subscriberName":'testSubscriber',
780             "isPermitted":false
781         };
782         let response = {
783             data:{
784                 status:202,
785                 customer:[customer],
786             }
787         };
788
789         mockFIELD.ID.GLOBAL_CUSTOMER_ID = 'globalCustomerId';
790         mockFIELD.ID.SUBNAME = 'subscriberName';
791         mockFIELD.ID.IS_PERMITTED = 'isPermitted';
792
793         // when
794         $scope.handleInitialResponse(response);
795
796         // then
797         expect($scope.customerList).toContainEqual(customer);
798     });
799
800     test('Verify handleInitialResponse calls showContentError with wrong response ', ()  => {
801         // given
802         $scope.showContentError = jestMock.fn();
803
804         // when
805         $scope.handleInitialResponse(null);
806
807         // then
808         expect($scope.showContentError).toHaveBeenCalledWith(expect.objectContaining({message:"Cannot read property 'data' of null"}));
809     });
810
811     test('Verify isConfigurationDataAvailiable will return proper response', ()  => {
812         // given
813         mockedLog.debug = jestMock.fn();
814         // when
815         expect( $scope.isConfigurationDataAvailiable({configData:{}}) ).toEqual(true);
816         expect( $scope.isConfigurationDataAvailiable({configData:{errorDescription:"testerror"}}) ).toEqual(false);
817         expect( $scope.isConfigurationDataAvailiable({}) ).toEqual(undefined);
818
819     });
820
821     test('Verify isActivateDeactivateEnabled will return proper response', ()  => {
822         // given
823         mockedLog.debug = jestMock.fn();
824
825         $scope.serviceOrchestrationStatus = "active";
826         mockCOMPONENT.ACTIVATE_SERVICE_STATUSES = ["active","up"];
827
828         // when
829         expect( $scope.isActivateDeactivateEnabled("deactivate")).toEqual(true);
830         expect( $scope.isActivateDeactivateEnabled("activate")).toEqual(true);
831
832         $scope.serviceOrchestrationStatus = "down";
833         mockCOMPONENT.ACTIVATE_SERVICE_STATUSES = ["active","up"];
834
835         expect( $scope.isActivateDeactivateEnabled("deactivate")).toEqual(false);
836         expect( $scope.isActivateDeactivateEnabled("activate")).toEqual(false);
837
838         $scope.serviceOrchestrationStatus = null;
839
840         expect( $scope.isActivateDeactivateEnabled(null)).toEqual(false);
841
842     });
843
844     test('Verify isShowVerifyService will return proper response base on feature flag', ()  => {
845         // given
846         mockCOMPONENT.FEATURE_FLAGS.FLAG_SHOW_VERIFY_SERVICE = 'showVerifyService';
847         mockFeatureFlags.isOn = (flag) => {
848             if (flag === 'showVerifyService'){return true};
849         };
850
851         // when
852         expect( $scope.isShowVerifyService()).toEqual(true);
853     });
854
855     test('Verify isEnableVerifyService will return false if is not ALaCarte', ()  => {
856         // given
857         dataService.setALaCarte(false);
858
859         // when
860         expect( $scope.isEnableVerifyService()).toEqual(false);
861     });
862
863     test('Verify isEnableVerifyService will return verifyButtonEnabled if is ALaCarte', ()  => {
864         // given
865         dataService.setALaCarte(true);
866
867         // when
868         $scope.verifyButtonEnabled = true;
869         expect( $scope.isEnableVerifyService()).toEqual(true);
870
871         $scope.verifyButtonEnabled = false;
872         expect( $scope.isEnableVerifyService()).toEqual(false);
873     });
874
875     test('Verify activateVerifyService will post POMBA verification', ()  => {
876         // given
877         mockCOMPONENT.VERIFY_SERVICE_URL = "/testURL";
878
879         mockAaiService.postPOMBAverificationRequest = jestMock.fn();
880
881         $scope.serviceInstanceId = "testInstanceID";
882         $scope.service = {model:{service:{}},instance:{}};
883         $scope.service.model.service.uuid = "testUuid";
884         $scope.service.model.service.invariantUuid = "testInvariantUuid";
885         $scope.globalCustomerId = "testCustomerId";
886         $scope.service.instance.serviceType = "testServiceType";
887
888         // when
889         $scope.activateVerifyService();
890
891         // then
892         expect(mockAaiService.postPOMBAverificationRequest).toHaveBeenCalledWith(
893             "/testURL",
894             expect.objectContaining({'serviceInstanceList':[expect.any(Object)]}),
895             expect.objectContaining({'headers':expect.any(Object)}));
896     });
897
898     test('Verify isShowAssignmentsEnabled will return proper response determine by feature flag', ()  => {
899         // given
900         mockCOMPONENT.FEATURE_FLAGS.FLAG_SHOW_ASSIGNMENTS = "showAssignment";
901
902         mockFeatureFlags.isOn = (flag) => {
903             if (flag === 'showAssignment'){return true};
904         };
905
906         // when
907         $scope.serviceOrchestrationStatus = "assigned";
908         expect( $scope.isShowAssignmentsEnabled() ).toEqual(true);
909
910         $scope.serviceOrchestrationStatus = "notAssigned";
911         expect( $scope.isShowAssignmentsEnabled() ).toEqual(false);
912
913         $scope.serviceOrchestrationStatus = null;
914         expect( $scope.isShowAssignmentsEnabled() ).toEqual(false);
915     });
916
917     test('Verify isActivateFabricConfiguration will return proper response determine by feature flag', ()  => {
918         // given
919         mockCOMPONENT.FEATURE_FLAGS.FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS = "fabricConfigurationAssignment";
920         $scope.hasFabricConfigurations = true;
921
922         mockFeatureFlags.isOn = (flag) => {
923             if (flag === 'fabricConfigurationAssignment'){return true};
924         };
925
926         // when
927         $scope.serviceOrchestrationStatus = "assigned";
928         expect( $scope.isActivateFabricConfiguration() ).toEqual(true);
929
930         $scope.serviceOrchestrationStatus = "notAssigned";
931         expect( $scope.isActivateFabricConfiguration() ).toEqual(false);
932
933         $scope.serviceOrchestrationStatus = null;
934         expect( $scope.isActivateFabricConfiguration() ).toEqual(false);
935     });
936
937     test('Verify isResumeShown will return proper response determine by feature flag with disabled ActivateDeactivate', ()  => {
938         // given
939         $scope.serviceOrchestrationStatus = "assigned";
940         $scope.isActivateDeactivateEnabled = () => {return false};
941
942         // when
943         expect( $scope.isResumeShown("assigned") ).toEqual(true);
944         expect( $scope.isResumeShown("unAssigned") ).toEqual(false);
945
946     });
947
948     test('Verify isResumeShown will return proper response determine by feature flag with enable ActivateDeactivate', ()  => {
949         // given
950         $scope.serviceOrchestrationStatus = "assigned";
951         $scope.isActivateDeactivateEnabled = () => {return true};
952
953         // when
954         expect( $scope.isResumeShown("assigned") ).toEqual(false);
955         expect( $scope.isResumeShown("unAssigned") ).toEqual(false);
956
957     });
958
959     test('Verify close will call time out cancel and hides pop up window if timer is defined', ()  => {
960         // given
961         $scope.timer = 1000;
962         $scope.isPopupVisible = true;
963
964         timeout.cancel = jestMock.fn();
965
966         // when
967         $scope.close();
968
969         // then
970         expect(timeout.cancel).toHaveBeenCalledWith(1000);
971         expect($scope.isPopupVisible).toEqual(false);
972     });
973
974     test('Verify close will hide pop up window if timer is undefined', ()  => {
975         // given
976         $scope.timer = undefined;
977         $scope.isPopupVisible = true;
978
979         // when
980         $scope.close();
981
982         // then
983         expect($scope.isPopupVisible).toEqual(false);
984     });
985
986     test('Verify reloadRoute will call reload on rout', ()  => {
987         // given
988         mockRoute.reload = jestMock.fn();
989
990         // when
991         $scope.reloadRoute();
992
993         // then
994         expect(mockRoute.reload).toHaveBeenCalled();
995     });
996
997     test('Verify prevPage will decrease currentPage', ()  => {
998         // given
999         $scope.currentPage = 5;
1000
1001         // when
1002         $scope.prevPage();
1003
1004         // then
1005         expect($scope.currentPage).toEqual(4);
1006     });
1007
1008     test('Verify showAssignmentsSDNC will return proper response base on VIDCONFIGURATION', ()  => {
1009         // given
1010         $scope.service = {};
1011         $scope.service.instance = {};
1012         $scope.service.instance.id = "testServiceInstanceId";
1013
1014         mockVIDCONFIGURATION.SDNC_SHOW_ASSIGNMENTS_URL = "test/ulr/to/<SERVICE_INSTANCE_ID>";
1015
1016         // when
1017         expect( $scope.showAssignmentsSDNC() ).toEqual("test/ulr/to/testServiceInstanceId");
1018     });
1019
1020     test('Verify showAssignmentsSDNC will return null if service instance dos not exist or is null', ()  => {
1021         // given
1022         $scope.service = {};
1023
1024         // when
1025         expect( $scope.showAssignmentsSDNC() ).toEqual(null);
1026
1027         $scope.service.instance = null;
1028         expect( $scope.showAssignmentsSDNC() ).toEqual(null);
1029     });
1030
1031     test('Verify activateFabricConfigurationMSO with logged in user, will call uibModal open that will return response ', ()  => {
1032         // given
1033         let resopnse = {};
1034
1035         mockCOMPONENT.MSO_ACTIVATE_FABRIC_CONFIGURATION_REQ = "testMsoActivateType";
1036
1037         $scope.service = {};
1038         $scope.service.model = {};
1039         $scope.service = {};
1040         $scope.serviceInstanceId= "testServiceInstanceId";
1041
1042         dataService.setLoggedInUserId("testUserId");
1043
1044         mockUibModal.open = (testResponse) => {
1045             resopnse = testResponse.resolve;
1046         };
1047
1048         // when
1049         $scope.activateFabricConfigurationMSO();
1050
1051         // then
1052         expect( resopnse.msoType() ).toEqual("testMsoActivateType");
1053         expect( resopnse.requestParams().serviceInstanceId ).toEqual("testServiceInstanceId");
1054         expect( resopnse.requestParams().userId ).toEqual("testUserId");
1055         expect( resopnse.configuration() ).toEqual(undefined);
1056     });
1057
1058     test('Verify activateFabricConfigurationMSO without logged in user will first get user id from AaiService , will call uibModal open that will return response ', ()  => {
1059         // given
1060         let resopnse = {};
1061
1062         mockCOMPONENT.MSO_ACTIVATE_FABRIC_CONFIGURATION_REQ = "testMsoActivateType";
1063
1064         $scope.service = {};
1065         $scope.service.model = {};
1066         $scope.service = {};
1067         $scope.serviceInstanceId= "testServiceInstanceId";
1068
1069
1070         mockAaiService.getLoggedInUserID = (onSuccess) => {
1071             onSuccess({data:"testAaiUserId"});
1072         };
1073
1074         mockUibModal.open = (testResponse) => {
1075             resopnse = testResponse.resolve;
1076         };
1077
1078         // when
1079         $scope.activateFabricConfigurationMSO();
1080
1081         // then
1082         expect( resopnse.msoType() ).toEqual("testMsoActivateType");
1083         expect( resopnse.requestParams().serviceInstanceId ).toEqual("testServiceInstanceId");
1084         expect( resopnse.requestParams().userId ).toEqual("testAaiUserId");
1085         expect( resopnse.configuration() ).toEqual(undefined);
1086     });
1087
1088     test('Verify activateMSOInstance with logged in user, will get aicZone from AaiService and call uibModal open that will return response ', ()  => {
1089         // given
1090         let resopnse = {};
1091
1092         mockCOMPONENT.MSO_ACTIVATE_SERVICE_REQ = "testMsoActivateType";
1093
1094         $scope.service = {};
1095         $scope.service.model = {};
1096         $scope.service.instance = {};
1097
1098         dataService.setLoggedInUserId("testUserId");
1099
1100         mockAaiService.getAicZoneForPNF = (globalCustomerId,serviceType,serviceInstanceId,getZoneFunction) => {
1101             getZoneFunction("testAicZone");
1102         };
1103
1104         mockUibModal.open = (testResponse) => {
1105             resopnse = testResponse.resolve;
1106         };
1107
1108         // when
1109         $scope.activateMSOInstance();
1110
1111         // then
1112         expect( resopnse.msoType() ).toEqual("testMsoActivateType");
1113         expect( resopnse.requestParams().aicZone ).toEqual("testAicZone");
1114         expect( resopnse.requestParams().userId ).toEqual("testUserId");
1115         expect( resopnse.configuration() ).toEqual(undefined);
1116     });
1117
1118     test('Verify activateMSOInstance without logged in user will first get user id from AaiService , will call uibModal open that will return response ', ()  => {
1119         // given
1120         let resopnse = {};
1121
1122         mockCOMPONENT.MSO_ACTIVATE_SERVICE_REQ = "testMsoActivateType";
1123
1124         $scope.service = {};
1125         $scope.service.model = {};
1126         $scope.service.instance = {};
1127
1128
1129         mockAaiService.getAicZoneForPNF = (globalCustomerId,serviceType,serviceInstanceId,getZoneFunction) => {
1130             getZoneFunction("testAicZone");
1131         };
1132
1133         mockAaiService.getLoggedInUserID = (onSuccess) => {
1134             onSuccess({data:"testAaiUserId"});
1135         };
1136
1137         mockUibModal.open = (testResponse) => {
1138             resopnse = testResponse.resolve;
1139         };
1140
1141         // when
1142         $scope.activateMSOInstance();
1143
1144         // then
1145         expect( resopnse.msoType() ).toEqual("testMsoActivateType");
1146         expect( resopnse.requestParams().aicZone ).toEqual("testAicZone");
1147         expect( resopnse.requestParams().userId ).toEqual("testAaiUserId");
1148         expect( resopnse.configuration() ).toEqual(undefined);
1149     });
1150
1151     test('Verify deactivateMSOInstance will get call uibModal open that will return response ', ()  => {
1152         // given
1153         let resopnse = {};
1154
1155         mockCOMPONENT.MSO_DEACTIVATE_SERVICE_REQ = "testMsoDeactivateType";
1156
1157         $scope.service = {};
1158         $scope.service.model = {};
1159         $scope.service.instance = {};
1160
1161
1162         mockAaiService.getAicZoneForPNF = (globalCustomerId,serviceType,serviceInstanceId,getZoneFunction) => {
1163             getZoneFunction("testAicZone");
1164         };
1165
1166         mockAaiService.getLoggedInUserID = (onSuccess) => {
1167             onSuccess({data:"testAaiUserId"});
1168         };
1169
1170         mockUibModal.open = (testResponse) => {
1171             resopnse = testResponse.resolve;
1172         };
1173
1174         // when
1175         $scope.deactivateMSOInstance();
1176
1177         // then
1178         expect( resopnse.msoType() ).toEqual("testMsoDeactivateType");
1179         expect( resopnse.requestParams().aicZone ).toEqual("testAicZone");
1180         expect( resopnse.requestParams().userId ).toEqual("testAaiUserId");
1181         expect( resopnse.configuration() ).toEqual(undefined);
1182     });
1183
1184     test('Verify deleteConfiguration will get call uibModal open that will return response ', ()  => {
1185         // given
1186         let resopnse = {};
1187
1188         serviceObject = {
1189             model:{
1190                 service:{
1191                     invariantUuid:"testInvariantUuid",
1192                     uuid:"testUuid",
1193                     name:"testService",
1194                     version:"testVersion",
1195                 }},
1196             instance:{
1197                 serviceInstanceId:"testServiceInstanceId",
1198             }
1199         };
1200
1201         configuration = {
1202             modelInvariantId:"testModelInvariantId",
1203             modelVersionId:"testModelVersionId",
1204             modelCustomizationId:"testModelCustomizationId",
1205             nodeId:"testNodeId",
1206             DELETE:"testDELETE",
1207         };
1208
1209         mockCOMPONENT.MSO_DELETE_CONFIGURATION_REQ = "testMsoDeleteType";
1210
1211         mockAaiService.getLoggedInUserID = (successFunction) => {
1212             successFunction( {data:"testLoggedInUserId"} );
1213         };
1214
1215         mockUibModal.open = (testResponse) => {
1216             resopnse = testResponse.resolve;
1217         };
1218
1219         // when
1220         $scope.deleteConfiguration(serviceObject, configuration);
1221
1222         // then
1223         expect( resopnse.msoType() ).toEqual("testMsoDeleteType");
1224         expect( resopnse.requestParams().serviceModel.modelInvariantId ).toEqual("testInvariantUuid");
1225         expect( resopnse.requestParams().serviceModel.modelVersionId ).toEqual("testUuid");
1226         expect( resopnse.requestParams().serviceModel.modelName ).toEqual("testService");
1227         expect( resopnse.requestParams().serviceModel.modelVersion ).toEqual("testVersion");
1228         expect( resopnse.requestParams().serviceInstanceId ).toEqual("testServiceInstanceId");
1229         expect( resopnse.requestParams().configurationModel.modelInvariantId ).toEqual("testModelInvariantId");
1230         expect( resopnse.requestParams().configurationModel.modelVersionId ).toEqual("testModelVersionId");
1231         expect( resopnse.requestParams().configurationModel.modelCustomizationId ).toEqual("testModelCustomizationId");
1232         expect( resopnse.requestParams().configurationId ).toEqual("testNodeId");
1233         expect( resopnse.requestParams().configStatus ).toEqual("testDELETE");
1234         expect( resopnse.requestParams().userId ).toEqual("testLoggedInUserId");
1235     });
1236
1237     test('Verify toggleConfigurationStatus will get call uibModal open that will return response ', ()  => {
1238         // given
1239         let resopnse = {};
1240
1241         serviceObject = {
1242             model:{
1243                 service:{
1244                     invariantUuid:"testInvariantUuid",
1245                     uuid:"testUuid",
1246                     name:"testService",
1247                     version:"testVersion",
1248                 }},
1249             instance:{
1250                 serviceInstanceId:"testServiceInstanceId",
1251             }
1252         };
1253
1254         configuration = {
1255             modelInvariantId:"testModelInvariantId",
1256             modelVersionId:"testModelVersionId",
1257             modelCustomizationId:"testModelCustomizationId",
1258             nodeId:"testNodeId",
1259             nodeStatus:"testNodeStatus",
1260         };
1261
1262         mockAaiService.getLoggedInUserID = (successFunction) => {
1263             successFunction( {data:"testLoggedInUserId"} );
1264         };
1265
1266         mockUibModal.open = (testResponse) => {
1267             resopnse = testResponse.resolve;
1268         };
1269
1270         mockCOMPONENT.MSO_CHANGE_CONFIG_STATUS_REQ = "testMsoChangeConfig";
1271
1272         // when
1273         $scope.toggleConfigurationStatus(serviceObject, configuration);
1274
1275         // then
1276         expect( resopnse.msoType() ).toEqual("testMsoChangeConfig");
1277         expect( resopnse.requestParams().serviceModel.modelInvariantId ).toEqual("testInvariantUuid");
1278         expect( resopnse.requestParams().serviceModel.modelVersionId ).toEqual("testUuid");
1279         expect( resopnse.requestParams().serviceModel.modelName ).toEqual("testService");
1280         expect( resopnse.requestParams().serviceModel.modelVersion ).toEqual("testVersion");
1281         expect( resopnse.requestParams().serviceInstanceId ).toEqual("testServiceInstanceId");
1282         expect( resopnse.requestParams().configurationModel.modelInvariantId ).toEqual("testModelInvariantId");
1283         expect( resopnse.requestParams().configurationModel.modelVersionId ).toEqual("testModelVersionId");
1284         expect( resopnse.requestParams().configurationModel.modelCustomizationId ).toEqual("testModelCustomizationId");
1285         expect( resopnse.requestParams().configurationId ).toEqual("testNodeId");
1286         expect( resopnse.requestParams().configStatus ).toEqual("testNodeStatus");
1287         expect( resopnse.requestParams().userId ).toEqual("testLoggedInUserId");
1288     });
1289
1290     test('Verify togglePortStatus will get call uibModal open that will return response ', ()  => {
1291         // given
1292         let resopnse = {};
1293
1294         let serviceObject = {
1295             model:{
1296                 service:{
1297                     invariantUuid:"testInvariantUuid",
1298                     uuid:"testUuid",
1299                     name:"testService",
1300                     version:"testVersion",
1301                 }},
1302             instance:{
1303                 serviceInstanceId:"testServiceInstanceId",
1304             }
1305         };
1306
1307         let configuration = {
1308             modelInvariantId:"testModelInvariantId",
1309             modelVersionId:"testModelVersionId",
1310             modelCustomizationId:"testModelCustomizationId",
1311             nodeId:"testNodeId",
1312         };
1313
1314         let port = {
1315             portId:"testPort",
1316             portStatus:"open",
1317         };
1318
1319         mockAaiService.getLoggedInUserID = (successFunction) => {
1320             successFunction( {data:"testLoggedInUserId"} );
1321         };
1322
1323         mockUibModal.open = (testResponse) => {
1324             resopnse = testResponse.resolve;
1325         };
1326
1327         mockCOMPONENT.MSO_CHANGE_PORT_STATUS_REQ = "testMsoPortStatus";
1328
1329         // when
1330         $scope.togglePortStatus(serviceObject, configuration,port);
1331
1332         // then
1333         expect( resopnse.msoType() ).toEqual("testMsoPortStatus");
1334         expect( resopnse.requestParams().serviceModel.modelInvariantId ).toEqual("testInvariantUuid");
1335         expect( resopnse.requestParams().serviceModel.modelVersionId ).toEqual("testUuid");
1336         expect( resopnse.requestParams().serviceModel.modelName ).toEqual("testService");
1337         expect( resopnse.requestParams().serviceModel.modelVersion ).toEqual("testVersion");
1338         expect( resopnse.requestParams().serviceInstanceId ).toEqual("testServiceInstanceId");
1339         expect( resopnse.requestParams().configurationModel.modelInvariantId ).toEqual("testModelInvariantId");
1340         expect( resopnse.requestParams().configurationModel.modelVersionId ).toEqual("testModelVersionId");
1341         expect( resopnse.requestParams().configurationModel.modelCustomizationId ).toEqual("testModelCustomizationId");
1342         expect( resopnse.requestParams().configurationId ).toEqual("testNodeId");
1343         expect( resopnse.requestParams().userId ).toEqual("testLoggedInUserId");
1344         expect( resopnse.requestParams().portId ).toEqual("testPort");
1345         expect( resopnse.requestParams().portStatus ).toEqual("open");
1346     });
1347
1348
1349     test('Verify getServiceInstancesSearchResults will get global customer Id from AaiService with proper service instance', ()  => {
1350         // given
1351         let selectedCustomer = 'testCustomer';
1352         let selectedInstanceIdentifierType = 'testInstanceIdentifierType';
1353         let selectedServiceInstance = 'testServiceInstance ';
1354         let selectedProject = "testProject";
1355         let selectedOwningEntity = "testOwningEntity";
1356
1357         let globalCustomerId = 'testCustomerIdResponse';
1358
1359         mockAaiService.getGlobalCustomerIdByInstanceIdentifier = jestMock.fn((serviceInstance, instanceIdentifierType) => {
1360             if(serviceInstance===selectedServiceInstance && instanceIdentifierType == selectedInstanceIdentifierType){
1361                 return Promise.resolve(globalCustomerId);
1362             }
1363             return Promise.reject();
1364         });
1365
1366         mockAaiService.getMultipleValueParamQueryString = ( element, subPath) => {
1367             return subPath + '/ ' + element;
1368         };
1369
1370         mockAaiService.getJoinedQueryString = jestMock.fn();
1371
1372         mock_.map = (element,id) => {
1373             return element;
1374         };
1375
1376         mockCOMPONENT.PROJECT_SUB_PATH = "test/project/sub";
1377         mockCOMPONENT.OWNING_ENTITY_SUB_PATH = "test/entity/sub";
1378         mockCOMPONENT.SELECTED_SUBSCRIBER_SUB_PATH = "test/subscriber/sub";
1379         mockCOMPONENT.SELECTED_SERVICE_INSTANCE_SUB_PATH = "test/service/instance/sub";
1380         mockCOMPONENT.SELECTED_SERVICE_SUB_PATH = "text/service/sub";
1381
1382         mockUtilityService.hasContents = (element) => {
1383           if (  element ===  selectedCustomer ||
1384                 element === selectedServiceInstance ||
1385                 element === globalCustomerId )
1386               return true;
1387         };
1388
1389         window.location = {};
1390
1391         // when
1392         $scope.getServiceInstancesSearchResults(selectedCustomer, selectedInstanceIdentifierType, selectedServiceInstance, selectedProject, selectedOwningEntity);
1393
1394         // then
1395         expect(mockAaiService.getGlobalCustomerIdByInstanceIdentifier).toHaveBeenCalledWith(selectedServiceInstance,selectedInstanceIdentifierType);
1396     });
1397
1398     test('Verify getServiceInstancesSearchResults will alert error if non of parameters is located in UtilityService', ()  => {
1399         // given
1400         let selectedCustomer = 'testCustomer';
1401         let selectedInstanceIdentifierType = 'testInstanceIdentifierType';
1402         let selectedServiceInstance = 'testServiceInstance ';
1403         let selectedProject = "testProject";
1404         let selectedOwningEntity = "testOwningEntity";
1405
1406         let globalCustomerId = 'testCustomerIdResponse';
1407
1408         mockAaiService.getGlobalCustomerIdByInstanceIdentifier = (serviceInstance, instanceIdentifierType) => {
1409             if(serviceInstance===selectedServiceInstance && instanceIdentifierType == selectedInstanceIdentifierType){
1410                 return Promise.resolve(globalCustomerId);
1411             }
1412             return Promise.reject();
1413         };
1414
1415         mockAaiService.getMultipleValueParamQueryString = ( element, subPath) => {
1416             return subPath + '/ ' + element;
1417         };
1418
1419         mockAaiService.getJoinedQueryString = (queryArray) => {
1420             let joinedQuery = "";
1421             queryArray.forEach((element)=>{
1422                 joinedQuery += element + "//"
1423             });
1424
1425             return joinedQuery;
1426         };
1427
1428         mock_.map = (element,id) => {
1429             return element;
1430         };
1431
1432         mockCOMPONENT.PROJECT_SUB_PATH = "test/project/sub";
1433         mockCOMPONENT.OWNING_ENTITY_SUB_PATH = "test/entity/sub";
1434         mockCOMPONENT.SELECTED_SUBSCRIBER_SUB_PATH = "test/subscriber/sub";
1435         mockCOMPONENT.SELECTED_SERVICE_INSTANCE_SUB_PATH = "test/service/instance/sub";
1436         mockCOMPONENT.SELECTED_SERVICE_SUB_PATH = "text/service/sub";
1437
1438         mockUtilityService.hasContents = (element) => {
1439                 return false;
1440         };
1441
1442         alert = jestMock.fn();
1443         mockFIELD.ERROR.SELECT = "testError";
1444
1445         window.location = {};
1446
1447         // when
1448         $scope.getServiceInstancesSearchResults(selectedCustomer, selectedInstanceIdentifierType, selectedServiceInstance, selectedProject, selectedOwningEntity);
1449
1450         // then
1451         expect(alert).toHaveBeenCalledWith("testError");
1452     });
1453
1454     test('Verify getServiceInstancesSearchResults will navigate to proper page if selected service instance is not present in UtilityService', ()  => {
1455         // given
1456         let selectedCustomer = 'testCustomer';
1457         let selectedInstanceIdentifierType = 'testInstanceIdentifierType';
1458         let selectedServiceInstance = 'testServiceInstance ';
1459         let selectedProject = "testProject";
1460         let selectedOwningEntity = "testOwningEntity";
1461
1462         let globalCustomerId = 'testCustomerIdResponse';
1463
1464         mockAaiService.getGlobalCustomerIdByInstanceIdentifier = (serviceInstance, instanceIdentifierType) => {
1465             if(serviceInstance===selectedServiceInstance && instanceIdentifierType == selectedInstanceIdentifierType){
1466                 return Promise.resolve(globalCustomerId);
1467             }
1468             return Promise.reject();
1469         };
1470
1471         mockAaiService.getMultipleValueParamQueryString = ( element, subPath) => {
1472             return subPath + element;
1473         };
1474
1475         mockAaiService.getJoinedQueryString = jestMock.fn();
1476
1477         mock_.map = (element,id) => {
1478             return element;
1479         };
1480
1481         mockCOMPONENT.PROJECT_SUB_PATH = "test/project/sub/";
1482         mockCOMPONENT.OWNING_ENTITY_SUB_PATH = "test/entity/sub/";
1483         mockCOMPONENT.SELECTED_SUBSCRIBER_SUB_PATH = "test/subscriber/sub/";
1484         mockCOMPONENT.SELECTED_SERVICE_INSTANCE_SUB_PATH = "test/service/instance/sub/";
1485         mockCOMPONENT.SELECTED_SERVICE_SUB_PATH = "text/service/sub/";
1486
1487
1488         mockUtilityService.hasContents = (element) => {
1489             return element === selectedCustomer;
1490         };
1491
1492         window.location = {};
1493
1494         // when
1495         $scope.getServiceInstancesSearchResults(selectedCustomer, selectedInstanceIdentifierType, selectedServiceInstance, selectedProject, selectedOwningEntity);
1496
1497         // then
1498         expect(mockAaiService.getJoinedQueryString).toHaveBeenCalledWith(expect.arrayContaining([
1499             mockCOMPONENT.PROJECT_SUB_PATH+selectedProject,
1500             mockCOMPONENT.OWNING_ENTITY_SUB_PATH+selectedOwningEntity,
1501             mockCOMPONENT.SELECTED_SUBSCRIBER_SUB_PATH+selectedCustomer
1502         ]));
1503     });
1504
1505
1506 });