Introduced mocked SO workflows in VID FE
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / modals / new-change-management / new-change-management.controller.test.js
1 require('./new-change-management.controller');
2 const jestMock = require('jest-mock');
3
4 describe('Testing workFlows from SO', () => {
5   let $notNeeded;
6   let $controller;
7   let $changeManagementService;
8   beforeEach(
9       angular.mock.module('app')
10   );
11
12   beforeEach(inject(function (_$controller_) {
13     $notNeeded = jestMock.fn();
14     // mock ChangeManagementService
15     $changeManagementService = jestMock.fn();
16     $changeManagementService.getAllSDCServices = jestMock.fn(() => Promise.resolve([]));
17
18     // mock q
19     $q = jestMock.fn();
20     $defer = jestMock.fn();
21     $q.defer = jestMock.fn(() => $defer);
22     $defer.promise = Promise.resolve({});
23     // mock AaiService
24     $aaiService = jestMock.fn();
25     $aaiService.getLoggedInUserID = jestMock.fn();
26     $aaiService.getSubscribers = jestMock.fn();
27     $controller = _$controller_('newChangeManagementModalController', {
28       $uibModalInstance: $notNeeded,
29       $uibModal: $notNeeded,
30       $q: $q,
31       AaiService: $aaiService,
32       changeManagementService: $changeManagementService,
33       Upload: $notNeeded,
34       $log: $notNeeded,
35       _: $notNeeded,
36       COMPONENT: $notNeeded,
37       VIDCONFIGURATION: $notNeeded,
38       DataService: $notNeeded,
39       featureFlags: $notNeeded,
40       $scope: $notNeeded,
41     });
42   }));
43
44   test('Verify load workflows from SO will call getSOWorkflow and return only names of workflows', () => {
45     // given
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 = [];
50     // when
51     return $controller.loadRemoteWorkFlows()
52     .then(() => {
53            remoteWorkflows = $controller.remoteWorkflows.map(item => item.name)
54            expect(remoteWorkflows).toContain('workflow 1');
55            expect(remoteWorkflows).toContain('workflow 2');
56         }
57      );
58   });
59
60   test('Verify load workflows will call load from SO and join workflow lists', () => {
61     // given
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"}]});
64
65     $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
66     $changeManagementService.getWorkflows = () => getWorkflowsStub;
67     $changeManagementService.getSOWorkflows = () =>  getSOWorkflowsPromiseStub;
68     // when
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');
73     });
74   });
75
76   test('Verify broken SO workflows wont change content of local workflows', () => {
77     // given
78     let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}});
79     let getSOWorkflowsPromiseStub = Promise.reject(new Error("Broken SO workflows service."));
80
81     $controller.changeManagement.vnfNames = "any";
82     $changeManagementService.getWorkflows = () => getWorkflowsStub;
83     $changeManagementService.getSOWorkflows = () =>  getSOWorkflowsPromiseStub;
84     // when
85     $controller.loadWorkFlows()
86     .then(() => {
87       expect($controller.workflows).toEqual(['workflow 0']);
88     });
89   });
90 });
91