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');
23 const moment = require('moment');
25 describe('changeManagementManualTasksController testing', () => {
27 let $uibModalInstance = jestMock.fn();
28 let $MsoService = jestMock.fn();
29 let $log = jestMock.fn();
32 angular.mock.module('app')
35 beforeEach(inject(function (_$controller_) {
36 $log.error = jestMock.fn();
37 $uibModalInstance.close = jestMock.fn();
39 mockManualTaskResponse(manualTaskResponse);
41 $controller = _$controller_('changeManagementManualTasksController', {
42 "MsoService": $MsoService,
43 "$uibModalInstance": $uibModalInstance,
47 requestState: job.requestStatus.requestState,
48 details: job.requestStatus.statusMessage,
52 MANUAL_TASKS: ["manualTaskName1", "manualTaskName2"]
57 function mockManualTaskResponse(manualTaskResponse) {
58 $MsoService.getManualTasks = jestMock.fn().mockResolvedValue(
59 {data: [manualTaskResponse]}
64 "requestId": "db775fac-d9b5-480e-8b3e-4f0d0ae67890",
65 "requestScope": "vnf",
67 "percentProgress": 100.0,
68 "requestState": "FAILED",
69 "statusMessage": "Error validating request. No valid catalog entry is specified",
70 "finishTime": "Thu, 05 Oct 2017 18:58:29 GMT"
72 "requestType": "replaceInstance",
73 "startTime": "Thu, 05 Oct 2017 18:58:29 GMT",
74 "instanceReferences": {
75 "serviceInstanceId": "cc8fa0a9-7576-4c39-af31-7ad61d057ac9",
76 "vnfInstanceId": "bec0c3d3-09ae-4eb1-b694-057987a10982",
77 "requestorId": "pa2396"
81 const manualTaskResponseWithoutValidResponses = {
82 "taskId": "db775fac-d9b5-480e-8b3e-4f0d0ae67890",
85 const manualTaskResponse = Object.assign({
86 "validResponses": ["rollback", "abort", "skip", "resume", "retry"],
87 }, manualTaskResponseWithoutValidResponses);
89 const manualTaskResponseWithTimeout = Object.assign({
90 description: 'description',
92 }, manualTaskResponse);
94 test('should populate vm.manualTasks (while init)', () => {
95 expect($controller.manualTasks).toEqual(
96 manualTaskResponse.validResponses);
99 test('should undefine vm.manualTasks when ValidResponses not given', () => {
101 mockManualTaskResponse(manualTaskResponseWithoutValidResponses);
103 return $controller.__test_only__.loadAvailableTasks('anything')
105 expect($controller.manualTasks).toBeUndefined()
109 test('should populate vm.MANUAL_TASKS from COMPONENT (while init)', () => {
110 expect($controller.MANUAL_TASKS).toEqual(
111 ["manualTaskName1", "manualTaskName2"]);
114 test('should populate vm.task (while init)', () => {
115 expect($controller.task).toEqual(manualTaskResponse);
118 test('should nullify vm.description (while init)', () => {
119 expect($controller.description).toBeNull();
122 test('should nullify vm.timeout (while init)', () => {
123 expect($controller.timeout).toBeNull();
126 test('should populate vm.description', () => {
128 mockManualTaskResponse(manualTaskResponseWithTimeout);
130 return $controller.__test_only__.loadAvailableTasks('anything')
132 expect($controller.description).toEqual('description');
136 test('should populate vm.timeout', () => {
138 mockManualTaskResponse(manualTaskResponseWithTimeout);
140 return $controller.__test_only__.loadAvailableTasks('anything')
142 expect($controller.timeout).toEqual('timeout');
146 test('should humanize timeout if proper ISO-8601', () => {
147 $controller.timeout = 'PT3350S';
148 expect($controller.timeoutHumanized()).toEqual('0:55 hours (PT3350S)');
151 test('should humanize timeout if proper ISO-8601', () => {
152 $controller.timeout = 'P3DT1H1M';
153 expect($controller.timeoutHumanized()).toEqual('73:01 hours (P3DT1H1M)');
156 test('should drive-through timeout if not proper ISO-8601', () => {
157 $controller.timeout = '56 minutes';
158 expect($controller.timeoutHumanized()).toEqual('56 minutes');
161 test('should drive-through timeout if undefined', () => {
162 $controller.timeout = undefined;
163 expect($controller.timeoutHumanized()).toEqual(undefined);
166 test('should find manual task using isTaskAvailable', () => {
167 expect($controller.isTaskAvailable('abort')).toBeTruthy();
168 expect($controller.isTaskAvailable('resume')).toBeTruthy();
170 expect($controller.isTaskAvailable('foo')).toBeFalsy();
171 expect($controller.isTaskAvailable(undefined)).toBeFalsy();
174 test('should call MsoService upon completeTask', () => {
175 $MsoService.completeTask = jestMock.fn().mockResolvedValue({data: {}});
177 $controller.completeTask("taskName");
178 expect($MsoService.completeTask).toBeCalledWith(
179 manualTaskResponse.taskId, "taskName");
182 test('should close modal upon completeTask', done => {
183 $MsoService.completeTask = jestMock.fn().mockResolvedValue({data: {}});
184 $uibModalInstance.close = jestMock.fn(() => {
188 $controller.completeTask("taskName");
191 test('should close modal upon failed completeTask', done => {
192 $MsoService.completeTask = jestMock.fn().mockRejectedValue();
193 $uibModalInstance.close = jestMock.fn(() => {
197 $controller.completeTask("taskName");