1 require('./new-change-management.controller');
2 const jestMock = require('jest-mock');
4 describe('Testing workFlows from SO', () => {
7 let $changeManagementService;
9 angular.mock.module('app')
12 beforeEach(inject(function (_$controller_) {
13 $notNeeded = jestMock.fn();
14 // mock ChangeManagementService
15 $changeManagementService = jestMock.fn();
16 $changeManagementService.getAllSDCServices = jestMock.fn(() => Promise.resolve([]));
20 $defer = jestMock.fn();
21 $q.defer = jestMock.fn(() => $defer);
22 $defer.promise = Promise.resolve({});
24 $aaiService = jestMock.fn();
25 $aaiService.getLoggedInUserID = jestMock.fn();
26 $aaiService.getSubscribers = jestMock.fn();
27 $controller = _$controller_('newChangeManagementModalController', {
28 $uibModalInstance: $notNeeded,
29 $uibModal: $notNeeded,
31 AaiService: $aaiService,
32 changeManagementService: $changeManagementService,
36 COMPONENT: $notNeeded,
37 VIDCONFIGURATION: $notNeeded,
38 DataService: $notNeeded,
39 featureFlags: $notNeeded,
44 test('Verify load workflows from SO will call getSOWorkflow and return only names of workflows', () => {
46 $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
47 let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 1"}, {"id": "2", "name": "workflow 2"}]});
48 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
49 $controller.workflows = [];
51 return $controller.loadRemoteWorkFlows()
53 remoteWorkflows = $controller.remoteWorkflows.map(item => item.name)
54 expect(remoteWorkflows).toContain('workflow 1');
55 expect(remoteWorkflows).toContain('workflow 2');
60 test('Verify load workflows will call load from SO and join workflow lists', () => {
62 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
63 let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 1"}, {"id": "2", "name": "workflow 2"}]});
65 $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
66 $changeManagementService.getWorkflows = () => getWorkflowsStub;
67 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
69 return $controller.loadWorkFlows().then(() => {
70 expect($controller.workflows).toContain('workflow 0');
71 expect($controller.workflows).toContain('workflow 1');
72 expect($controller.workflows).toContain('workflow 2');
76 test('Verify broken SO workflows wont change content of local workflows', () => {
78 let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
79 let getSOWorkflowsPromiseStub = Promise.reject(new Error("Broken SO workflows service."));
81 $controller.changeManagement.vnfNames = "any";
82 $changeManagementService.getWorkflows = () => getWorkflowsStub;
83 $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
85 $controller.loadWorkFlows()
87 expect($controller.workflows).toEqual(['workflow 0']);