2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 require('./new-change-management.controller');
22 const jestMock = require('jest-mock');
24 describe('Testing workFlows from SO', () => {
27 let $changeManagementService;
29 angular.mock.module('app')
32 beforeEach(inject(function (_$controller_) {
33 $notNeeded = jestMock.fn();
34 // mock ChangeManagementService
35 $changeManagementService = jestMock.fn();
36 $changeManagementService.getAllSDCServices = jestMock.fn(() => Promise.resolve([]));
40 $defer = jestMock.fn();
41 $q.defer = jestMock.fn(() => $defer);
42 $defer.promise = Promise.resolve({});
44 $aaiService = jestMock.fn();
45 $aaiService.getLoggedInUserID = jestMock.fn();
46 $aaiService.getSubscribers = jestMock.fn();
47 $controller = _$controller_('newChangeManagementModalController', {
48 $uibModalInstance: $notNeeded,
49 $uibModal: $notNeeded,
51 AaiService: $aaiService,
52 changeManagementService: $changeManagementService,
56 COMPONENT: $notNeeded,
57 VIDCONFIGURATION: $notNeeded,
58 DataService: $notNeeded,
59 featureFlags: $notNeeded,
64 test('Verify load workflows from SO will call getSOWorkflow and return only names of workflows', () => {
66 $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
67 let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 1"}, {"id": "2", "name": "workflow 2"}]});
68 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
69 $controller.workflows = [];
71 return $controller.loadRemoteWorkFlows()
73 remoteWorkflows = $controller.remoteWorkflows.map(item => item.name);
74 expect(remoteWorkflows).toContain('workflow 1');
75 expect(remoteWorkflows).toContain('workflow 2');
80 test('Verify load workflows will call load from SO and join workflow lists', () => {
82 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
83 let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 1"}, {"id": "2", "name": "workflow 2"}]});
84 let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": []}});
86 $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
87 $changeManagementService.getWorkflows = () => getWorkflowsStub;
88 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
89 $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub;
91 return $controller.loadWorkFlows().then(() => {
92 expect($controller.workflows).toContain('workflow 0');
93 expect($controller.workflows).toContain('workflow 1');
94 expect($controller.workflows).toContain('workflow 2');
98 test('Verify load workflows will call load workflows parameters from SO', () => {
100 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
101 let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 0"}]});
102 let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": [
103 {"id": 1, "name": "parameter 1", "required": true, "type": "STRING", "pattern": "[0-9]*"},
104 {"id": 2, "name": "parameter 2", "required": true, "type": "STRING", "pattern": ".*"},
105 {"id": 3, "name": "parameter 3", "required": false, "type": "STRING", "pattern": "[0-9]*"}]}});
107 $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
108 $changeManagementService.getWorkflows = () => getWorkflowsStub;
109 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
110 $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub;
112 return $controller.loadWorkFlows()
114 expect($controller.remoteWorkflowsParameters).toEqual(new Map([["workflow 0",
115 [{"id": 1, "name": "parameter 1", "pattern": "[0-9]*", "required": true, "type": "STRING"},
116 {"id": 2, "name": "parameter 2", "pattern": ".*", "required": true, "type": "STRING"},
117 {"id": 3, "name": "parameter 3", "pattern": "[0-9]*", "required": false, "type": "STRING"}]]]));
121 test('Verify broken SO workflows wont change content of local workflows', () => {
123 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
124 let getSOWorkflowsPromiseStub = Promise.reject(new Error("Broken SO workflows service."));
126 $controller.changeManagement.vnfNames = "any";
127 $changeManagementService.getWorkflows = () => getWorkflowsStub;
128 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
130 $controller.loadWorkFlows()
132 expect($controller.workflows).toEqual(['workflow 0']);