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
|
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']);
});
});
});
|