2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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('./change-management-manual-tasks.controller');
22 const jestMock = require('jest-mock');
24 describe('changeManagementManualTasksController testing', () => {
26 let $uibModalInstance = jestMock.fn();
27 let $MsoService = jestMock.fn();
28 let $log = jestMock.fn();
31 angular.mock.module('app')
34 beforeEach(inject(function (_$controller_) {
35 $log.error = jestMock.fn();
36 $uibModalInstance.close = jestMock.fn();
38 mockManualTaskResponse(manualTaskResponse);
40 $controller = _$controller_('changeManagementManualTasksController', {
41 "MsoService": $MsoService,
42 "$uibModalInstance": $uibModalInstance,
45 requestState: job.requestStatus.requestState,
46 details: job.requestStatus.statusMessage,
50 MANUAL_TASKS: ["manualTaskName1", "manualTaskName2"]
55 function mockManualTaskResponse(manualTaskResponse) {
56 $MsoService.getManualTasks = jestMock.fn().mockResolvedValue(
57 {data: [manualTaskResponse]}
62 "requestId": "db775fac-d9b5-480e-8b3e-4f0d0ae67890",
63 "requestScope": "vnf",
65 "percentProgress": 100.0,
66 "requestState": "FAILED",
67 "statusMessage": "Error validating request. No valid catalog entry is specified",
68 "finishTime": "Thu, 05 Oct 2017 18:58:29 GMT"
70 "requestType": "replaceInstance",
71 "startTime": "Thu, 05 Oct 2017 18:58:29 GMT",
72 "instanceReferences": {
73 "serviceInstanceId": "cc8fa0a9-7576-4c39-af31-7ad61d057ac9",
74 "vnfInstanceId": "bec0c3d3-09ae-4eb1-b694-057987a10982",
75 "requestorId": "pa2396"
79 const manualTaskResponseWithoutValidResponses = {
80 "taskId": "db775fac-d9b5-480e-8b3e-4f0d0ae67890",
83 const manualTaskResponse = Object.assign({
84 "validResponses": ["rollback", "abort", "skip", "resume", "retry"],
85 }, manualTaskResponseWithoutValidResponses);
87 const manualTaskResponseWithTimeout = Object.assign({
88 description: 'description',
90 }, manualTaskResponse);
92 test('should populate vm.manualTasks (while init)', () => {
93 expect($controller.manualTasks).toEqual(
94 manualTaskResponse.validResponses);
97 test('should undefine vm.manualTasks when ValidResponses not given', () => {
99 mockManualTaskResponse(manualTaskResponseWithoutValidResponses);
101 return $controller.__test_only__.loadAvailableTasks('anything')
103 expect($controller.manualTasks).toBeUndefined()
107 test('should populate vm.MANUAL_TASKS from COMPONENT (while init)', () => {
108 expect($controller.MANUAL_TASKS).toEqual(
109 ["manualTaskName1", "manualTaskName2"]);
112 test('should populate vm.task (while init)', () => {
113 expect($controller.task).toEqual(manualTaskResponse);
116 test('should nullify vm.description (while init)', () => {
117 expect($controller.description).toBeNull();
120 test('should nullify vm.timeout (while init)', () => {
121 expect($controller.timeout).toBeNull();
124 test('should populate vm.description', () => {
126 mockManualTaskResponse(manualTaskResponseWithTimeout);
128 return $controller.__test_only__.loadAvailableTasks('anything')
130 expect($controller.description).toEqual('description');
134 test('should populate vm.timeout', () => {
136 mockManualTaskResponse(manualTaskResponseWithTimeout);
138 return $controller.__test_only__.loadAvailableTasks('anything')
140 expect($controller.timeout).toEqual('timeout');
144 test('should find manual task using isTaskAvailable', () => {
145 expect($controller.isTaskAvailable('abort')).toBeTruthy();
146 expect($controller.isTaskAvailable('resume')).toBeTruthy();
148 expect($controller.isTaskAvailable('foo')).toBeFalsy();
149 expect($controller.isTaskAvailable(undefined)).toBeFalsy();
152 test('should call MsoService upon completeTask', () => {
153 $MsoService.completeTask = jestMock.fn().mockResolvedValue({data: {}});
155 $controller.completeTask("taskName");
156 expect($MsoService.completeTask).toBeCalledWith(
157 manualTaskResponse.taskId, "taskName");
160 test('should close modal upon completeTask', done => {
161 $MsoService.completeTask = jestMock.fn().mockResolvedValue({data: {}});
162 $uibModalInstance.close = jestMock.fn(() => {
166 $controller.completeTask("taskName");
169 test('should close modal upon failed completeTask', done => {
170 $MsoService.completeTask = jestMock.fn().mockRejectedValue();
171 $uibModalInstance.close = jestMock.fn(() => {
175 $controller.completeTask("taskName");