Merge changes Ib4430bf2,Icc0bdb9e,I2736b984
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / objectsToTree / models / vrf / vrfModal / networkStep / network.step.service.spec.ts
1 import {NgRedux} from "@angular-redux/store";
2 import {AppState} from "../../../../../../../shared/store/reducers";
3 import {getTestBed, TestBed} from "@angular/core/testing";
4 import {NgReduxTestingModule} from "@angular-redux/store/testing";
5 import {HttpClientTestingModule} from "@angular/common/http/testing";
6 import {FeatureFlagsService} from "../../../../../../../shared/services/featureFlag/feature-flags.service";
7 import {AaiService} from "../../../../../../../shared/services/aaiService/aai.service";
8 import {NetworkStepService} from "./network.step.service";
9 import {updateGenericModalCriteria} from "../../../../../../../shared/storeUtil/utils/global/global.actions";
10 import {ITableContent} from "../../../../../../../shared/components/searchMembersModal/members-table/element-table-row.model";
11
12 describe('Network step service', () => {
13   let injector;
14   let service: NetworkStepService;
15   let store: NgRedux<AppState>;
16   beforeAll(done => (async () => {
17     TestBed.configureTestingModule({
18       imports: [NgReduxTestingModule, HttpClientTestingModule],
19       providers: [
20         NetworkStepService,
21         FeatureFlagsService,
22         AaiService
23       ]
24     });
25     await TestBed.compileComponents();
26     injector = getTestBed();
27     service = injector.get(NetworkStepService);
28     store = injector.get(NgRedux);
29   })().then(done).catch(done.fail));
30
31   test('service should be defined', () => {
32     expect(service).toBeDefined();
33   });
34
35
36   test('networkStep', () => {
37     spyOn(store, 'getState').and.returnValue({
38       "global": {
39         "genericModalHelper": {
40           "selectedNetwork": {
41             "action": "None",
42             "instanceName": "NETWORK_1_INSTANCE_NAME",
43             "instanceId": "NETWORK_1_INSTANCE_ID",
44             "orchStatus": null,
45             "productFamilyId": null,
46             "lcpCloudRegionId": "hvf23b",
47             "tenantId": "3e9a20a3e89e45f884e09df0cc2d2d2a",
48             "tenantName": "APPC-24595-T-IST-02C",
49             "modelInfo": {
50               "modelInvariantId": "network-instance-model-invariant-id",
51               "modelVersionId": "7a6ee536-f052-46fa-aa7e-2fca9d674c44",
52               "modelVersion": "2.0",
53               "modelName": "vf_vEPDG",
54               "modelType": "vnf"
55             },
56             "roles": ["network role 1", "network role 2"],
57             "instanceType": "NETWORK_1_INSTANCE_TYPE",
58             "provStatus": null,
59             "inMaint": false,
60             "uuid": "7a6ee536-f052-46fa-aa7e-2fca9d674c44",
61             "originalName": null,
62             "legacyRegion": null,
63             "lineOfBusiness": null,
64             "platformName": null,
65             "trackById": "VNF1_INSTANCE_ID",
66             "serviceInstanceId": "service-instance-id1",
67             "serviceInstanceName": "service-instance-name",
68             "isSelected": true
69           },
70           "selectedVpn": {
71             "vpn-id": "120d39fb-3627-473d-913c-d228dd0f8e5b",
72             "vpn-name": "LPPVPN",
73             "vpn-platform": "AVPN",
74             "vpn-type": "SERVICE-INFRASTRUCTURE",
75             "vpn-region": "USA,EMEA",
76             "customer-vpn-id": "VPN1260",
77             "model-customization-id": null,
78             "model-invariant-id": null,
79             "model-version-id": null,
80             "route-targets": null,
81             "isSelected": true
82           }
83         },
84         "genericModalCriteria": {"roles": ["-- select an option --", "network role 1", "network role 2", "network role 3", "network role 4", "network role 5"]},
85         "name": null,
86         "flags": {
87           "CREATE_INSTANCE_TEST": false,
88           "EMPTY_DRAWING_BOARD_TEST": false,
89           "FLAG_NETWORK_TO_ASYNC_INSTANTIATION": false,
90           "FLAG_ASYNC_INSTANTIATION": true,
91           "FLAG_ASYNC_JOBS": true,
92           "FLAG_ADD_MSO_TESTAPI_FIELD": true,
93           "FLAG_UNASSIGN_SERVICE": false,
94           "FLAG_SERVICE_MODEL_CACHE": false,
95           "FLAG_SHOW_ASSIGNMENTS": true,
96           "FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS": true,
97           "FLAG_DUPLICATE_VNF": true,
98           "FLAG_DEFAULT_VNF": true,
99           "FLAG_SETTING_DEFAULTS_IN_DRAWING_BOARD": true,
100           "FLAG_A_LA_CARTE_AUDIT_INFO": true,
101           "FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST": true,
102           "FLAG_PRESENT_PROVIDER_NETWORKS_ASSOCIATIONS": true,
103           "FLAG_1810_CR_SOFT_DELETE_ALACARTE_VF_MODULE": true,
104           "FLAG_1902_NEW_VIEW_EDIT": true,
105           "FLAG_VF_MODULE_RESUME_STATUS_CREATE": true,
106           "FLAG_1906_COMPONENT_INFO": true
107         },
108         "drawingBoardStatus": "CREATE",
109         "type": "UPDATE_DRAWING_BOARD_STATUS"
110       }, "service": {
111         "serviceHierarchy": {
112           "f028b2e2-7080-4b13-91b2-94944d4c42d8": {
113             "service": {
114               "uuid": "f028b2e2-7080-4b13-91b2-94944d4c42d8",
115               "invariantUuid": "dfc2c44c-2429-44ca-ae26-1e6dc1f207fb",
116               "name": "infraVPN",
117               "version": "1.0",
118               "toscaModelURL": null,
119               "category": "Network Service",
120               "serviceType": "BONDING",
121               "serviceRole": "INFRASTRUCTURE-VPN",
122               "description": "ddd",
123               "serviceEcompNaming": "true",
124               "instantiationType": "A-La-Carte",
125               "inputs": {},
126               "vidNotions": {"instantiationUI": "macroService", "modelCategory": "other", "viewEditUI": "legacy"}
127             },
128             "vnfs": {},
129             "networks": {},
130             "collectionResources": {},
131             "configurations": {},
132             "fabricConfigurations": {},
133             "serviceProxies": {
134               "misvpn_service_proxy 0": {
135                 "uuid": "35186eb0-e6b6-4fa5-86bb-1501b342a7b1",
136                 "invariantUuid": "73f89e21-b96c-473f-8884-8b93bcbd2f76",
137                 "description": "A Proxy for Service MISVPN_SERVICE",
138                 "name": "MISVPN_SERVICE Service Proxy",
139                 "version": "3.0",
140                 "customizationUuid": "4c2fb7e0-a0a5-4b32-b6ed-6a974e55d923",
141                 "inputs": {},
142                 "commands": {},
143                 "properties": {"ecomp_generated_naming": "false"},
144                 "type": "Service Proxy",
145                 "sourceModelUuid": "d5cc7d15-c842-450e-95ae-2a69e66dd23b",
146                 "sourceModelInvariant": "c126ec86-59fe-48c0-9532-e39a9b3e5272",
147                 "sourceModelName": "MISVPN_SERVICE"
148               }
149             },
150             "vfModules": {},
151             "volumeGroups": {},
152             "pnfs": {},
153             "vnfGroups": {},
154             "vrfs": {
155               "VRF Entry Configuration 0": {
156                 "uuid": "9cac02be-2489-4374-888d-2863b4511a59",
157                 "invariantUuid": "b67a289b-1688-496d-86e8-1583c828be0a",
158                 "description": "VRF Entry configuration object",
159                 "name": "VRF Entry Configuration",
160                 "version": "30.0",
161                 "customizationUuid": "dd024d73-9bd1-425d-9db5-476338d53433",
162                 "inputs": {},
163                 "commands": {},
164                 "properties": {"ecomp_generated_naming": "false"},
165                 "type": "Configuration",
166                 "modelCustomizationName": "VRF Entry Configuration 0",
167                 "sourceNodes": [],
168                 "collectorNodes": null,
169                 "configurationByPolicy": false
170               }
171             }
172           }
173         },
174         "serviceInstance": {
175           "f028b2e2-7080-4b13-91b2-94944d4c42d8": {
176             "action": "Create",
177             "isDirty": false,
178             "vnfs": {},
179             "vrfs": {},
180             "instanceParams": [{}],
181             "validationCounter": 0,
182             "existingNames": {"dfd": ""},
183             "existingVNFCounterMap": {},
184             "existingVRFCounterMap": {},
185             "existingVnfGroupCounterMap": {},
186             "existingNetworksCounterMap": {},
187             "optionalGroupMembersMap": {},
188             "networks": {},
189             "vnfGroups": {},
190             "bulkSize": 1,
191             "instanceName": "dfd",
192             "globalSubscriberId": "e433710f-9217-458d-a79d-1c7aff376d89",
193             "subscriptionServiceType": "TYLER SILVIA",
194             "owningEntityId": "d61e6f2d-12fa-4cc2-91df-7c244011d6fc",
195             "projectName": "WATKINS",
196             "rollbackOnFailure": "true",
197             "aicZoneName": null,
198             "owningEntityName": "WayneHolland",
199             "testApi": "VNF_API",
200             "tenantName": null,
201             "modelInfo": {
202               "modelInvariantId": "dfc2c44c-2429-44ca-ae26-1e6dc1f207fb",
203               "modelVersionId": "f028b2e2-7080-4b13-91b2-94944d4c42d8",
204               "modelName": "infraVPN",
205               "modelVersion": "1.0",
206               "uuid": "f028b2e2-7080-4b13-91b2-94944d4c42d8",
207               "modelUniqueId": "f028b2e2-7080-4b13-91b2-94944d4c42d8"
208             },
209             "isALaCarte": true,
210             "name": "infraVPN",
211             "version": "1.0",
212             "description": "ddd",
213             "category": "Network Service",
214             "uuid": "f028b2e2-7080-4b13-91b2-94944d4c42d8",
215             "invariantUuid": "dfc2c44c-2429-44ca-ae26-1e6dc1f207fb",
216             "serviceType": "BONDING",
217             "serviceRole": "INFRASTRUCTURE-VPN",
218             "vidNotions": {"instantiationUI": "macroService", "modelCategory": "other", "viewEditUI": "legacy"},
219             "isEcompGeneratedNaming": true,
220             "isMultiStepDesign": false
221           }
222         },
223         "type": "UPDATE_CATEGORY_PARAMETERS",
224         "categoryParameters": {
225           "owningEntityList": [{
226             "id": "d61e6f2d-12fa-4cc2-91df-7c244011d6fc",
227             "name": "WayneHolland"
228           }, {"id": "Melissa", "name": "Melissa"}, {"id": "aaa1", "name": "aaa1"}],
229           "projectList": [{"id": "WATKINS", "name": "WATKINS"}, {"id": "x1", "name": "x1"}, {"id": "yyy1", "name": "yyy1"}],
230           "lineOfBusinessList": [{"id": "ONAP", "name": "ONAP"}, {"id": "zzz1", "name": "zzz1"}],
231           "platformList": [{"id": "platform", "name": "platform"}, {"id": "xxx1", "name": "xxx1"}]
232         }
233       }
234     });
235     const networkStep = service.getNetworkStep(
236       "f028b2e2-7080-4b13-91b2-94944d4c42d8",
237       <any>{
238         data: {
239           children: [],
240           componentInfoType: "VRF",
241           count: 0,
242           disabled: false,
243           id: "dd024d73-9bd1-425d-9db5-476338d53433",
244           isEcompGeneratedNaming: false,
245           max: 1,
246           modelCustomizationId: "dd024d73-9bd1-425d-9db5-476338d53433",
247           modelUniqueId: "dd024d73-9bd1-425d-9db5-476338d53433",
248           modelVersionId: "9cac02be-2489-4374-888d-2863b4511a59",
249           name: "VRF Entry Configuration 0",
250           tooltip: "VRF",
251           type: "VRF",
252           typeName: "VRF"
253         }
254       });
255
256
257     expect(networkStep.type).toEqual('Network');
258     expect(networkStep.title).toEqual('Associate network to VRF Entry');
259     expect(networkStep.description).toEqual('Select a network to associate to the VRF Entry');
260     expect(networkStep.noElementsMsg).toEqual('No network were found.');
261     expect(networkStep.maxSelectRow).toEqual(1);
262     expect(networkStep.uniqObjectField).toEqual('instanceId');
263     expect(networkStep.topButton.text).toEqual('Next');
264     expect(networkStep.criteria).toHaveLength(1);
265
266   });
267
268   test('getsNetworkStepSearchFields', () => {
269     const networkStepSearchFields = service.getsNetworkStepSearchFields({
270       "lcpCloudRegionId": "lcpCloudRegionId",
271       "tenantName": "tenantName"
272     });
273
274     expect(networkStepSearchFields[0].value).toEqual("lcpCloudRegionId");
275     expect(networkStepSearchFields[1].value).toEqual("tenantName");
276     expect(networkStepSearchFields[2].value).toEqual("Active");
277     expect(networkStepSearchFields[3].value).toEqual("VPN binding");
278   });
279
280   test('generateRolesOptions should sort networks roles, check if should add "Not assigned" option', () => {
281     const networks = [
282       {"role": "2"},
283       {"role": "3"},
284       {"role": "4"},
285       {"role": "1"},
286       {"role": "6"}
287     ];
288
289     spyOn(store, 'dispatch');
290
291     service.generateRolesOptions(networks);
292     expect(store.dispatch).toHaveBeenCalledWith(updateGenericModalCriteria("roles", ["-- select an option --", "1", "2", "3", "4", "6"]))
293
294     networks.push({"role": null});
295     service.generateRolesOptions(networks);
296     expect(store.dispatch).toHaveBeenCalledWith(updateGenericModalCriteria("roles", ["-- select an option --", "Not assigned", "1", "2", "3", "4", "6"]))
297   });
298
299   test('shouldAddNotAssigned- check if "Not Assigned" option to roles', () => {
300     const networks = [
301       {"role": "5"},
302       {"role": "3"},
303       {"role": "4"},
304       {"role": "1"},
305       {"role": "6"}
306     ];
307
308     let result: boolean = service.shouldAddNotAssigned(networks);
309     expect(result).toBeFalsy();
310
311     networks.push({"role": null});
312
313     result = service.shouldAddNotAssigned(networks);
314     expect(result).toBeTruthy();
315   });
316
317
318   test('getNetworkStepHeaders should return the correct headers for network popup', () => {
319     let headers = service.getNetworkStepHeaders();
320
321     expect(headers[0].displayName).toEqual('Name');
322     expect(headers[0].key).toEqual(['instanceName']);
323
324     expect(headers[1].displayName).toEqual('Type');
325     expect(headers[1].key).toEqual(['instanceType']);
326
327     expect(headers[2].displayName).toEqual('Role');
328     expect(headers[2].key).toEqual(['role']);
329
330     expect(headers[3].displayName).toEqual('Orch. Status');
331     expect(headers[3].key).toEqual(['orchStatus']);
332
333     expect(headers[4].displayName).toEqual('Physical name');
334     expect(headers[4].key).toEqual(['physicalName']);
335
336     expect(headers[5].displayName).toEqual('Instance ID');
337     expect(headers[5].key).toEqual(['instanceId']);
338
339     expect(headers[6].displayName).toEqual('Model UUID');
340     expect(headers[6].key).toEqual(['modelInfo', 'modelVersionId']);
341
342     expect(headers[7].displayName).toEqual('Service name');
343     expect(headers[7].key).toEqual(['serviceName']);
344
345     expect(headers[8].displayName).toEqual('Service UUID');
346     expect(headers[8].key).toEqual(['serviceUUID']);
347
348     expect(headers[9].displayName).toEqual('Tenant');
349     expect(headers[9].key).toEqual(['tenantName']);
350
351     expect(headers[10].displayName).toEqual('Region');
352     expect(headers[10].key).toEqual(['lcpCloudRegionId']);
353   });
354
355   test('getElementsFirstStep should return sort networks by instance name', () => {
356     let networks = [
357       {"instanceUUID": "B"},
358       {"instanceUUID": "A"},
359       {"instanceUUID": "D"},
360       {"instanceUUID": "C"},
361       {"instanceUUID": "E"}
362     ];
363
364     let sortedNetworkByInstanceName = service.sortElementsResultByField(networks, "instanceUUID");
365     expect(sortedNetworkByInstanceName).toEqual([
366       {"instanceUUID": "A"},
367       {"instanceUUID": "B"},
368       {"instanceUUID": "C"},
369       {"instanceUUID": "D"},
370       {"instanceUUID": "E"}
371     ])
372   });
373
374
375   test('getNetworkTableContent', () => {
376     let tableContent: ITableContent[] = service.getNetworkTableContent();
377     expect(tableContent).toEqual(
378     [
379       {
380         id: 'instanceName',
381         contents: [{
382           id: ['name'],
383           value: ["instanceName"]
384         }]
385       },
386       {
387         id: 'instanceType',
388         contents: [{
389           id: ['type'],
390           value: ['instanceType']
391         }]
392       },
393       {
394         id: 'role',
395         contents: [{
396           id: ['role'],
397           value: ['role']
398         }]
399       },
400       {
401         id: 'network-orch-status',
402         contents: [{
403           id: ['orchStatus'],
404           value: ['orchStatus']
405         }]
406       },
407       {
408         id: 'network-physical-name',
409         contents: [{
410           id: ['physicalName'],
411           value: ['physicalName']
412         }]
413       },
414       {
415         id: 'network-instance-id',
416         contents: [{
417           id: ['instanceID'],
418           value: ['instanceId']
419         }]
420       },
421       {
422         id: 'network-model-uuid',
423         contents: [{
424           id: ['modelUUID'],
425           value: ['modelInfo', 'modelVersionId']
426         }]
427       },
428       {
429         id: 'network-serviceName',
430         contents: [{
431           id: ['serviceName'],
432           value: ['serviceName']
433         }]
434       },
435       {
436         id: 'network-service-id',
437         contents: [{
438           id: ['serviceUUID'],
439           value: ['serviceUUID']
440         }]
441       },
442       {
443         id: 'network-tenantName',
444         contents: [{
445           id: ['tenant'],
446           value: ['tenantName']
447         }]
448       },
449       {
450         id: 'network-region',
451         contents: [{
452           id: ['region'],
453           value: ['lcpCloudRegionId']
454         }]
455       }
456     ]);
457   });
458 });