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