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