aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js')
-rw-r--r--vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js
new file mode 100644
index 000000000..c4b940641
--- /dev/null
+++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js
@@ -0,0 +1,91 @@
+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"}]});
+
+ $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}];
+ $changeManagementService.getWorkflows = () => getWorkflowsStub;
+ $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub;
+ // 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 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']);
+ });
+ });
+});
+