Fix for Penetration test _ Session and cookie management
[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           "EMPTY_DRAWING_BOARD_TEST": false,
88           "FLAG_NETWORK_TO_ASYNC_INSTANTIATION": false,
89           "FLAG_ENABLE_WEBPACK_MODERN_UI": true,
90           "FLAG_ASYNC_JOBS": true,
91           "FLAG_ADD_MSO_TESTAPI_FIELD": true,
92           "FLAG_UNASSIGN_SERVICE": false,
93           "FLAG_SERVICE_MODEL_CACHE": false,
94           "FLAG_SHOW_ASSIGNMENTS": true,
95           "FLAG_FABRIC_CONFIGURATION_ASSIGNMENTS": true,
96           "FLAG_DUPLICATE_VNF": true,
97           "FLAG_A_LA_CARTE_AUDIT_INFO": true,
98           "FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST": true,
99           "FLAG_PRESENT_PROVIDER_NETWORKS_ASSOCIATIONS": true,
100           "FLAG_1902_NEW_VIEW_EDIT": true,
101           "FLAG_VF_MODULE_RESUME_STATUS_CREATE": true,
102           "FLAG_1906_COMPONENT_INFO": true
103         },
104         "drawingBoardStatus": "CREATE",
105         "type": "UPDATE_DRAWING_BOARD_STATUS"
106       }, "service": {
107         "serviceHierarchy": {
108           "f028b2e2-7080-4b13-91b2-94944d4c42d8": {
109             "service": {
110               "uuid": "f028b2e2-7080-4b13-91b2-94944d4c42d8",
111               "invariantUuid": "dfc2c44c-2429-44ca-ae26-1e6dc1f207fb",
112               "name": "infraVPN",
113               "version": "1.0",
114               "toscaModelURL": null,
115               "category": "Network Service",
116               "serviceType": "BONDING",
117               "serviceRole": "INFRASTRUCTURE-VPN",
118               "description": "ddd",
119               "serviceEcompNaming": "true",
120               "instantiationType": "A-La-Carte",
121               "inputs": {},
122               "vidNotions": {"instantiationUI": "macroService", "modelCategory": "other", "viewEditUI": "legacy"}
123             },
124             "vnfs": {},
125             "networks": {},
126             "collectionResources": {},
127             "configurations": {},
128             "fabricConfigurations": {},
129             "serviceProxies": {
130               "misvpn_service_proxy 0": {
131                 "uuid": "35186eb0-e6b6-4fa5-86bb-1501b342a7b1",
132                 "invariantUuid": "73f89e21-b96c-473f-8884-8b93bcbd2f76",
133                 "description": "A Proxy for Service MISVPN_SERVICE",
134                 "name": "MISVPN_SERVICE Service Proxy",
135                 "version": "3.0",
136                 "customizationUuid": "4c2fb7e0-a0a5-4b32-b6ed-6a974e55d923",
137                 "inputs": {},
138                 "commands": {},
139                 "properties": {"ecomp_generated_naming": "false"},
140                 "type": "Service Proxy",
141                 "sourceModelUuid": "d5cc7d15-c842-450e-95ae-2a69e66dd23b",
142                 "sourceModelInvariant": "c126ec86-59fe-48c0-9532-e39a9b3e5272",
143                 "sourceModelName": "MISVPN_SERVICE"
144               }
145             },
146             "vfModules": {},
147             "volumeGroups": {},
148             "pnfs": {},
149             "vnfGroups": {},
150             "vrfs": {
151               "VRF Entry Configuration 0": {
152                 "uuid": "9cac02be-2489-4374-888d-2863b4511a59",
153                 "invariantUuid": "b67a289b-1688-496d-86e8-1583c828be0a",
154                 "description": "VRF Entry configuration object",
155                 "name": "VRF Entry Configuration",
156                 "version": "30.0",
157                 "customizationUuid": "dd024d73-9bd1-425d-9db5-476338d53433",
158                 "inputs": {},
159                 "commands": {},
160                 "properties": {"ecomp_generated_naming": "false"},
161                 "type": "Configuration",
162                 "modelCustomizationName": "VRF Entry Configuration 0",
163                 "sourceNodes": [],
164                 "collectorNodes": null,
165                 "configurationByPolicy": false
166               }
167             }
168           }
169         },
170         "serviceInstance": {
171           "f028b2e2-7080-4b13-91b2-94944d4c42d8": {
172             "action": "Create",
173             "isDirty": false,
174             "vnfs": {},
175             "vrfs": {},
176             "instanceParams": [{}],
177             "validationCounter": 0,
178             "existingNames": {"dfd": ""},
179             "existingVNFCounterMap": {},
180             "existingVRFCounterMap": {},
181             "existingVnfGroupCounterMap": {},
182             "existingNetworksCounterMap": {},
183             "optionalGroupMembersMap": {},
184             "networks": {},
185             "vnfGroups": {},
186             "bulkSize": 1,
187             "instanceName": "dfd",
188             "globalSubscriberId": "e433710f-9217-458d-a79d-1c7aff376d89",
189             "subscriptionServiceType": "TYLER SILVIA",
190             "owningEntityId": "d61e6f2d-12fa-4cc2-91df-7c244011d6fc",
191             "projectName": "WATKINS",
192             "rollbackOnFailure": "true",
193             "aicZoneName": null,
194             "owningEntityName": "WayneHolland",
195             "testApi": "VNF_API",
196             "tenantName": null,
197             "modelInfo": {
198               "modelInvariantId": "dfc2c44c-2429-44ca-ae26-1e6dc1f207fb",
199               "modelVersionId": "f028b2e2-7080-4b13-91b2-94944d4c42d8",
200               "modelName": "infraVPN",
201               "modelVersion": "1.0",
202               "uuid": "f028b2e2-7080-4b13-91b2-94944d4c42d8",
203               "modelUniqueId": "f028b2e2-7080-4b13-91b2-94944d4c42d8"
204             },
205             "isALaCarte": true,
206             "name": "infraVPN",
207             "version": "1.0",
208             "description": "ddd",
209             "category": "Network Service",
210             "uuid": "f028b2e2-7080-4b13-91b2-94944d4c42d8",
211             "invariantUuid": "dfc2c44c-2429-44ca-ae26-1e6dc1f207fb",
212             "serviceType": "BONDING",
213             "serviceRole": "INFRASTRUCTURE-VPN",
214             "vidNotions": {"instantiationUI": "macroService", "modelCategory": "other", "viewEditUI": "legacy"},
215             "isEcompGeneratedNaming": true,
216             "isMultiStepDesign": false
217           }
218         },
219         "type": "UPDATE_CATEGORY_PARAMETERS",
220         "categoryParameters": {
221           "owningEntityList": [{
222             "id": "d61e6f2d-12fa-4cc2-91df-7c244011d6fc",
223             "name": "WayneHolland"
224           }, {"id": "Melissa", "name": "Melissa"}, {"id": "aaa1", "name": "aaa1"}],
225           "projectList": [{"id": "WATKINS", "name": "WATKINS"}, {"id": "x1", "name": "x1"}, {"id": "yyy1", "name": "yyy1"}],
226           "lineOfBusinessList": [{"id": "ONAP", "name": "ONAP"}, {"id": "zzz1", "name": "zzz1"}],
227           "platformList": [{"id": "platform", "name": "platform"}, {"id": "xxx1", "name": "xxx1"}]
228         }
229       }
230     });
231     const networkStep = service.getNetworkStep(
232       "f028b2e2-7080-4b13-91b2-94944d4c42d8",
233       <any>{
234         data: {
235           children: [],
236           componentInfoType: "VRF",
237           count: 0,
238           disabled: false,
239           id: "dd024d73-9bd1-425d-9db5-476338d53433",
240           isEcompGeneratedNaming: false,
241           max: 1,
242           modelCustomizationId: "dd024d73-9bd1-425d-9db5-476338d53433",
243           modelUniqueId: "dd024d73-9bd1-425d-9db5-476338d53433",
244           modelVersionId: "9cac02be-2489-4374-888d-2863b4511a59",
245           name: "VRF Entry Configuration 0",
246           tooltip: "VRF",
247           type: "VRF",
248           typeName: "VRF"
249         }
250       });
251
252
253     expect(networkStep.type).toEqual('Network');
254     expect(networkStep.title).toEqual('Associate network to VRF Entry');
255     expect(networkStep.description).toEqual('Select a network to associate to the VRF Entry');
256     expect(networkStep.noElementsMsg).toEqual('No network were found.');
257     expect(networkStep.maxSelectRow).toEqual(1);
258     expect(networkStep.uniqObjectField).toEqual('instanceId');
259     expect(networkStep.topButton.text).toEqual('Next');
260     expect(networkStep.criteria).toHaveLength(1);
261
262   });
263
264   test('getsNetworkStepSearchFields', () => {
265     const networkStepSearchFields = service.getsNetworkStepSearchFields({
266       "lcpCloudRegionId": "lcpCloudRegionId",
267       "tenantName": "tenantName"
268     });
269
270     expect(networkStepSearchFields[0].value).toEqual("lcpCloudRegionId");
271     expect(networkStepSearchFields[1].value).toEqual("tenantName");
272     expect(networkStepSearchFields[2].value).toEqual("Active");
273     expect(networkStepSearchFields[3].value).toEqual("VPN binding");
274   });
275
276   test('generateRolesOptions should sort networks roles, check if should add "Not assigned" option', () => {
277     const networks = [
278       {"role": "2"},
279       {"role": "3"},
280       {"role": "4"},
281       {"role": "1"},
282       {"role": "6"}
283     ];
284
285     spyOn(store, 'dispatch');
286
287     service.generateRolesOptions(networks);
288     expect(store.dispatch).toHaveBeenCalledWith(updateGenericModalCriteria("roles", ["-- select an option --", "1", "2", "3", "4", "6"]))
289
290     networks.push({"role": null});
291     service.generateRolesOptions(networks);
292     expect(store.dispatch).toHaveBeenCalledWith(updateGenericModalCriteria("roles", ["-- select an option --", "Not assigned", "1", "2", "3", "4", "6"]))
293   });
294
295   test('shouldAddNotAssigned- check if "Not Assigned" option to roles', () => {
296     const networks = [
297       {"role": "5"},
298       {"role": "3"},
299       {"role": "4"},
300       {"role": "1"},
301       {"role": "6"}
302     ];
303
304     let result: boolean = service.shouldAddNotAssigned(networks);
305     expect(result).toBeFalsy();
306
307     networks.push({"role": null});
308
309     result = service.shouldAddNotAssigned(networks);
310     expect(result).toBeTruthy();
311   });
312
313
314   test('getNetworkStepHeaders should return the correct headers for network popup', () => {
315     let headers = service.getNetworkStepHeaders();
316
317     expect(headers[0].displayName).toEqual('Name');
318     expect(headers[0].key).toEqual(['instanceName']);
319
320     expect(headers[1].displayName).toEqual('Type');
321     expect(headers[1].key).toEqual(['instanceType']);
322
323     expect(headers[2].displayName).toEqual('Role');
324     expect(headers[2].key).toEqual(['role']);
325
326     expect(headers[3].displayName).toEqual('Orch. Status');
327     expect(headers[3].key).toEqual(['orchStatus']);
328
329     expect(headers[4].displayName).toEqual('Physical name');
330     expect(headers[4].key).toEqual(['physicalName']);
331
332     expect(headers[5].displayName).toEqual('Instance ID');
333     expect(headers[5].key).toEqual(['instanceId']);
334
335     expect(headers[6].displayName).toEqual('Model UUID');
336     expect(headers[6].key).toEqual(['modelInfo', 'modelVersionId']);
337
338     expect(headers[7].displayName).toEqual('Service name');
339     expect(headers[7].key).toEqual(['serviceName']);
340
341     expect(headers[8].displayName).toEqual('Service UUID');
342     expect(headers[8].key).toEqual(['serviceUUID']);
343
344     expect(headers[9].displayName).toEqual('Tenant');
345     expect(headers[9].key).toEqual(['tenantName']);
346
347     expect(headers[10].displayName).toEqual('Region');
348     expect(headers[10].key).toEqual(['lcpCloudRegionId']);
349   });
350
351   test('getElementsFirstStep should return sort networks by instance name', () => {
352     let networks = [
353       {"instanceUUID": "B"},
354       {"instanceUUID": "A"},
355       {"instanceUUID": "D"},
356       {"instanceUUID": "C"},
357       {"instanceUUID": "E"}
358     ];
359
360     let sortedNetworkByInstanceName = service.sortElementsResultByField(networks, "instanceUUID");
361     expect(sortedNetworkByInstanceName).toEqual([
362       {"instanceUUID": "A"},
363       {"instanceUUID": "B"},
364       {"instanceUUID": "C"},
365       {"instanceUUID": "D"},
366       {"instanceUUID": "E"}
367     ])
368   });
369
370
371   test('getNetworkTableContent', () => {
372     let tableContent: ITableContent[] = service.getNetworkTableContent();
373     expect(tableContent).toEqual(
374     [
375       {
376         id: 'instanceName',
377         contents: [{
378           id: ['name'],
379           value: ["instanceName"]
380         }]
381       },
382       {
383         id: 'instanceType',
384         contents: [{
385           id: ['type'],
386           value: ['instanceType']
387         }]
388       },
389       {
390         id: 'role',
391         contents: [{
392           id: ['role'],
393           value: ['role']
394         }]
395       },
396       {
397         id: 'network-orch-status',
398         contents: [{
399           id: ['orchStatus'],
400           value: ['orchStatus']
401         }]
402       },
403       {
404         id: 'network-physical-name',
405         contents: [{
406           id: ['physicalName'],
407           value: ['physicalName']
408         }]
409       },
410       {
411         id: 'network-instance-id',
412         contents: [{
413           id: ['instanceID'],
414           value: ['instanceId']
415         }]
416       },
417       {
418         id: 'network-model-uuid',
419         contents: [{
420           id: ['modelUUID'],
421           value: ['modelInfo', 'modelVersionId']
422         }]
423       },
424       {
425         id: 'network-serviceName',
426         contents: [{
427           id: ['serviceName'],
428           value: ['serviceName']
429         }]
430       },
431       {
432         id: 'network-service-id',
433         contents: [{
434           id: ['serviceUUID'],
435           value: ['serviceUUID']
436         }]
437       },
438       {
439         id: 'network-tenantName',
440         contents: [{
441           id: ['tenant'],
442           value: ['tenantName']
443         }]
444       },
445       {
446         id: 'network-region',
447         contents: [{
448           id: ['region'],
449           value: ['lcpCloudRegionId']
450         }]
451       }
452     ]);
453   });
454 });