Relax VNF Change Management filters for VNFs
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / modals / new-change-management / new-change-management.controller.test.js
index 9810c00..224289f 100644 (file)
@@ -3,6 +3,7 @@
  * VID
  * ================================================================================
  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -33,6 +34,8 @@ describe('Testing workFlows from SO', () => {
 
   beforeEach(inject(function (_$controller_) {
     $notNeeded = jestMock.fn();
+    let lodash = require('lodash')
+
     // mock ChangeManagementService
     $changeManagementService = jestMock.fn();
     $changeManagementService.getAllSDCServices = jestMock.fn(() => Promise.resolve([]));
@@ -58,7 +61,7 @@ describe('Testing workFlows from SO', () => {
       changeManagementService: $changeManagementService,
       Upload: $notNeeded,
       $log: $notNeeded,
-      _: $notNeeded,
+      _: lodash,
       COMPONENT: $flags,
       VIDCONFIGURATION: $notNeeded,
       DataService: $notNeeded,
@@ -92,7 +95,7 @@ describe('Testing workFlows from SO', () => {
             "id": 1,
             "name": "Configuration Parameters",
             "required": true,
-            "type": "STRING",
+            "type": "text",
             "pattern": ".*",
             "msgOnPatternError": null,
             "msgOnContentError": null,
@@ -100,32 +103,59 @@ describe('Testing workFlows from SO', () => {
           }
         ],
       }});
-    let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 1"}, {"id": "2", "name": "workflow 2"}]});
-    let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": []}});
+    let getSOWorkflowsPromiseStub = Promise.resolve({"data":[{
 
-    $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
+        "id": "ab6478e4-ea33-3346-ac12-ab121484a333",
+        "workflowName": "inPlaceSoftwareUpdate",
+        "name": "inPlaceSoftwareUpdate",
+        "source": "sdc",
+        "workflowInputParameters": [
+            {
+                "label": "New Software Version",
+                "inputType": "text",
+                "required": true,
+                "soFieldName": "new_software_version",
+                "soPayloadLocation": "userParams",
+                "validation":[]
+            }
+        ]
+    }]
+    });
+
+    $controller.changeManagement.vnfNames = [{modelVersionId: 'test1', name:'test'}];
     $changeManagementService.getWorkflows = () => getWorkflowsStub;
     $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
     $changeManagementService.getSOWorkflows = () =>  getSOWorkflowsPromiseStub;
-    $changeManagementService.getSOWorkflowParameter = () =>  getSOWorkflowsParametersPromiseStub;
     // when
     return $controller.loadWorkFlows().then(() => {
-      expect($controller.workflows).toContain('workflow 1');
-      expect($controller.workflows).toContain('workflow 2');
+      expect($controller.workflows).toContain('inPlaceSoftwareUpdate');
+      expect($controller.localWorkflowsParameters).toEqual(new Map());
     });
   });
 
-  test('Verify load workflows will call load workflows parameters from SO', () => {
+  test('Verify load workflows will set workflows and parameters', () => {
     // given
     let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
     let getLocalWorkflowsParametersStub = Promise.resolve({"data": {}});
-    let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 0"}]});
-    let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": [
-          {"id": 1, "name": "parameter 1", "required": true, "type": "STRING", "pattern": "[0-9]*"},
-          {"id": 2, "name": "parameter 2", "required": true, "type": "STRING", "pattern": ".*"},
-          {"id": 3, "name": "parameter 3", "required": false, "type": "STRING", "pattern": "[0-9]*"}]}});
+    let getSOWorkflowsPromiseStub = Promise.resolve({"data":[{
 
-    $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
+            "id": "ab6478e4-ea33-3346-ac12-ab121484a333",
+            "workflowName": "inPlaceSoftwareUpdate",
+            "name": "inPlaceSoftwareUpdate",
+            "source": "sdc",
+          "workflowInputParameters": [
+            {
+              "label": "New Software Version",
+              "inputType": "text",
+              "required": true,
+              "soFieldName": "new_software_version",
+              "soPayloadLocation": "userParams",
+                "validation":[]
+            }
+          ]
+        }]
+      });
+    $controller.changeManagement.vnfNames = [{modelVersionId: 'test1', name:'test'}];
     $changeManagementService.getWorkflows = () => getWorkflowsStub;
     $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
     $changeManagementService.getSOWorkflows = () =>  getSOWorkflowsPromiseStub;
@@ -133,10 +163,18 @@ describe('Testing workFlows from SO', () => {
     // when
     return $controller.loadWorkFlows()
     .then(() => {
-      expect($controller.remoteWorkflowsParameters).toEqual(new Map([["workflow 0",
-        [{"id": 1, "name": "parameter 1", "pattern": "[0-9]*", "required": true, "type": "STRING"},
-         {"id": 2, "name": "parameter 2", "pattern": ".*", "required": true, "type": "STRING"},
-         {"id": 3, "name": "parameter 3", "pattern": "[0-9]*", "required": false, "type": "STRING"}]]]));
+      expect($controller.workflows).toEqual(["inPlaceSoftwareUpdate"]);
+      expect($controller.remoteWorkflowsParameters).toEqual(new Map([["inPlaceSoftwareUpdate",
+        [{
+          "name": "New Software Version",
+          "required": true,
+          "id": "new_software_version",
+          "soFieldName": "new_software_version",
+          "maxLength": '500',
+          "pattern": '.*',
+          "type": "text"
+        }]]
+      ]));
     });
   });
 
@@ -147,9 +185,9 @@ describe('Testing workFlows from SO', () => {
     let getLocalWorkflowsParametersStub = Promise.resolve({"data": {}});
     let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 0"}]});
     let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": [
-          {"id": 1, "name": "parameter 1", "required": true, "type": "STRING", "pattern": "[0-9]*"},
-          {"id": 2, "name": "parameter 2", "required": true, "type": "STRING", "pattern": ".*"},
-          {"id": 3, "name": "parameter 3", "required": false, "type": "STRING", "pattern": "[0-9]*"}]}});
+          {"id": 1, "name": "parameter 1", "required": true, "type": "text", "pattern": "[0-9]*"},
+          {"id": 2, "name": "parameter 2", "required": true, "type": "text", "pattern": ".*"},
+          {"id": 3, "name": "parameter 3", "required": false, "type": "text", "pattern": "[0-9]*"}]}});
 
     $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
     $changeManagementService.getWorkflows = () => getWorkflowsStub;
@@ -160,7 +198,7 @@ describe('Testing workFlows from SO', () => {
     return $controller.loadWorkFlows()
     .then(() => {
       expect($controller.workflows).toEqual(["workflow 0"]);
-      expect($controller.remoteWorkflowsParameters).toEqual(undefined);
+      expect($controller.remoteWorkflowsParameters).toEqual(new Map());
     });
   });
 
@@ -174,7 +212,7 @@ describe('Testing workFlows from SO', () => {
             "id": 1,
             "name": "Configuration Parameters",
             "required": true,
-            "type": "STRING",
+            "type": "text",
             "pattern": ".*",
             "msgOnPatternError": null,
             "msgOnContentError": null,
@@ -189,9 +227,7 @@ describe('Testing workFlows from SO', () => {
     // when
 
     let result = new Map();
-    const scaleOutResult = new Map();
-    scaleOutResult.set("FILE", []);
-    scaleOutResult.set("STRING", [
+    const scaleOutResult = [
       {
         "acceptableFileType": null,
         "id": 1,
@@ -200,9 +236,9 @@ describe('Testing workFlows from SO', () => {
         "name": "Configuration Parameters",
         "pattern": ".*",
         "required": true,
-        "type": "STRING",
+        "type": "text",
       }
-    ]);
+    ];
     result.set("VNF Scale Out", scaleOutResult);
 
     return $controller.loadWorkFlows()
@@ -234,7 +270,7 @@ describe('Testing workFlows from SO', () => {
             "id": 1,
             "name": "Configuration Parameters",
             "required": true,
-            "type": "STRING",
+            "type": "text",
             "pattern": ".*",
             "msgOnPatternError": null,
             "msgOnContentError": null,
@@ -249,7 +285,7 @@ describe('Testing workFlows from SO', () => {
     // when
     return $controller.loadWorkFlows()
     .then(() => {
-      let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("NON-EXISTENT WF", "STRING");
+      let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("NON-EXISTENT WF", "text");
       expect(internalWorkFlowParameters).toEqual([]);
     });
   });
@@ -264,7 +300,7 @@ describe('Testing workFlows from SO', () => {
             "id": 1,
             "name": "Configuration Parameters",
             "required": true,
-            "type": "STRING",
+            "type": "text",
             "pattern": ".*",
             "msgOnPatternError": null,
             "msgOnContentError": null,
@@ -284,6 +320,23 @@ describe('Testing workFlows from SO', () => {
     });
   });
 
+  test('Verify get internal workflow parameters should return an empty list if type exist but mapped to undefined', () => {
+    // given
+    $featureFlags.isOn = jestMock.fn(() => false);
+    let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}});
+    let getLocalWorkflowsParametersStub = Promise.resolve({"data": undefined});
+
+    $controller.changeManagement.vnfNames = [{name: 'test1'}];
+    $changeManagementService.getWorkflows = () => getWorkflowsStub;
+    $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
+    // when
+    return $controller.loadWorkFlows()
+    .then(() => {
+      let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("VNF Scale Out", "FILE");
+      expect(internalWorkFlowParameters).toEqual([]);
+    });
+  });
+
   test('Verify get internal workflow parameters should return a list if such workflow and type exist', () => {
     // given
     $featureFlags.isOn = jestMock.fn(() => false);
@@ -294,7 +347,7 @@ describe('Testing workFlows from SO', () => {
             "id": 1,
             "name": "Configuration Parameters",
             "required": true,
-            "type": "STRING",
+            "type": "text",
             "pattern": ".*",
             "msgOnPatternError": null,
             "msgOnContentError": null,
@@ -314,13 +367,152 @@ describe('Testing workFlows from SO', () => {
         "name": "Configuration Parameters",
         "pattern": ".*",
         "required": true,
-        "type": "STRING",
+        "type": "text",
         }];
     // when
     return $controller.loadWorkFlows()
     .then(() => {
-      let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("VNF Scale Out", "STRING");
+      let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("VNF Scale Out", "text");
       expect(internalWorkFlowParameters).toEqual(result);
     });
   });
+
+  test('Verify get remote workflow should call internal service for params when workflow is native', () =>{
+      let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
+      let getLocalWorkflowsParametersStub = Promise.resolve({"data":{
+              "parameterDefinitions": [
+                  {
+                      "id": 1,
+                      "name": "Configuration Parameters",
+                      "required": true,
+                      "type": "text",
+                      "pattern": ".*",
+                      "msgOnPatternError": null,
+                      "msgOnContentError": null,
+                      "acceptableFileType": null
+                  }
+              ],
+          }});
+      let getSOWorkflowsPromiseStub = Promise.resolve({"data":[{
+
+        "id": "ab6478e4-ea33-3346-ac12-ab121484a333",
+        "workflowName": "inPlaceSoftwareUpdate",
+        "name": "inPlaceSoftwareUpdate",
+        "source": "native",
+        "workflowInputParameters": [
+        ]
+    }]
+  });
+
+  $controller.changeManagement.vnfNames = [{modelVersionId: 'test1', name:'test'}];
+  $changeManagementService.getWorkflows = () => getWorkflowsStub;
+  $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
+  $changeManagementService.getSOWorkflows = () =>  getSOWorkflowsPromiseStub;
+
+  return $controller.loadWorkFlows().then(() => {
+    expect($controller.workflows).toContain('inPlaceSoftwareUpdate');
+    expect($controller.localWorkflowsParameters.get('inPlaceSoftwareUpdate')).toEqual([{
+        "id": 1,
+        "name": "Configuration Parameters",
+        "required": true,
+        "type": "text",
+        "pattern": ".*",
+        "msgOnPatternError": null,
+        "msgOnContentError": null,
+        "acceptableFileType": null
+    }]);
+  });
+});
+
+    test('Verify that vm.searchVNFs return only generic-vnfs with relation to vserver', () => {
+        // given
+        $controller.changeManagement.serviceType = [];
+        let getVnfsByCustomerIdAndServiceType = Promise.resolve({"data":
+                { "results" : [
+                        { "id": "1",
+                            "node-type": "generic-vnf",
+                            "properties": {
+                                "nf-role": "vLB"
+                            },
+                            "related-to": [
+                                { "id": "11",
+                                    "node-type": "vf-module"
+                                },
+                                { "id": "12",
+                                    "node-type": "tenant"
+                                }
+                            ]
+                        },
+                        { "id": "2",
+                            "node-type": "generic-vnf",
+                            "properties": {
+                                "nf-role": "vLB"
+                            },
+                            "related-to": [
+                                { "id": "21",
+                                    "node-type": "tenant"
+                                }
+                            ]
+                        },
+                        { "id": "3",
+                            "node-type": "generic-vnf",
+                            "properties": {
+                                "nf-role": "vLB"
+                            },
+                            "related-to": [
+                                { "id": "31",
+                                    "node-type": "vf-module"
+                                },
+                                { "id": "32",
+                                    "node-type": "tenant"
+                                },
+                                { "id": "33",
+                                    "node-type": "vserver"
+                                }
+                            ]
+                        },
+                        { "id": "11",
+                            "node-type": "vf-module",
+                            "related-to": [
+                                { "id": "111",
+                                    "node-type": "vserver"
+                                }
+                            ]
+                        },
+                        { "id": "31",
+                            "node-type": "vf-module",
+                            "related-to": [
+                                { "id": "311",
+                                    "node-type": "vserver"
+                                }
+                            ]
+                        }
+                    ]
+                }
+        });
+        let expectedVnfs = [
+            {
+                "id": "1",
+                "node-type": "generic-vnf",
+                "properties": {"nf-role": "vLB"},
+                "related-to": [
+                    {"id": "11", "node-type": "vf-module"},
+                    {"id": "12", "node-type": "tenant"}]},
+            {
+                "id": "3",
+                "node-type": "generic-vnf",
+                "properties": {"nf-role": "vLB"},
+                "related-to": [
+                    {"id": "31", "node-type": "vf-module"},
+                    {"id": "32", "node-type": "tenant"},
+                    {"id": "33", "node-type": "vserver"}
+                ]}];
+        $aaiService.getVnfsByCustomerIdAndServiceType = () => getVnfsByCustomerIdAndServiceType;
+
+        // when
+        $controller.searchVNFs().then(() => {
+            expect($controller.vnfs).toHaveLength(2);
+            expect($controller.vnfs).toEqual(expectedVnfs);
+        });
+    });
 });