AAI Query optimization for VID
[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         mockAaiService.getSubscriberNameAndServiceInstanceInfo = (customerId, serviceInstanceId, serviceIdentifierType, subscriberName, successFunction) => {
695             successFunction({"serviceInstanceId":"5d942bc7-3acf-4e35-836a-393619ebde66",
696                 "serviceInstanceName":"dpa2actsf5001v_Port_Mirroring_dpa2a_SVC",
697                 "modelVersionId":"a9088517-efe8-4bed-9c54-534462cb08c2",
698                 "modelInvariantId":"0757d856-a9c6-450d-b494-e1c0a4aab76f",
699                 "orchestrationStatus":"Active","subscriberName":"Mobility"});
700         };
701
702         mock_.map = (serviceNetworkVlans, networkId) => {
703             return ["aaiNetworkId1","aaiNetworkId2"];
704         };
705
706         // when
707         return $scope.getComponentList('','').
708         then(components =>{
709             expect(components).toEqual("testComponentList")
710         });
711
712     });
713
714     test('Verify handleServerError sets proper  $scope.error and $scope.status', () => {
715         // given
716         mockUtilityService.getHttpErrorMessage = (response) => {return response.statusText};
717         mockFIELD.ERROR.SYSTEM_ERROR = "testSystemError";
718         mockFIELD.STATUS.ERROR = "testStatusError";
719
720         // when
721         $scope.handleServerError({statusText:'testStatusError'},'');
722
723         // then
724         expect($scope.error).toEqual("testSystemError (testStatusError)");
725         expect($scope.status).toEqual("testStatusError");
726     });
727
728     test('Verify showContentError sets proper $scope.error and $scope.status if UtilityService has that content', () => {
729         // given
730         mockFIELD.STATUS.ERROR = "testStatusError";
731
732         mockUtilityService.hasContents = (content) => {
733           return content === 'testContentError';
734
735         };
736
737         // when
738         $scope.showContentError('testContentError');
739
740         // then
741         expect($scope.error).toEqual("System failure (testContentError)");
742         expect($scope.status).toEqual("testStatusError");
743     });
744
745     test('Verify showContentError sets proper $scope.error and $scope.status if UtilityService has not that content', () => {
746         // given
747         mockFIELD.ERROR.SYSTEM_ERROR = "testSystemError";
748         mockFIELD.STATUS.ERROR = "testStatusError";
749
750         mockUtilityService.hasContents = (content) => {
751             return false;
752         };
753
754         // when
755         $scope.showContentError('testContentError');
756
757         // then
758         expect($scope.error).toEqual("testSystemError");
759         expect($scope.status).toEqual("testStatusError");
760     });
761
762     test('Verify handleInitialResponse shows error for response codes other then 200,201,202', ()  => {
763         // given
764         let response = {
765             data:{
766                 status:404,
767             }
768         };
769
770         mockFIELD.ERROR.MSO = "testSystemError";
771         mockFIELD.ERROR.AAI_FETCHING_CUST_DATA = "testStatusError:";
772
773         $scope.showError = jestMock.fn();
774
775         // when
776         $scope.handleInitialResponse(response);
777
778         // then
779         expect($scope.showError).toHaveBeenCalledWith("testSystemError");
780         expect($scope.status).toEqual("testStatusError:404");
781     });
782
783     test('Verify handleInitialResponse updates customer list with response code 202', ()  => {
784         // given
785         let customer ={
786             'globalCustomerId':'testCustomerID',
787             "subscriberName":'testSubscriber',
788             "isPermitted":false
789         };
790         let response = {
791             data:{
792                 status:202,
793                 customer:[customer],
794             }
795         };
796
797         mockFIELD.ID.GLOBAL_CUSTOMER_ID = 'globalCustomerId';
798         mockFIELD.ID.SUBNAME = 'subscriberName';
799         mockFIELD.ID.IS_PERMITTED = 'isPermitted';
800
801         // when
802         $scope.handleInitialResponse(response);
803
804         // then
805         expect($scope.customerList).toContainEqual(customer);
806     });
807
808     test('Verify handleInitialResponse calls showContentError with wrong response ', ()  => {
809         // given
810         $scope.showContentError = jestMock.fn();
811
812         // when
813         $scope.handleInitialResponse(null);
814
815         // then
816         expect($scope.showContentError).toHaveBeenCalledWith(expect.objectContaining({message:"Cannot read property 'data' of null"}));
817     });
818
819     test('Verify isConfigurationDataAvailiable will return proper response', ()  => {
820         // given
821         mockedLog.debug = jestMock.fn();
822         // when
823         expect( $scope.isConfigurationDataAvailiable({configData:{}}) ).toEqual(true);
824         expect( $scope.isConfigurationDataAvailiable({configData:{errorDescription:"testerror"}}) ).toEqual(false);
825         expect( $scope.isConfigurationDataAvailiable({}) ).toEqual(undefined);
826
827     });
828
829     test('Verify isActivateDeactivateEnabled will return proper response', ()  => {
830         // given
831         mockedLog.debug = jestMock.fn();
832
833         $scope.serviceOrchestrationStatus = "active";
834         mockCOMPONENT.ACTIVATE_SERVICE_STATUSES = ["active","up"];
835
836         // when
837         expect( $scope.isActivateDeactivateEnabled("deactivate")).toEqual(true);
838         expect( $scope.isActivateDeactivateEnabled("activate")).toEqual(true);
839
840         $scope.serviceOrchestrationStatus = "down";
841         mockCOMPONENT.ACTIVATE_SERVICE_STATUSES = ["active","up"];
842
843         expect( $scope.isActivateDeactivateEnabled("deactivate")).toEqual(false);
844         expect( $scope.isActivateDeactivateEnabled("activate")).toEqual(false);
845
846         $scope.serviceOrchestrationStatus = null;
847
848         expect( $scope.isActivateDeactivateEnabled(null)).toEqual(false);
849
850     });
851
852     test('Verify isShowVerifyService will return proper response base on feature flag', ()  => {
853         // given
854         mockCOMPONENT.FEATURE_FLAGS.FLAG_SHOW_VERIFY_SERVICE = 'showVerifyService';
855         mockFeatureFlags.isOn = (flag) => {
856             if (flag === 'showVerifyService'){return true};
857         };
858
859         // when
860         expect( $scope.isShowVerifyService()).toEqual(true);
861     });
862
863     test('Verify isEnableVerifyService will return false if is not ALaCarte', ()  => {
864         // given
865         dataService.setALaCarte(false);
866
867         // when
868         expect( $scope.isEnableVerifyService()).toEqual(false);
869     });
870
871     test('Verify isEnableVerifyService will return verifyButtonEnabled if is ALaCarte', ()  => {
872         // given
873         dataService.setALaCarte(true);
874
875         // when
876         $scope.verifyButtonEnabled = true;
877         expect( $scope.isEnableVerifyService()).toEqual(true);
878
879         $scope.verifyButtonEnabled = false;
880         expect( $scope.isEnableVerifyService()).toEqual(false);
881     });
882
883     test('Verify activateVerifyService will post POMBA verification', ()  => {
884         // given
885         mockCOMPONENT.VERIFY_SERVICE_URL = "/testURL";
886
887         mockAaiService.postPOMBAverificationRequest = jestMock.fn();
888
889         $scope.serviceInstanceId = "testInstanceID";
890         $scope.service = {model:{service:{}},instance:{}};
891         $scope.service.model.service.uuid = "testUuid";
892         $scope.service.model.service.invariantUuid = "testInvariantUuid";
893         $scope.globalCustomerId = "testCustomerId";
894         $scope.service.instance.serviceType = "testServiceType";
895
896         // when
897         $scope.activateVerifyService();
898
899         // then
900         expect(mockAaiService.postPOMBAverificationRequest).toHaveBeenCalledWith(
901             "/testURL",
902             expect.objectContaining({'serviceInstanceList':[expect.any(Object)]}),
903             expect.objectContaining({'headers':expect.any(Object)}));
904     });
905
906     test('Verify isShowAssignmentsEnabled will return proper response determine by feature flag', ()  => {
907         // given
908         mockCOMPONENT.FEATURE_FLAGS.FLAG_SHOW_ASSIGNMENTS = "showAssignment";
909
910         mockFeatureFlags.isOn = (flag) => {
911             if (flag === 'showAssignment'){return true};
912         };
913
914         // when
915         $scope.serviceOrchestrationStatus = "assigned";
916         expect( $scope.isShowAssignmentsEnabled() ).toEqual(true);
917
918         $scope.serviceOrchestrationStatus = "notAssigned";
919         expect( $scope.isShowAssignmentsEnabled() ).toEqual(false);
920
921         $scope.serviceOrchestrationStatus = null;
922         expect( $scope.isShowAssignmentsEnabled() ).toEqual(false);
923     });
924
925     test('Verify isActivateFabricConfiguration will return proper response determine by feature flag', ()  => {
926         // given
927         mockCOMPONENT.FEATURE_FLAGS.FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS = "fabricConfigurationAssignment";
928         $scope.hasFabricConfigurations = true;
929
930         mockFeatureFlags.isOn = (flag) => {
931             if (flag === 'fabricConfigurationAssignment'){return true};
932         };
933
934         // when
935         $scope.serviceOrchestrationStatus = "assigned";
936         expect( $scope.isActivateFabricConfiguration() ).toEqual(true);
937
938         $scope.serviceOrchestrationStatus = "notAssigned";
939         expect( $scope.isActivateFabricConfiguration() ).toEqual(false);
940
941         $scope.serviceOrchestrationStatus = null;
942         expect( $scope.isActivateFabricConfiguration() ).toEqual(false);
943     });
944
945     test('Verify isResumeShown will return proper response determine by feature flag with disabled ActivateDeactivate', ()  => {
946         // given
947         $scope.serviceOrchestrationStatus = "assigned";
948         $scope.isActivateDeactivateEnabled = () => {return false};
949
950         // when
951         expect( $scope.isResumeShown("assigned") ).toEqual(true);
952         expect( $scope.isResumeShown("unAssigned") ).toEqual(false);
953
954     });
955
956     test('Verify isResumeShown will return proper response determine by feature flag with enable ActivateDeactivate', ()  => {
957         // given
958         $scope.serviceOrchestrationStatus = "assigned";
959         $scope.isActivateDeactivateEnabled = () => {return true};
960
961         // when
962         expect( $scope.isResumeShown("assigned") ).toEqual(false);
963         expect( $scope.isResumeShown("unAssigned") ).toEqual(false);
964
965     });
966
967     test('Verify close will call time out cancel and hides pop up window if timer is defined', ()  => {
968         // given
969         $scope.timer = 1000;
970         $scope.isPopupVisible = true;
971
972         timeout.cancel = jestMock.fn();
973
974         // when
975         $scope.close();
976
977         // then
978         expect(timeout.cancel).toHaveBeenCalledWith(1000);
979         expect($scope.isPopupVisible).toEqual(false);
980     });
981
982     test('Verify close will hide pop up window if timer is undefined', ()  => {
983         // given
984         $scope.timer = undefined;
985         $scope.isPopupVisible = true;
986
987         // when
988         $scope.close();
989
990         // then
991         expect($scope.isPopupVisible).toEqual(false);
992     });
993
994     test('Verify reloadRoute will call reload on rout', ()  => {
995         // given
996         mockRoute.reload = jestMock.fn();
997
998         // when
999         $scope.reloadRoute();
1000
1001         // then
1002         expect(mockRoute.reload).toHaveBeenCalled();
1003     });
1004
1005     test('Verify prevPage will decrease currentPage', ()  => {
1006         // given
1007         $scope.currentPage = 5;
1008
1009         // when
1010         $scope.prevPage();
1011
1012         // then
1013         expect($scope.currentPage).toEqual(4);
1014     });
1015
1016     test('Verify showAssignmentsSDNC will return proper response base on VIDCONFIGURATION', ()  => {
1017         // given
1018         $scope.service = {};
1019         $scope.service.instance = {};
1020         $scope.service.instance.id = "testServiceInstanceId";
1021
1022         mockVIDCONFIGURATION.SDNC_SHOW_ASSIGNMENTS_URL = "test/ulr/to/<SERVICE_INSTANCE_ID>";
1023
1024         // when
1025         expect( $scope.showAssignmentsSDNC() ).toEqual("test/ulr/to/testServiceInstanceId");
1026     });
1027
1028     test('Verify showAssignmentsSDNC will return null if service instance dos not exist or is null', ()  => {
1029         // given
1030         $scope.service = {};
1031
1032         // when
1033         expect( $scope.showAssignmentsSDNC() ).toEqual(null);
1034
1035         $scope.service.instance = null;
1036         expect( $scope.showAssignmentsSDNC() ).toEqual(null);
1037     });
1038
1039     test('Verify activateFabricConfigurationMSO with logged in user, will call uibModal open that will return response ', ()  => {
1040         // given
1041         let resopnse = {};
1042
1043         mockCOMPONENT.MSO_ACTIVATE_FABRIC_CONFIGURATION_REQ = "testMsoActivateType";
1044
1045         $scope.service = {};
1046         $scope.service.model = {};
1047         $scope.service = {};
1048         $scope.serviceInstanceId= "testServiceInstanceId";
1049
1050         dataService.setLoggedInUserId("testUserId");
1051
1052         mockUibModal.open = (testResponse) => {
1053             resopnse = testResponse.resolve;
1054         };
1055
1056         // when
1057         $scope.activateFabricConfigurationMSO();
1058
1059         // then
1060         expect( resopnse.msoType() ).toEqual("testMsoActivateType");
1061         expect( resopnse.requestParams().serviceInstanceId ).toEqual("testServiceInstanceId");
1062         expect( resopnse.requestParams().userId ).toEqual("testUserId");
1063         expect( resopnse.configuration() ).toEqual(undefined);
1064     });
1065
1066     test('Verify activateFabricConfigurationMSO without logged in user will first get user id from AaiService , will call uibModal open that will return response ', ()  => {
1067         // given
1068         let resopnse = {};
1069
1070         mockCOMPONENT.MSO_ACTIVATE_FABRIC_CONFIGURATION_REQ = "testMsoActivateType";
1071
1072         $scope.service = {};
1073         $scope.service.model = {};
1074         $scope.service = {};
1075         $scope.serviceInstanceId= "testServiceInstanceId";
1076
1077
1078         mockAaiService.getLoggedInUserID = (onSuccess) => {
1079             onSuccess({data:"testAaiUserId"});
1080         };
1081
1082         mockUibModal.open = (testResponse) => {
1083             resopnse = testResponse.resolve;
1084         };
1085
1086         // when
1087         $scope.activateFabricConfigurationMSO();
1088
1089         // then
1090         expect( resopnse.msoType() ).toEqual("testMsoActivateType");
1091         expect( resopnse.requestParams().serviceInstanceId ).toEqual("testServiceInstanceId");
1092         expect( resopnse.requestParams().userId ).toEqual("testAaiUserId");
1093         expect( resopnse.configuration() ).toEqual(undefined);
1094     });
1095
1096     test('Verify activateMSOInstance with logged in user, will get aicZone from AaiService and call uibModal open that will return response ', ()  => {
1097         // given
1098         let resopnse = {};
1099
1100         mockCOMPONENT.MSO_ACTIVATE_SERVICE_REQ = "testMsoActivateType";
1101
1102         $scope.service = {};
1103         $scope.service.model = {};
1104         $scope.service.instance = {};
1105
1106         dataService.setLoggedInUserId("testUserId");
1107
1108         mockAaiService.getAicZoneForPNF = (globalCustomerId,serviceType,serviceInstanceId,getZoneFunction) => {
1109             getZoneFunction("testAicZone");
1110         };
1111
1112         mockUibModal.open = (testResponse) => {
1113             resopnse = testResponse.resolve;
1114         };
1115
1116         // when
1117         $scope.activateMSOInstance();
1118
1119         // then
1120         expect( resopnse.msoType() ).toEqual("testMsoActivateType");
1121         expect( resopnse.requestParams().aicZone ).toEqual("testAicZone");
1122         expect( resopnse.requestParams().userId ).toEqual("testUserId");
1123         expect( resopnse.configuration() ).toEqual(undefined);
1124     });
1125
1126     test('Verify activateMSOInstance without logged in user will first get user id from AaiService , will call uibModal open that will return response ', ()  => {
1127         // given
1128         let resopnse = {};
1129
1130         mockCOMPONENT.MSO_ACTIVATE_SERVICE_REQ = "testMsoActivateType";
1131
1132         $scope.service = {};
1133         $scope.service.model = {};
1134         $scope.service.instance = {};
1135
1136
1137         mockAaiService.getAicZoneForPNF = (globalCustomerId,serviceType,serviceInstanceId,getZoneFunction) => {
1138             getZoneFunction("testAicZone");
1139         };
1140
1141         mockAaiService.getLoggedInUserID = (onSuccess) => {
1142             onSuccess({data:"testAaiUserId"});
1143         };
1144
1145         mockUibModal.open = (testResponse) => {
1146             resopnse = testResponse.resolve;
1147         };
1148
1149         // when
1150         $scope.activateMSOInstance();
1151
1152         // then
1153         expect( resopnse.msoType() ).toEqual("testMsoActivateType");
1154         expect( resopnse.requestParams().aicZone ).toEqual("testAicZone");
1155         expect( resopnse.requestParams().userId ).toEqual("testAaiUserId");
1156         expect( resopnse.configuration() ).toEqual(undefined);
1157     });
1158
1159     test('Verify deactivateMSOInstance will get call uibModal open that will return response ', ()  => {
1160         // given
1161         let resopnse = {};
1162
1163         mockCOMPONENT.MSO_DEACTIVATE_SERVICE_REQ = "testMsoDeactivateType";
1164
1165         $scope.service = {};
1166         $scope.service.model = {};
1167         $scope.service.instance = {};
1168
1169
1170         mockAaiService.getAicZoneForPNF = (globalCustomerId,serviceType,serviceInstanceId,getZoneFunction) => {
1171             getZoneFunction("testAicZone");
1172         };
1173
1174         mockAaiService.getLoggedInUserID = (onSuccess) => {
1175             onSuccess({data:"testAaiUserId"});
1176         };
1177
1178         mockUibModal.open = (testResponse) => {
1179             resopnse = testResponse.resolve;
1180         };
1181
1182         // when
1183         $scope.deactivateMSOInstance();
1184
1185         // then
1186         expect( resopnse.msoType() ).toEqual("testMsoDeactivateType");
1187         expect( resopnse.requestParams().aicZone ).toEqual("testAicZone");
1188         expect( resopnse.requestParams().userId ).toEqual("testAaiUserId");
1189         expect( resopnse.configuration() ).toEqual(undefined);
1190     });
1191
1192     test('Verify deleteConfiguration will get call uibModal open that will return response ', ()  => {
1193         // given
1194         let resopnse = {};
1195
1196         serviceObject = {
1197             model:{
1198                 service:{
1199                     invariantUuid:"testInvariantUuid",
1200                     uuid:"testUuid",
1201                     name:"testService",
1202                     version:"testVersion",
1203                 }},
1204             instance:{
1205                 serviceInstanceId:"testServiceInstanceId",
1206             }
1207         };
1208
1209         configuration = {
1210             modelInvariantId:"testModelInvariantId",
1211             modelVersionId:"testModelVersionId",
1212             modelCustomizationId:"testModelCustomizationId",
1213             nodeId:"testNodeId",
1214             DELETE:"testDELETE",
1215         };
1216
1217         mockCOMPONENT.MSO_DELETE_CONFIGURATION_REQ = "testMsoDeleteType";
1218
1219         mockAaiService.getLoggedInUserID = (successFunction) => {
1220             successFunction( {data:"testLoggedInUserId"} );
1221         };
1222
1223         mockUibModal.open = (testResponse) => {
1224             resopnse = testResponse.resolve;
1225         };
1226
1227         // when
1228         $scope.deleteConfiguration(serviceObject, configuration);
1229
1230         // then
1231         expect( resopnse.msoType() ).toEqual("testMsoDeleteType");
1232         expect( resopnse.requestParams().serviceModel.modelInvariantId ).toEqual("testInvariantUuid");
1233         expect( resopnse.requestParams().serviceModel.modelVersionId ).toEqual("testUuid");
1234         expect( resopnse.requestParams().serviceModel.modelName ).toEqual("testService");
1235         expect( resopnse.requestParams().serviceModel.modelVersion ).toEqual("testVersion");
1236         expect( resopnse.requestParams().serviceInstanceId ).toEqual("testServiceInstanceId");
1237         expect( resopnse.requestParams().configurationModel.modelInvariantId ).toEqual("testModelInvariantId");
1238         expect( resopnse.requestParams().configurationModel.modelVersionId ).toEqual("testModelVersionId");
1239         expect( resopnse.requestParams().configurationModel.modelCustomizationId ).toEqual("testModelCustomizationId");
1240         expect( resopnse.requestParams().configurationId ).toEqual("testNodeId");
1241         expect( resopnse.requestParams().configStatus ).toEqual("testDELETE");
1242         expect( resopnse.requestParams().userId ).toEqual("testLoggedInUserId");
1243     });
1244
1245     test('Verify toggleConfigurationStatus will get call uibModal open that will return response ', ()  => {
1246         // given
1247         let resopnse = {};
1248
1249         serviceObject = {
1250             model:{
1251                 service:{
1252                     invariantUuid:"testInvariantUuid",
1253                     uuid:"testUuid",
1254                     name:"testService",
1255                     version:"testVersion",
1256                 }},
1257             instance:{
1258                 serviceInstanceId:"testServiceInstanceId",
1259             }
1260         };
1261
1262         configuration = {
1263             modelInvariantId:"testModelInvariantId",
1264             modelVersionId:"testModelVersionId",
1265             modelCustomizationId:"testModelCustomizationId",
1266             nodeId:"testNodeId",
1267             nodeStatus:"testNodeStatus",
1268         };
1269
1270         mockAaiService.getLoggedInUserID = (successFunction) => {
1271             successFunction( {data:"testLoggedInUserId"} );
1272         };
1273
1274         mockUibModal.open = (testResponse) => {
1275             resopnse = testResponse.resolve;
1276         };
1277
1278         mockCOMPONENT.MSO_CHANGE_CONFIG_STATUS_REQ = "testMsoChangeConfig";
1279
1280         // when
1281         $scope.toggleConfigurationStatus(serviceObject, configuration);
1282
1283         // then
1284         expect( resopnse.msoType() ).toEqual("testMsoChangeConfig");
1285         expect( resopnse.requestParams().serviceModel.modelInvariantId ).toEqual("testInvariantUuid");
1286         expect( resopnse.requestParams().serviceModel.modelVersionId ).toEqual("testUuid");
1287         expect( resopnse.requestParams().serviceModel.modelName ).toEqual("testService");
1288         expect( resopnse.requestParams().serviceModel.modelVersion ).toEqual("testVersion");
1289         expect( resopnse.requestParams().serviceInstanceId ).toEqual("testServiceInstanceId");
1290         expect( resopnse.requestParams().configurationModel.modelInvariantId ).toEqual("testModelInvariantId");
1291         expect( resopnse.requestParams().configurationModel.modelVersionId ).toEqual("testModelVersionId");
1292         expect( resopnse.requestParams().configurationModel.modelCustomizationId ).toEqual("testModelCustomizationId");
1293         expect( resopnse.requestParams().configurationId ).toEqual("testNodeId");
1294         expect( resopnse.requestParams().configStatus ).toEqual("testNodeStatus");
1295         expect( resopnse.requestParams().userId ).toEqual("testLoggedInUserId");
1296     });
1297
1298     test('Verify togglePortStatus will get call uibModal open that will return response ', ()  => {
1299         // given
1300         let resopnse = {};
1301
1302         let serviceObject = {
1303             model:{
1304                 service:{
1305                     invariantUuid:"testInvariantUuid",
1306                     uuid:"testUuid",
1307                     name:"testService",
1308                     version:"testVersion",
1309                 }},
1310             instance:{
1311                 serviceInstanceId:"testServiceInstanceId",
1312             }
1313         };
1314
1315         let configuration = {
1316             modelInvariantId:"testModelInvariantId",
1317             modelVersionId:"testModelVersionId",
1318             modelCustomizationId:"testModelCustomizationId",
1319             nodeId:"testNodeId",
1320         };
1321
1322         let port = {
1323             portId:"testPort",
1324             portStatus:"open",
1325         };
1326
1327         mockAaiService.getLoggedInUserID = (successFunction) => {
1328             successFunction( {data:"testLoggedInUserId"} );
1329         };
1330
1331         mockUibModal.open = (testResponse) => {
1332             resopnse = testResponse.resolve;
1333         };
1334
1335         mockCOMPONENT.MSO_CHANGE_PORT_STATUS_REQ = "testMsoPortStatus";
1336
1337         // when
1338         $scope.togglePortStatus(serviceObject, configuration,port);
1339
1340         // then
1341         expect( resopnse.msoType() ).toEqual("testMsoPortStatus");
1342         expect( resopnse.requestParams().serviceModel.modelInvariantId ).toEqual("testInvariantUuid");
1343         expect( resopnse.requestParams().serviceModel.modelVersionId ).toEqual("testUuid");
1344         expect( resopnse.requestParams().serviceModel.modelName ).toEqual("testService");
1345         expect( resopnse.requestParams().serviceModel.modelVersion ).toEqual("testVersion");
1346         expect( resopnse.requestParams().serviceInstanceId ).toEqual("testServiceInstanceId");
1347         expect( resopnse.requestParams().configurationModel.modelInvariantId ).toEqual("testModelInvariantId");
1348         expect( resopnse.requestParams().configurationModel.modelVersionId ).toEqual("testModelVersionId");
1349         expect( resopnse.requestParams().configurationModel.modelCustomizationId ).toEqual("testModelCustomizationId");
1350         expect( resopnse.requestParams().configurationId ).toEqual("testNodeId");
1351         expect( resopnse.requestParams().userId ).toEqual("testLoggedInUserId");
1352         expect( resopnse.requestParams().portId ).toEqual("testPort");
1353         expect( resopnse.requestParams().portStatus ).toEqual("open");
1354     });
1355
1356
1357     test('Verify getServiceInstancesSearchResults will get global customer Id from AaiService with proper service instance', ()  => {
1358         // given
1359         let selectedCustomer = 'testCustomer';
1360         let selectedInstanceIdentifierType = 'testInstanceIdentifierType';
1361         let selectedServiceInstance = 'testServiceInstance ';
1362         let selectedProject = "testProject";
1363         let selectedOwningEntity = "testOwningEntity";
1364
1365         let globalCustomerId = 'testCustomerIdResponse';
1366
1367         mockAaiService.getGlobalCustomerIdByInstanceIdentifier = jestMock.fn((serviceInstance, instanceIdentifierType) => {
1368             if(serviceInstance===selectedServiceInstance && instanceIdentifierType == selectedInstanceIdentifierType){
1369                 return Promise.resolve(globalCustomerId);
1370             }
1371             return Promise.reject();
1372         });
1373
1374         mockAaiService.getMultipleValueParamQueryString = ( element, subPath) => {
1375             return subPath + '/ ' + element;
1376         };
1377
1378         mockAaiService.getJoinedQueryString = jestMock.fn();
1379
1380         mock_.map = (element,id) => {
1381             return element;
1382         };
1383
1384         mockCOMPONENT.PROJECT_SUB_PATH = "test/project/sub";
1385         mockCOMPONENT.OWNING_ENTITY_SUB_PATH = "test/entity/sub";
1386         mockCOMPONENT.SELECTED_SUBSCRIBER_SUB_PATH = "test/subscriber/sub";
1387         mockCOMPONENT.SELECTED_SERVICE_INSTANCE_SUB_PATH = "test/service/instance/sub";
1388         mockCOMPONENT.SELECTED_SERVICE_SUB_PATH = "text/service/sub";
1389
1390         mockUtilityService.hasContents = (element) => {
1391           if (  element ===  selectedCustomer ||
1392                 element === selectedServiceInstance ||
1393                 element === globalCustomerId )
1394               return true;
1395         };
1396
1397         window.location = {};
1398
1399         // when
1400         $scope.getServiceInstancesSearchResults(selectedCustomer, selectedInstanceIdentifierType, selectedServiceInstance, selectedProject, selectedOwningEntity);
1401
1402         // then
1403         expect(mockAaiService.getGlobalCustomerIdByInstanceIdentifier).toHaveBeenCalledWith(selectedServiceInstance,selectedInstanceIdentifierType);
1404     });
1405
1406     test('Verify getServiceInstancesSearchResults will alert error if non of parameters is located in UtilityService', ()  => {
1407         // given
1408         let selectedCustomer = 'testCustomer';
1409         let selectedInstanceIdentifierType = 'testInstanceIdentifierType';
1410         let selectedServiceInstance = 'testServiceInstance ';
1411         let selectedProject = "testProject";
1412         let selectedOwningEntity = "testOwningEntity";
1413
1414         let globalCustomerId = 'testCustomerIdResponse';
1415
1416         mockAaiService.getGlobalCustomerIdByInstanceIdentifier = (serviceInstance, instanceIdentifierType) => {
1417             if(serviceInstance===selectedServiceInstance && instanceIdentifierType == selectedInstanceIdentifierType){
1418                 return Promise.resolve(globalCustomerId);
1419             }
1420             return Promise.reject();
1421         };
1422
1423         mockAaiService.getMultipleValueParamQueryString = ( element, subPath) => {
1424             return subPath + '/ ' + element;
1425         };
1426
1427         mockAaiService.getJoinedQueryString = (queryArray) => {
1428             let joinedQuery = "";
1429             queryArray.forEach((element)=>{
1430                 joinedQuery += element + "//"
1431             });
1432
1433             return joinedQuery;
1434         };
1435
1436         mock_.map = (element,id) => {
1437             return element;
1438         };
1439
1440         mockCOMPONENT.PROJECT_SUB_PATH = "test/project/sub";
1441         mockCOMPONENT.OWNING_ENTITY_SUB_PATH = "test/entity/sub";
1442         mockCOMPONENT.SELECTED_SUBSCRIBER_SUB_PATH = "test/subscriber/sub";
1443         mockCOMPONENT.SELECTED_SERVICE_INSTANCE_SUB_PATH = "test/service/instance/sub";
1444         mockCOMPONENT.SELECTED_SERVICE_SUB_PATH = "text/service/sub";
1445
1446         mockUtilityService.hasContents = (element) => {
1447                 return false;
1448         };
1449
1450         alert = jestMock.fn();
1451         mockFIELD.ERROR.SELECT = "testError";
1452
1453         window.location = {};
1454
1455         // when
1456         $scope.getServiceInstancesSearchResults(selectedCustomer, selectedInstanceIdentifierType, selectedServiceInstance, selectedProject, selectedOwningEntity);
1457
1458         // then
1459         expect(alert).toHaveBeenCalledWith("testError");
1460     });
1461
1462     test('Verify getServiceInstancesSearchResults will navigate to proper page if selected service instance is not present in UtilityService', ()  => {
1463         // given
1464         let selectedCustomer = 'testCustomer';
1465         let selectedInstanceIdentifierType = 'testInstanceIdentifierType';
1466         let selectedServiceInstance = 'testServiceInstance ';
1467         let selectedProject = "testProject";
1468         let selectedOwningEntity = "testOwningEntity";
1469
1470         let globalCustomerId = 'testCustomerIdResponse';
1471
1472         mockAaiService.getGlobalCustomerIdByInstanceIdentifier = (serviceInstance, instanceIdentifierType) => {
1473             if(serviceInstance===selectedServiceInstance && instanceIdentifierType == selectedInstanceIdentifierType){
1474                 return Promise.resolve(globalCustomerId);
1475             }
1476             return Promise.reject();
1477         };
1478
1479         mockAaiService.getMultipleValueParamQueryString = ( element, subPath) => {
1480             return subPath + element;
1481         };
1482
1483         mockAaiService.getJoinedQueryString = jestMock.fn();
1484
1485         mock_.map = (element,id) => {
1486             return element;
1487         };
1488
1489         mockCOMPONENT.PROJECT_SUB_PATH = "test/project/sub/";
1490         mockCOMPONENT.OWNING_ENTITY_SUB_PATH = "test/entity/sub/";
1491         mockCOMPONENT.SELECTED_SUBSCRIBER_SUB_PATH = "test/subscriber/sub/";
1492         mockCOMPONENT.SELECTED_SERVICE_INSTANCE_SUB_PATH = "test/service/instance/sub/";
1493         mockCOMPONENT.SELECTED_SERVICE_SUB_PATH = "text/service/sub/";
1494
1495
1496         mockUtilityService.hasContents = (element) => {
1497             return element === selectedCustomer;
1498         };
1499
1500         window.location = {};
1501
1502         // when
1503         $scope.getServiceInstancesSearchResults(selectedCustomer, selectedInstanceIdentifierType, selectedServiceInstance, selectedProject, selectedOwningEntity);
1504
1505         // then
1506         expect(mockAaiService.getJoinedQueryString).toHaveBeenCalledWith(expect.arrayContaining([
1507             mockCOMPONENT.PROJECT_SUB_PATH+selectedProject,
1508             mockCOMPONENT.OWNING_ENTITY_SUB_PATH+selectedOwningEntity,
1509             mockCOMPONENT.SELECTED_SUBSCRIBER_SUB_PATH+selectedCustomer
1510         ]));
1511     });
1512
1513
1514 });