Add Semicolon at the end
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / modals / new-change-management / new-change-management.controller.test.js
index 5f36691..675c1b7 100644 (file)
@@ -25,12 +25,15 @@ describe('Testing workFlows from SO', () => {
   let $notNeeded;
   let $controller;
   let $changeManagementService;
+  let $featureFlags;
+
   beforeEach(
       angular.mock.module('app')
   );
 
   beforeEach(inject(function (_$controller_) {
     $notNeeded = jestMock.fn();
+
     // mock ChangeManagementService
     $changeManagementService = jestMock.fn();
     $changeManagementService.getAllSDCServices = jestMock.fn(() => Promise.resolve([]));
@@ -38,6 +41,10 @@ describe('Testing workFlows from SO', () => {
     // mock q
     $q = jestMock.fn();
     $defer = jestMock.fn();
+    $flags = jestMock.fn();
+    $flags.FEATURE_FLAGS = {FLAG_HANDLE_SO_WORKFLOWS: ''};
+    $featureFlags = jestMock.fn();
+    $featureFlags.isOn = jestMock.fn(() => true);
     $q.defer = jestMock.fn(() => $defer);
     $defer.promise = Promise.resolve({});
     // mock AaiService
@@ -53,10 +60,10 @@ describe('Testing workFlows from SO', () => {
       Upload: $notNeeded,
       $log: $notNeeded,
       _: $notNeeded,
-      COMPONENT: $notNeeded,
+      COMPONENT: $flags,
       VIDCONFIGURATION: $notNeeded,
       DataService: $notNeeded,
-      featureFlags: $notNeeded,
+      featureFlags: $featureFlags,
       $scope: $notNeeded,
     });
   }));
@@ -77,35 +84,108 @@ describe('Testing workFlows from SO', () => {
      );
   });
 
-  test('Verify load workflows will call load from SO and join workflow lists', () => {
+  test('Verify load workflows wont load parameters from local service', () => {
+    // given
+    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": "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;
+    // when
+    return $controller.loadWorkFlows().then(() => {
+      expect($controller.workflows).toContain('inPlaceSoftwareUpdate');
+      expect($controller.localWorkflowsParameters).toEqual(new Map());
+    });
+  });
+
+  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 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 0');
-      expect($controller.workflows).toContain('workflow 1');
-      expect($controller.workflows).toContain('workflow 2');
+    return $controller.loadWorkFlows()
+    .then(() => {
+      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"
+        }]]
+      ]));
     });
   });
 
-  test('Verify load workflows will call load workflows parameters from SO', () => {
+  test('Verify load workflows wont load workflows parameters from SO if feature flag is disabled', () => {
     // given
+    $featureFlags.isOn = jestMock.fn(() => false);
     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]*"}]}});
+          {"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;
@@ -115,15 +195,14 @@ 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(["workflow 0"]);
+      expect($controller.remoteWorkflowsParameters).toEqual(new Map());
     });
   });
 
   test('Verify load workflows will call load workflows parameters from local service', () => {
     // given
+    $featureFlags.isOn = jestMock.fn(() => false);
     let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}});
     let getLocalWorkflowsParametersStub = Promise.resolve({"data":{
         "parameterDefinitions": [
@@ -131,7 +210,7 @@ describe('Testing workFlows from SO', () => {
             "id": 1,
             "name": "Configuration Parameters",
             "required": true,
-            "type": "STRING",
+            "type": "text",
             "pattern": ".*",
             "msgOnPatternError": null,
             "msgOnContentError": null,
@@ -139,20 +218,14 @@ describe('Testing workFlows from SO', () => {
           }
         ],
       }});
-    let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{}]});
-    let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{}});
 
     $controller.changeManagement.vnfNames = [{name: 'test1'}];
     $changeManagementService.getWorkflows = () => getWorkflowsStub;
     $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
-    $changeManagementService.getSOWorkflows = () =>  getSOWorkflowsPromiseStub;
-    $changeManagementService.getSOWorkflowParameter = () =>  getSOWorkflowsParametersPromiseStub;
     // when
 
     let result = new Map();
-    const scaleOutResult = new Map();
-    scaleOutResult.set("FILE", []);
-    scaleOutResult.set("STRING", [
+    const scaleOutResult = [
       {
         "acceptableFileType": null,
         "id": 1,
@@ -161,9 +234,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()
@@ -172,23 +245,22 @@ describe('Testing workFlows from SO', () => {
     });
   });
 
-  test('Verify broken SO workflows wont change content of local workflows', () => {
+  test('Verify broken SO workflows will return empty list of workflows', () => {
     // given
-    let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
     let getSOWorkflowsPromiseStub = Promise.reject(new Error("Broken SO workflows service."));
 
-    $controller.changeManagement.vnfNames = "any";
-    $changeManagementService.getWorkflows = () => getWorkflowsStub;
+    $controller.changeManagement.vnfNames = [{name:"any"}];
     $changeManagementService.getSOWorkflows = () =>  getSOWorkflowsPromiseStub;
     // when
     $controller.loadWorkFlows()
     .then(() => {
-      expect($controller.workflows).toEqual(['workflow 0']);
+      expect($controller.workflows).toEqual([]);
     });
   });
 
   test('Verify get internal workflow parameters should return an empty list if not such workflow exist', () => {
   // given
+    $featureFlags.isOn = jestMock.fn(() => false);
     let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}});
     let getLocalWorkflowsParametersStub = Promise.resolve({"data":{
         "parameterDefinitions": [
@@ -196,7 +268,7 @@ describe('Testing workFlows from SO', () => {
             "id": 1,
             "name": "Configuration Parameters",
             "required": true,
-            "type": "STRING",
+            "type": "text",
             "pattern": ".*",
             "msgOnPatternError": null,
             "msgOnContentError": null,
@@ -204,24 +276,21 @@ describe('Testing workFlows from SO', () => {
           }
         ],
       }});
-    let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{}]});
-    let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{}});
 
     $controller.changeManagement.vnfNames = [{name: 'test1'}];
     $changeManagementService.getWorkflows = () => getWorkflowsStub;
     $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
-    $changeManagementService.getSOWorkflows = () =>  getSOWorkflowsPromiseStub;
-    $changeManagementService.getSOWorkflowParameter = () =>  getSOWorkflowsParametersPromiseStub;
     // when
     return $controller.loadWorkFlows()
     .then(() => {
-      let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("NON-EXISTENT WF", "STRING");
+      let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("NON-EXISTENT WF", "text");
       expect(internalWorkFlowParameters).toEqual([]);
     });
   });
 
   test('Verify get internal workflow parameters should return an empty list if not such type exist', () => {
     // given
+    $featureFlags.isOn = jestMock.fn(() => false);
     let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}});
     let getLocalWorkflowsParametersStub = Promise.resolve({"data":{
         "parameterDefinitions": [
@@ -229,7 +298,7 @@ describe('Testing workFlows from SO', () => {
             "id": 1,
             "name": "Configuration Parameters",
             "required": true,
-            "type": "STRING",
+            "type": "text",
             "pattern": ".*",
             "msgOnPatternError": null,
             "msgOnContentError": null,
@@ -237,14 +306,10 @@ describe('Testing workFlows from SO', () => {
           }
         ],
       }});
-    let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{}]});
-    let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{}});
 
     $controller.changeManagement.vnfNames = [{name: 'test1'}];
     $changeManagementService.getWorkflows = () => getWorkflowsStub;
     $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
-    $changeManagementService.getSOWorkflows = () =>  getSOWorkflowsPromiseStub;
-    $changeManagementService.getSOWorkflowParameter = () =>  getSOWorkflowsParametersPromiseStub;
     // when
     return $controller.loadWorkFlows()
     .then(() => {
@@ -255,6 +320,7 @@ describe('Testing workFlows from SO', () => {
 
   test('Verify get internal workflow parameters should return a list if such workflow and type exist', () => {
     // given
+    $featureFlags.isOn = jestMock.fn(() => false);
     let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}});
     let getLocalWorkflowsParametersStub = Promise.resolve({"data":{
         "parameterDefinitions": [
@@ -262,7 +328,7 @@ describe('Testing workFlows from SO', () => {
             "id": 1,
             "name": "Configuration Parameters",
             "required": true,
-            "type": "STRING",
+            "type": "text",
             "pattern": ".*",
             "msgOnPatternError": null,
             "msgOnContentError": null,
@@ -270,14 +336,9 @@ describe('Testing workFlows from SO', () => {
           }
         ],
       }});
-    let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{}]});
-    let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{}});
-
     $controller.changeManagement.vnfNames = [{name: 'test1'}];
     $changeManagementService.getWorkflows = () => getWorkflowsStub;
     $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub;
-    $changeManagementService.getSOWorkflows = () =>  getSOWorkflowsPromiseStub;
-    $changeManagementService.getSOWorkflowParameter = () =>  getSOWorkflowsParametersPromiseStub;
 
     let result = [{
         "acceptableFileType": null,
@@ -287,13 +348,60 @@ 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
+    }]);
+  });
+});
 });