aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js
blob: c271b750524850cf40ef121280a0ea77b219d74c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*-
 * ============LICENSE_START=======================================================
 * VID
 * ================================================================================
 * Copyright (C) 2017 - 2019 AT&T 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.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

require('./new-change-management.controller');
const jestMock = require('jest-mock');

describe('Testing workFlows from SO', () => {
  let $notNeeded;
  let $controller;
  let $changeManagementService;
  beforeEach(
      angular.mock.module('app')
  );

  beforeEach(inject(function (_$controller_) {
    $notNeeded = jestMock.fn();
    // mock ChangeManagementService
    $changeManagementService = jestMock.fn();
    $changeManagementService.getAllSDCServices = jestMock.fn(() => Promise.resolve([]));

    // mock q
    $q = jestMock.fn();
    $defer = jestMock.fn();
    $q.defer = jestMock.fn(() => $defer);
    $defer.promise = Promise.resolve({});
    // mock AaiService
    $aaiService = jestMock.fn();
    $aaiService.getLoggedInUserID = jestMock.fn();
    $aaiService.getSubscribers = jestMock.fn();
    $controller = _$controller_('newChangeManagementModalController', {
      $uibModalInstance: $notNeeded,
      $uibModal: $notNeeded,
      $q: $q,
      AaiService: $aaiService,
      changeManagementService: $changeManagementService,
      Upload: $notNeeded,
      $log: $notNeeded,
      _: $notNeeded,
      COMPONENT: $notNeeded,
      VIDCONFIGURATION: $notNeeded,
      DataService: $notNeeded,
      featureFlags: $notNeeded,
      $scope: $notNeeded,
    });
  }));

  test('Verify load workflows from SO will call getSOWorkflow and return only names of workflows', () => {
    // given
    $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
    let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 1"}, {"id": "2", "name": "workflow 2"}]});
    $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
    $controller.workflows = [];
    // when
    return $controller.loadRemoteWorkFlows()
    .then(() => {
           remoteWorkflows = $controller.remoteWorkflows.map(item => item.name);
           expect(remoteWorkflows).toContain('workflow 1');
           expect(remoteWorkflows).toContain('workflow 2');
        }
     );
  });

  test('Verify load workflows will call load from SO and join workflow lists', () => {
    // given
    let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
    let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 1"}, {"id": "2", "name": "workflow 2"}]});
    let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": []}});

    $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
    $changeManagementService.getWorkflows = () => getWorkflowsStub;
    $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');
    });
  });

  test('Verify load workflows will call load workflows parameters from SO', () => {
    // given
    let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
    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]*"}]}});

    $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
    $changeManagementService.getWorkflows = () => getWorkflowsStub;
    $changeManagementService.getSOWorkflows = () =>  getSOWorkflowsPromiseStub;
    $changeManagementService.getSOWorkflowParameter = () =>  getSOWorkflowsParametersPromiseStub;
    // 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"}]]]));
    });
  });

  test('Verify broken SO workflows wont change content of local 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;
    $changeManagementService.getSOWorkflows = () =>  getSOWorkflowsPromiseStub;
    // when
    $controller.loadWorkFlows()
    .then(() => {
      expect($controller.workflows).toEqual(['workflow 0']);
    });
  });
});