05fc008ad607d4e2b6a37031c7ebb5ac948ec1de
[vid.git] / vid-webpack-master / src / app / shared / storeUtil / utils / service / service.reducers.spec.ts
1 import {ServiceInstance} from "../../../models/serviceInstance";
2 import {
3   AddServiceAction, ChangeServiceDirty,
4   DeleteServiceInstanceAction,
5   ServiceActions,
6   CreateServiceInstanceAction,
7   UpdateServiceModelAction, UpdateServiceInstanceAction
8 } from "./service.actions";
9 import {serviceReducer} from "./service.reducers";
10 import {ServiceInstanceActions} from "../../../models/serviceInstanceActions";
11
12 describe('serviceReducer', () => {
13
14   test('#UPDATE_SERVICE_INSTANCE should update exiting instance without change his child', () => {
15     const serviceUuid: string = 'serviceUuid';
16     const actionName: ServiceInstanceActions = ServiceInstanceActions.Create;
17
18     const elemntThatShouldNotOverideOnUpdateService = {
19       vnfs: {
20         "2017-388_ADIOD-vPE 0": {
21           "action": "Create",
22           "inMaint": false,
23           "rollbackOnFailure": "true",
24           "originalName": "2017-388_ADIOD-vPE 0",
25           "isMissingData": false,
26           "trackById": "eymgwlevh54",
27           "vfModules": {},
28           "vnfStoreKey": "2017-388_ADIOD-vPE 0",
29           "uuid": "afacccf6-397d-45d6-b5ae-94c39734b168",
30           "productFamilyId": "e433710f-9217-458d-a79d-1c7aff376d89",
31           "lcpCloudRegionId": "JANET25",
32           "tenantId": "092eb9e8e4b7412e8787dd091bc58e86",
33           "lineOfBusiness": "ONAP",
34           "platformName": "platform",
35           "modelInfo": {
36             "modelInvariantId": "72e465fe-71b1-4e7b-b5ed-9496118ff7a8",
37             "modelVersionId": "afacccf6-397d-45d6-b5ae-94c39734b168",
38             "modelName": "2017-388_ADIOD-vPE",
39             "modelVersion": "4.0",
40             "modelCustomizationId": "b3c76f73-eeb5-4fb6-9d31-72a889f1811c",
41             "modelCustomizationName": "2017-388_ADIOD-vPE 0",
42             "uuid": "afacccf6-397d-45d6-b5ae-94c39734b168",
43             "modelUniqueId": "b3c76f73-eeb5-4fb6-9d31-72a889f1811c"
44           },
45           "instanceName": "2017-388_ADIOD-vPEAjXzainstanceName",
46           "legacyRegion": "some legacy region",
47           "instanceParams": [
48             {
49               "vnf_config_template_version": "17.2",
50               "bandwidth_units": "Gbps",
51               "bandwidth": "10",
52               "AIC_CLLI": "ATLMY8GA",
53               "ASN": "AV_vPE",
54               "vnf_instance_name": "mtnj309me6"
55             }
56           ]
57         },
58         "2017-488_ADIOD-vPE 0": {
59           "action": "Create",
60           "inMaint": false,
61           "rollbackOnFailure": "true",
62           "originalName": "2017-488_ADIOD-vPE 0",
63           "isMissingData": false,
64           "trackById": "xr6o2782z7",
65           "vfModules": {
66             "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_base_vPE_BV..module-0": {
67               "2017488_adiodvpe0..2017488AdiodVpe..ADIOD_base_vPE_BV..module-0wmkjw": {
68                 "isMissingData": true,
69                 "sdncPreReload": null,
70                 "modelInfo": {
71                   "modelType": "VFmodule",
72                   "modelInvariantId": "b34833bb-6aa9-4ad6-a831-70b06367a091",
73                   "modelVersionId": "f8360508-3f17-4414-a2ed-6bc71161e8db",
74                   "modelName": "2017488AdiodVpe..ADIOD_base_vPE_BV..module-0",
75                   "modelVersion": "5",
76                   "modelCustomizationId": "a55961b2-2065-4ab0-a5b7-2fcee1c227e3",
77                   "modelCustomizationName": "2017488AdiodVpe..ADIOD_base_vPE_BV..module-0",
78                   "modelUniqueId": "a55961b2-2065-4ab0-a5b7-2fcee1c227e3"
79                 },
80                 "instanceParams": [
81                   {}
82                 ],
83                 "trackById": "a19sjb1ez2"
84               }
85             }
86           },
87           "vnfStoreKey": "2017-488_ADIOD-vPE 0",
88           "uuid": "69e09f68-8b63-4cc9-b9ff-860960b5db09",
89           "productFamilyId": "e433710f-9217-458d-a79d-1c7aff376d89",
90           "lcpCloudRegionId": "JANET25",
91           "tenantId": "092eb9e8e4b7412e8787dd091bc58e86",
92           "lineOfBusiness": "ONAP",
93           "platformName": "platform",
94           "modelInfo": {
95             "modelInvariantId": "72e465fe-71b1-4e7b-b5ed-9496118ff7a8",
96             "modelVersionId": "69e09f68-8b63-4cc9-b9ff-860960b5db09",
97             "modelName": "2017-488_ADIOD-vPE",
98             "modelVersion": "5.0",
99             "modelCustomizationId": "1da7b585-5e61-4993-b95e-8e6606c81e45",
100             "modelCustomizationName": "2017-488_ADIOD-vPE 0",
101             "uuid": "69e09f68-8b63-4cc9-b9ff-860960b5db09",
102             "modelUniqueId": "1da7b585-5e61-4993-b95e-8e6606c81e45"
103           },
104           "instanceName": "2017-488_ADIOD-vPEVNFinstancename",
105           "legacyRegion": "some legacy region",
106           "instanceParams": [
107             {
108               "vnf_config_template_version": "17.2",
109               "bandwidth_units": "Gbps",
110               "bandwidth": "10",
111               "AIC_CLLI": "ATLMY8GA",
112               "ASN": "AV_vPE",
113               "vnf_instance_name": "mtnj309me6"
114             }
115           ]
116         }
117       },
118       existingVNFCounterMap: {
119         "b3c76f73-eeb5-4fb6-9d31-72a889f1811c": 1,
120         "1da7b585-5e61-4993-b95e-8e6606c81e45": 1
121       },
122       existingVnfGroupCounterMap: {},
123       existingNetworksCounterMap: {},
124       optionalGroupMembersMap : {},
125       networks : {},
126       vnfGroups : {}
127     };
128
129
130     let service = serviceReducer(<any>{
131       "serviceInstance": {
132         "6b528779-44a3-4472-bdff-9cd15ec93450": {
133           "action": "Create",
134           "isDirty": true,
135           "vnfs": elemntThatShouldNotOverideOnUpdateService.vnfs,
136           "instanceParams": [
137             {
138               "2017488_adiodvpe0_ASN": "AV_vPE"
139             }
140           ],
141           "validationCounter": 1,
142           "existingNames": {
143             "ajxzainstancename": "",
144             "2017-488_adiod-vpevnfinstancename": "",
145             "2017-388_adiod-vpeajxzainstancename": ""
146           },
147           "existingVNFCounterMap": elemntThatShouldNotOverideOnUpdateService.existingVNFCounterMap,
148           "existingVnfGroupCounterMap": elemntThatShouldNotOverideOnUpdateService.existingVnfGroupCounterMap,
149           "existingNetworksCounterMap": elemntThatShouldNotOverideOnUpdateService.existingNetworksCounterMap,
150           "optionalGroupMembersMap":elemntThatShouldNotOverideOnUpdateService.optionalGroupMembersMap,
151           "networks": elemntThatShouldNotOverideOnUpdateService.networks,
152           "vnfGroups": elemntThatShouldNotOverideOnUpdateService.vnfGroups,
153           "bulkSize": "3",
154           "instanceName": "AjXzainstancename",
155           "globalSubscriberId": "e433710f-9217-458d-a79d-1c7aff376d89",
156           "subscriptionServiceType": "TYLER SILVIA",
157           "owningEntityId": "d61e6f2d-12fa-4cc2-91df-7c244011d6fc",
158           "productFamilyId": "e433710f-9217-458d-a79d-1c7aff376d89",
159           "lcpCloudRegionId": "hvf6",
160           "tenantId": "bae71557c5bb4d5aac6743a4e5f1d054",
161           "aicZoneId": "NFT1",
162           "projectName": "WATKINS",
163           "rollbackOnFailure": "true",
164           "aicZoneName": "NFTJSSSS-NFT1",
165           "owningEntityName": "WayneHolland",
166           "testApi": "VNF_API",
167           "tenantName": "AIN Web Tool-15-D-testalexandria",
168           "modelInfo": {
169             "modelInvariantId": "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
170             "modelVersionId": "6b528779-44a3-4472-bdff-9cd15ec93450",
171             "modelName": "action-data",
172             "modelVersion": "1.0",
173             "uuid": "6b528779-44a3-4472-bdff-9cd15ec93450",
174             "modelUniqueId": "6b528779-44a3-4472-bdff-9cd15ec93450"
175           },
176           "isALaCarte": false,
177           "name": "action-data",
178           "version": "1.0",
179           "description": "",
180           "category": "",
181           "uuid": "6b528779-44a3-4472-bdff-9cd15ec93450",
182           "invariantUuid": "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
183           "serviceType": "",
184           "serviceRole": "",
185           "vidNotions": {
186             "instantiationUI": "legacy",
187             "modelCategory": "other",
188             "viewEditUI": "legacy"
189           },
190           "isEcompGeneratedNaming": false,
191           "isMultiStepDesign": false
192         }
193       },
194     }, <UpdateServiceInstanceAction>{
195       type: ServiceActions.UPDATE_SERVICE_INSTANCE,
196       serviceUuid: "6b528779-44a3-4472-bdff-9cd15ec93450",
197       serviceInstance: <any>{
198         aicZoneId: "ATL53",
199         aicZoneName: "AAIATLTE-ATL53",
200         bulkSize: 1,
201         category: "",
202         description: "",
203         globalSubscriberId: "e433710f-9217-458d-a79d-1c7aff376d89",
204         instanceName: "yoav",
205         instanceParams: [{}],
206         invariantUuid: "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
207         isALaCarte: false,
208         isEcompGeneratedNaming: false,
209         isMultiStepDesign: false,
210         lcpCloudRegionId: "JANET25",
211         modelInfo: {
212           modelInvariantId: "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
213           modelVersionId: "6b528779-44a3-4472-bdff-9cd15ec93450",
214           modelName: "action-data",
215           modelVersion: "1.0"
216         },
217         name: "action-data",
218         owningEntityId: "d61e6f2d-12fa-4cc2-91df-7c244011d6fc",
219         owningEntityName: "WayneHolland",
220         productFamilyId: "d8a6ed93-251c-47ca-adc9-86671fd19f4c",
221         projectName: "WATKINS",
222         rollbackOnFailure: "true",
223         serviceRole: "",
224         serviceType: "",
225         subscriptionServiceType: "TYLER SILVIA",
226         tenantId: "092eb9e8e4b7412e8787dd091bc58e86",
227         tenantName: "USP-SIP-IC-24335-T-01",
228         testApi: "VNF_API",
229         uuid: "6b528779-44a3-4472-bdff-9cd15ec93450",
230         version: "1.0",
231         vidNotions: {instantiationUI: "legacy", modelCategory: "other", viewEditUI: "legacy"}
232       }
233     });
234     expect(service.serviceInstance["6b528779-44a3-4472-bdff-9cd15ec93450"]).toBeDefined();
235
236     for(const element in elemntThatShouldNotOverideOnUpdateService){
237       expect(service.serviceInstance["6b528779-44a3-4472-bdff-9cd15ec93450"][element]).toEqual(elemntThatShouldNotOverideOnUpdateService[element]);
238     }
239
240     expect(service.serviceInstance["6b528779-44a3-4472-bdff-9cd15ec93450"].aicZoneId).toEqual("ATL53");
241     expect(service.serviceInstance["6b528779-44a3-4472-bdff-9cd15ec93450"].owningEntityId).toEqual("d61e6f2d-12fa-4cc2-91df-7c244011d6fc");
242     expect(service.serviceInstance["6b528779-44a3-4472-bdff-9cd15ec93450"].owningEntityName).toEqual("WayneHolland");
243     expect(service.serviceInstance["6b528779-44a3-4472-bdff-9cd15ec93450"].productFamilyId).toEqual("d8a6ed93-251c-47ca-adc9-86671fd19f4c");
244     expect(service.serviceInstance["6b528779-44a3-4472-bdff-9cd15ec93450"].projectName).toEqual("WATKINS");
245     expect(service.serviceInstance["6b528779-44a3-4472-bdff-9cd15ec93450"].rollbackOnFailure).toEqual("true");
246     expect(service.serviceInstance["6b528779-44a3-4472-bdff-9cd15ec93450"].subscriptionServiceType).toEqual("TYLER SILVIA");
247     expect(service.serviceInstance["6b528779-44a3-4472-bdff-9cd15ec93450"].tenantId).toEqual("092eb9e8e4b7412e8787dd091bc58e86");
248
249   });
250
251   test('#ADD_SERVICE_ACTION should add action to the service', () => {
252     const serviceUuid: string = 'serviceUuid';
253     const actionName: ServiceInstanceActions = ServiceInstanceActions.Create;
254
255     let service = serviceReducer(<any>{
256       serviceInstance: {
257         'serviceUuid': {}
258       }
259     }, <AddServiceAction>{
260       type: ServiceActions.ADD_SERVICE_ACTION,
261       serviceUuid: 'serviceUuid',
262       action: actionName
263     });
264     expect(service.serviceInstance[serviceUuid]['action']).toEqual(actionName);
265   });
266
267   test('#UPDATE_SERVICE_INSTANCE', () => {
268     const serviceUuid: string = 'serviceUuid';
269
270     let serviceInstanceObject: ServiceInstance = <any>{
271       isDirty: false,
272       instanceName: 'instanceName',
273       isEcompGeneratedNaming: false,
274       globalSubscriberId: 'globalSubscriberId',
275       productFamilyId: 'productFamilyId',
276       subscriptionServiceType: 'subscriptionServiceType',
277       lcpCloudRegionId: 'lcpCloudRegionId',
278       tenantId: 'tenantId',
279       tenantName: 'tenantName',
280       aicZoneId: 'aicZoneId',
281       aicZoneName: 'aicZoneName',
282       projectName: 'projectName',
283       owningEntityId: 'owningEntityId',
284       owningEntityName: 'owningEntityName',
285       existingVnfGroupCounterMap: {},
286       existingVNFCounterMap: {},
287       existingNetworksCounterMap: {},
288       pause: false,
289       bulkSize: 1,
290       vnfs: {},
291       vnfGroups: {},
292       networks: {},
293       instanceParams: [],
294       rollbackOnFailure: false,
295       subscriberName: 'subscriberName',
296       validationCounter: 0,
297       existingNames: {},
298       action: ServiceInstanceActions.Create
299     };
300
301     let serviceState = serviceReducer(<any>{serviceInstance: {}},
302       <CreateServiceInstanceAction>{
303         type: ServiceActions.CREATE_SERVICE_INSTANCE,
304         serviceUuid: serviceUuid,
305         serviceInstance: serviceInstanceObject
306       }).serviceInstance[serviceUuid];
307
308     expect(serviceState.instanceName).toEqual(serviceInstanceObject.instanceName);
309     expect(serviceState.isEcompGeneratedNaming).toEqual(serviceInstanceObject.isEcompGeneratedNaming);
310     expect(serviceState.globalSubscriberId).toEqual(serviceInstanceObject.globalSubscriberId);
311     expect(serviceState.productFamilyId).toEqual(serviceInstanceObject.productFamilyId);
312     expect(serviceState.subscriptionServiceType).toEqual(serviceInstanceObject.subscriptionServiceType);
313     expect(serviceState.lcpCloudRegionId).toEqual(serviceInstanceObject.lcpCloudRegionId);
314     expect(serviceState.tenantId).toEqual(serviceInstanceObject.tenantId);
315     expect(serviceState.tenantName).toEqual(serviceInstanceObject.tenantName);
316     expect(serviceState.aicZoneId).toEqual(serviceInstanceObject.aicZoneId);
317     expect(serviceState.aicZoneName).toEqual(serviceInstanceObject.aicZoneName);
318     expect(serviceState.projectName).toEqual(serviceInstanceObject.projectName);
319     expect(serviceState.owningEntityId).toEqual(serviceInstanceObject.owningEntityId);
320     expect(serviceState.owningEntityName).toEqual(serviceInstanceObject.owningEntityName);
321     expect(serviceState.pause).toEqual(serviceInstanceObject.pause);
322     expect(serviceState.bulkSize).toEqual(serviceInstanceObject.bulkSize);
323     expect(serviceState.vnfs).toEqual(serviceInstanceObject.vnfs);
324     expect(serviceState.instanceParams).toEqual(serviceInstanceObject.instanceParams);
325     expect(serviceState.rollbackOnFailure).toEqual(serviceInstanceObject.rollbackOnFailure);
326     expect(serviceState.subscriberName).toEqual(serviceInstanceObject.subscriberName);
327   });
328
329
330   test('#DELETE_ALL_SERVICE_INSTANCES should delete all services', () => {
331     const state = serviceReducer(<any>{
332         serviceInstance: {
333           'service-1': {},
334           'service-2': {}
335         }
336       },
337       <CreateServiceInstanceAction>{
338         type: ServiceActions.DELETE_ALL_SERVICE_INSTANCES
339       });
340
341     expect(state.serviceInstance['service-1']).toBeUndefined();
342     expect(state.serviceInstance['service-2']).toBeUndefined();
343   });
344
345   test('#DELETE_SERVICE_INSTANCE should delete service', () => {
346     const state = serviceReducer(<any>{
347         serviceInstance: {
348           'service-1': {}
349         }
350       },
351       <DeleteServiceInstanceAction>{
352         type: ServiceActions.DELETE_ALL_SERVICE_INSTANCES
353       });
354
355     expect(state.serviceInstance['service-1']).toBeUndefined();
356   });
357
358   test('#UPDATE_MODEL should update service model ', () => {
359     const state = serviceReducer(<any>{
360         serviceHierarchy: {}
361       },
362       <UpdateServiceModelAction>{
363         type: ServiceActions.UPDATE_MODEL,
364         serviceHierarchy: {
365           service: {
366             uuid: 'uuid-1'
367           }
368         }
369       });
370
371     expect(state.serviceHierarchy['uuid-1'].service).toBeDefined();
372   });
373
374   test('#UPDATE_MODEL should update service model with vnfGroups ', () => {
375     const state = serviceReducer(<any>{
376         serviceHierarchy: {}
377       },
378       <UpdateServiceModelAction>{
379         type: ServiceActions.UPDATE_MODEL,
380         serviceHierarchy: {
381           service: {
382             uuid: 'uuid-1'
383           },
384           vnfs: {},
385           vnfGroups: {
386             'vnfGrouop_1': {
387               uuid: 'vnfGroup_uuid_1',
388               name: 'vnfGroup_name_1',
389               type: 'Group'
390             },
391             'vnfGrouop_2': {
392               uuid: 'vnfGroup_uuid_2',
393               name: 'vnfGroup_name_2',
394               type: 'Group'
395             }
396           }
397         }
398       });
399
400     expect(state.serviceHierarchy['uuid-1']).toBeDefined();
401     expect(state.serviceHierarchy['uuid-1'].vnfGroups['vnfGrouop_1']).toBeDefined();
402     expect(state.serviceHierarchy['uuid-1'].vnfGroups['vnfGrouop_2']).toBeDefined();
403   });
404
405   test('#CHANGE_SERVICE_IS_DIRTY should update service isDirty flag : service is not dirty ', () => {
406     const state = serviceReducer(<any>{
407         serviceInstance: {
408           'serviceId': {
409             action: ServiceInstanceActions.None,
410             'vnfs': {
411               'vnf1': {
412                 action: ServiceInstanceActions.None
413               },
414               'vnf2': {
415                 action: ServiceInstanceActions.None
416               }
417             }
418
419           }
420         }
421       },
422       <ChangeServiceDirty>{
423         type: ServiceActions.CHANGE_SERVICE_IS_DIRTY,
424         nodes: [
425           {
426             action: ServiceInstanceActions.None
427           },
428           {
429             action: ServiceInstanceActions.None
430           }],
431         serviceId: 'serviceId'
432
433       });
434
435     expect(state.serviceInstance['serviceId'].isDirty).toBeFalsy();
436   });
437
438   test('#CHANGE_SERVICE_IS_DIRTY should update service isDirty flag : service is dirty should return true', () => {
439     const state = serviceReducer(<any>{
440         serviceInstance: {
441           'serviceId': {
442             action: ServiceInstanceActions.Create
443
444           }
445         }
446       },
447       <ChangeServiceDirty>{
448         type: ServiceActions.CHANGE_SERVICE_IS_DIRTY,
449         nodes: [
450           {
451             action: ServiceInstanceActions.None
452           },
453           {
454             action: ServiceInstanceActions.None
455           }],
456         serviceId: 'serviceId'
457
458       });
459
460     expect(state.serviceInstance['serviceId'].isDirty).toBeTruthy();
461   });
462
463   test('#CHANGE_SERVICE_IS_DIRTY should update service isDirty flag : vnf is dirty ', () => {
464     const state = serviceReducer(<any>{
465         serviceInstance: {
466           'serviceId': {
467             action: ServiceInstanceActions.None,
468             'vnfs': {
469               'vnf1': {
470                 action: ServiceInstanceActions.None
471               },
472               'vnf2': {
473                 action: ServiceInstanceActions.Create
474               }
475             }
476
477           }
478         }
479       },
480       <ChangeServiceDirty>{
481         type: ServiceActions.CHANGE_SERVICE_IS_DIRTY,
482         nodes: [
483           {
484             action: ServiceInstanceActions.None
485           },
486           {
487             action: ServiceInstanceActions.Create
488           }],
489         serviceId: 'serviceId'
490
491       });
492
493     expect(state.serviceInstance['serviceId'].isDirty).toBeTruthy();
494   });
495
496 });
497
498
499