blob: 43110d2e55dbf3df8bb2613be97744d54260a8bf [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
AviZi280f8012017-06-09 02:39:56 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import deepFreeze from 'deep-freeze';
17import mockRest from 'test-utils/MockRest.js';
18import {cloneAndSet} from 'test-utils/Util.js';
19import {storeCreator} from 'sdc-app/AppStore.js';
20import Configuration from 'sdc-app/config/Configuration.js';
21import SoftwareProductProcessesActionHelper from 'sdc-app/onboarding/softwareProduct/processes/SoftwareProductProcessesActionHelper.js';
AviZi280f8012017-06-09 02:39:56 +030022import {
23 VSPProcessPostFactory,
24 VSPProcessStoreFactory,
25 VSPProcessPostFactoryWithType,
26 VSPProcessStoreFactoryWithType,
27 VSPProcessStoreWithFormDataFactory,
28 VSPProcessPostWithFormDataFactory,
29 VSPProcessStoreWithArtifactNameFactory } from 'test-utils/factories/softwareProduct/SoftwareProductProcessFactories.js';
30import {buildFromExistingObject} from 'test-utils/Util.js';
31import {VSPEditorFactory} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';
32import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
Michael Landoefa037d2017-02-19 12:57:33 +020033
34const softwareProductId = '123';
AviZi280f8012017-06-09 02:39:56 +030035const version = VSPEditorFactory.build().version;
Michael Landoefa037d2017-02-19 12:57:33 +020036
37describe('Software Product Processes Module Tests', function () {
38
39 let restPrefix = '';
40
AviZi280f8012017-06-09 02:39:56 +030041 beforeAll(function() {
Michael Landoefa037d2017-02-19 12:57:33 +020042 restPrefix = Configuration.get('restPrefix');
43 deepFreeze(restPrefix);
44 });
45
46 //**
47 //** ADD
48 //**
49 it('Add Software Products Processes', () => {
50
51 const store = storeCreator();
52 deepFreeze(store.getState());
53
Michael Landoefa037d2017-02-19 12:57:33 +020054 const softwareProductProcessFromResponse = 'ADDED_ID';
AviZi280f8012017-06-09 02:39:56 +030055
56 const softwareProductProcessAfterAdd = VSPProcessStoreFactory.build({id: softwareProductProcessFromResponse});
57 const softwareProductPostRequest = buildFromExistingObject(VSPProcessPostFactory, softwareProductProcessAfterAdd);
Michael Landoefa037d2017-02-19 12:57:33 +020058
59 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', [softwareProductProcessAfterAdd]);
60
AviZi280f8012017-06-09 02:39:56 +030061 mockRest.addHandler('post', ({data, options, baseUrl}) => {
Michael Landoefa037d2017-02-19 12:57:33 +020062
AviZi280f8012017-06-09 02:39:56 +030063 expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/processes`);
64 expect(data).toEqual(softwareProductPostRequest);
65 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020066 return {
67 returnCode: 'OK',
68 value: softwareProductProcessFromResponse
69 };
70 });
71
72 return SoftwareProductProcessesActionHelper.saveProcess(store.dispatch,
73 {
AviZi280f8012017-06-09 02:39:56 +030074 softwareProductId,
75 version,
Michael Landoefa037d2017-02-19 12:57:33 +020076 previousProcess: null,
AviZi280f8012017-06-09 02:39:56 +030077 process: softwareProductPostRequest
Michael Landoefa037d2017-02-19 12:57:33 +020078 }
79 ).then(() => {
AviZi280f8012017-06-09 02:39:56 +030080 expect(store.getState()).toEqual(expectedStore);
81 });
82 });
83
84 it('Add Software Products Processes with type', () => {
85
86 const store = storeCreator();
87 deepFreeze(store.getState());
88
89 const softwareProductProcessFromResponse = 'ADDED_ID';
90
91 const softwareProductProcessAfterAdd = VSPProcessStoreFactoryWithType.build({id: softwareProductProcessFromResponse});
92 const softwareProductPostRequest = buildFromExistingObject(VSPProcessPostFactoryWithType, softwareProductProcessAfterAdd);
93
94 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', [softwareProductProcessAfterAdd]);
95
96 mockRest.addHandler('post', ({data, options, baseUrl}) => {
97
98 expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/processes`);
99 expect(data).toEqual(softwareProductPostRequest);
100 expect(options).toEqual(undefined);
101 return {
102 returnCode: 'OK',
103 value: softwareProductProcessFromResponse
104 };
105 });
106
107 return SoftwareProductProcessesActionHelper.saveProcess(store.dispatch,
108 {
109 softwareProductId,
110 version,
111 previousProcess: null,
112 process: softwareProductPostRequest
113 }
114 ).then(() => {
115 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200116 });
117 });
118
119 it('Add Software Products Processes with uploaded file', () => {
120
121 const store = storeCreator();
122 deepFreeze(store.getState());
123
AviZi280f8012017-06-09 02:39:56 +0300124 const softwareProductPostRequest = VSPProcessPostFactoryWithType.build();
125 const softwareProductProcessToAdd = VSPProcessPostWithFormDataFactory.build(softwareProductPostRequest);
126 const softwareProductProcessAfterAdd = VSPProcessStoreWithFormDataFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200127
128 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', [softwareProductProcessAfterAdd]);
129
AviZi280f8012017-06-09 02:39:56 +0300130 mockRest.addHandler('post', ({data, options, baseUrl}) => {
131 expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/processes`);
132 expect(data).toEqual(softwareProductPostRequest);
133 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200134 return {
135 returnCode: 'OK',
AviZi280f8012017-06-09 02:39:56 +0300136 value: softwareProductProcessAfterAdd.id
Michael Landoefa037d2017-02-19 12:57:33 +0200137 };
138 });
139
AviZi280f8012017-06-09 02:39:56 +0300140 mockRest.addHandler('post', ({data, options, baseUrl}) => {
141 expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/processes/${softwareProductProcessAfterAdd.id}/upload`);
142 expect(data).toEqual(softwareProductProcessToAdd.formData);
143 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200144 return {returnCode: 'OK'};
145 });
146
147 return SoftwareProductProcessesActionHelper.saveProcess(store.dispatch,
148 {
AviZi280f8012017-06-09 02:39:56 +0300149 softwareProductId,
150 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200151 previousProcess: null,
152 process: softwareProductProcessToAdd
153 }
154 ).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300155 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200156 });
157 });
158
159 //**
160 //** UPDATE
161 //**
162 it('Update Software Products Processes', () => {
AviZi280f8012017-06-09 02:39:56 +0300163 const softwareProductProcessesList = VSPProcessStoreWithArtifactNameFactory.buildList(1);
Michael Landoefa037d2017-02-19 12:57:33 +0200164 deepFreeze(softwareProductProcessesList);
165
166 const store = storeCreator({
167 softwareProduct: {
168 softwareProductProcesses: {
169 processesList: softwareProductProcessesList
170 }
171 }
172 });
173 deepFreeze(store.getState());
174
175 const toBeUpdatedProcessId = softwareProductProcessesList[0].id;
176 const previousProcessData = softwareProductProcessesList[0];
AviZi280f8012017-06-09 02:39:56 +0300177 const processUpdateData = VSPProcessStoreWithArtifactNameFactory.build(
178 {...previousProcessData,
179 name: 'Pr1_UPDATED',
180 description: 'string_UPDATED',
181 type: 'Other'
182 }
183 );
184
Michael Landoefa037d2017-02-19 12:57:33 +0200185 deepFreeze(processUpdateData);
186
AviZi280f8012017-06-09 02:39:56 +0300187 const processPutRequest = VSPProcessPostFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200188 name: 'Pr1_UPDATED',
AviZi280f8012017-06-09 02:39:56 +0300189 description: 'string_UPDATED',
190 type: 'Other'
191 });
Michael Landoefa037d2017-02-19 12:57:33 +0200192 deepFreeze(processPutRequest);
193
194 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', [processUpdateData]);
195
196
AviZi280f8012017-06-09 02:39:56 +0300197 mockRest.addHandler('put', ({data, options, baseUrl}) => {
198 expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/processes/${toBeUpdatedProcessId}`);
199 expect(data).toEqual(processPutRequest);
200 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200201 return {returnCode: 'OK'};
202 });
203
204 return SoftwareProductProcessesActionHelper.saveProcess(store.dispatch,
205 {
AviZi280f8012017-06-09 02:39:56 +0300206 softwareProductId,
207 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200208 previousProcess: previousProcessData,
209 process: processUpdateData
210 }
211 ).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300212 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200213 });
214 });
215
216 it('Update Software Products Processes and uploaded file', () => {
AviZi280f8012017-06-09 02:39:56 +0300217 const previousProcessData = VSPProcessStoreWithArtifactNameFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200218 deepFreeze(previousProcessData);
219
220 const store = storeCreator({
221 softwareProduct: {
222 softwareProductProcesses: {
223 processesList: [previousProcessData]
224 }
225 }
226 });
227 deepFreeze(store.getState());
228
AviZi280f8012017-06-09 02:39:56 +0300229 const newProcessToUpdate = VSPProcessStoreWithFormDataFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200230 ...previousProcessData,
231 name: 'new name',
232 formData: {
233 name: 'new artifact name'
234 }
AviZi280f8012017-06-09 02:39:56 +0300235 });
Michael Landoefa037d2017-02-19 12:57:33 +0200236 deepFreeze(newProcessToUpdate);
237
AviZi280f8012017-06-09 02:39:56 +0300238 const newProcessToPutRequest = VSPProcessPostFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200239 name: newProcessToUpdate.name,
AviZi280f8012017-06-09 02:39:56 +0300240 description: previousProcessData.description,
241 type: previousProcessData.type
242 });
Michael Landoefa037d2017-02-19 12:57:33 +0200243 deepFreeze(newProcessToPutRequest);
244
245 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', [newProcessToUpdate]);
246
AviZi280f8012017-06-09 02:39:56 +0300247 mockRest.addHandler('put', ({data, options, baseUrl}) => {
248 expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/processes/${newProcessToUpdate.id}`);
249 expect(data).toEqual(newProcessToPutRequest);
250 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200251 return {returnCode: 'OK'};
252 });
253
AviZi280f8012017-06-09 02:39:56 +0300254 mockRest.addHandler('post', ({data, options, baseUrl}) => {
255 expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/processes/${newProcessToUpdate.id}/upload`);
256 expect(data).toEqual(newProcessToUpdate.formData);
257 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200258 return {returnCode: 'OK'};
259 });
260
261 return SoftwareProductProcessesActionHelper.saveProcess(store.dispatch,
262 {
AviZi280f8012017-06-09 02:39:56 +0300263 softwareProductId,
264 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200265 previousProcess: previousProcessData,
266 process: newProcessToUpdate
267 }
268 ).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300269 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200270 });
271 });
272
273 //**
274 //** GET
275 //**
276 it('Get Software Products Processes List', () => {
277 const store = storeCreator();
278 deepFreeze(store.getState());
279
AviZi280f8012017-06-09 02:39:56 +0300280 const softwareProductProcessesList = VSPProcessStoreFactory.buildList(2);
Michael Landoefa037d2017-02-19 12:57:33 +0200281
282 deepFreeze(softwareProductProcessesList);
283
284 deepFreeze(store.getState());
285
286 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', softwareProductProcessesList);
287
288 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +0300289 expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/processes`);
290 expect(data).toEqual(undefined);
291 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200292 return {results: softwareProductProcessesList};
293 });
294
AviZi280f8012017-06-09 02:39:56 +0300295 return SoftwareProductProcessesActionHelper.fetchProcessesList(store.dispatch, {softwareProductId, version}).then(() => {
296 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200297 });
298 });
299
300 //**
301 //** DELETE
302 //**
303 it('Delete Software Products Processes', () => {
AviZi280f8012017-06-09 02:39:56 +0300304 const softwareProductProcessesList = VSPProcessStoreWithArtifactNameFactory.buildList(1);
305 const currentSoftwareProduct = VSPEditorFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200306
307 deepFreeze(softwareProductProcessesList);
308 const store = storeCreator({
309 softwareProduct: {
310 softwareProductProcesses: {
311 processesList: softwareProductProcessesList
AviZi280f8012017-06-09 02:39:56 +0300312 },
313 softwareProductEditor: {
314 data: currentSoftwareProduct
Michael Landoefa037d2017-02-19 12:57:33 +0200315 }
316 }
317 });
318
AviZi280f8012017-06-09 02:39:56 +0300319 const processId = softwareProductProcessesList[0].id;
320 const version = store.getState().softwareProduct.softwareProductEditor.data.version;
321 const versionId = version.id;
Michael Landoefa037d2017-02-19 12:57:33 +0200322 deepFreeze(store.getState());
323
324 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', []);
325
326 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +0300327 expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/processes/${processId}`);
328 expect(data).toEqual(undefined);
329 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200330 return {
331 results: {
332 returnCode: 'OK'
333 }
334 };
335 });
336
337 return SoftwareProductProcessesActionHelper.deleteProcess(store.dispatch, {
338 process: softwareProductProcessesList[0],
AviZi280f8012017-06-09 02:39:56 +0300339 softwareProductId,
340 version
Michael Landoefa037d2017-02-19 12:57:33 +0200341 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300342 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200343 });
344 });
345
346 it('Validating Software Products Processes Delete confirmation', done => {
347 const store = storeCreator();
348 deepFreeze(store.getState());
349
AviZi280f8012017-06-09 02:39:56 +0300350 let process = VSPProcessStoreFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200351 deepFreeze(process);
352
353 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processToDelete', process);
354
355 SoftwareProductProcessesActionHelper.openDeleteProcessesConfirm(store.dispatch, {process});
356
357 setTimeout(function(){
AviZi280f8012017-06-09 02:39:56 +0300358 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200359 done();
360 }, 100);
361 });
362
363 it('Validating Software Products Processes Cancel Delete', done => {
364 const store = storeCreator();
365 deepFreeze(store.getState());
366
367 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processToDelete', false);
368
369 SoftwareProductProcessesActionHelper.hideDeleteConfirm(store.dispatch);
370
371 setTimeout(function(){
AviZi280f8012017-06-09 02:39:56 +0300372 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200373 done();
374 }, 100);
375 });
376
377 //**
378 //** CREATE/EDIT
379 //**
AviZi280f8012017-06-09 02:39:56 +0300380 it('Validating open Software Products Processes for create', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200381 const store = storeCreator();
382 deepFreeze(store.getState());
383
384 let process = {};
385 deepFreeze(process);
386
387 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesEditor.data', process);
388
389 SoftwareProductProcessesActionHelper.openEditor(store.dispatch);
AviZi280f8012017-06-09 02:39:56 +0300390 expect(store.getState().softwareProduct.softwareProductProcesses.processesEditor.data).toEqual(expectedStore.softwareProduct.softwareProductProcesses.processesEditor.data);
Michael Landoefa037d2017-02-19 12:57:33 +0200391 });
392
AviZi280f8012017-06-09 02:39:56 +0300393 it('Validating close Software Products Processes from editing mode', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200394 const store = storeCreator();
395 deepFreeze(store.getState());
396
397 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesEditor', {});
398
399 SoftwareProductProcessesActionHelper.closeEditor(store.dispatch);
AviZi280f8012017-06-09 02:39:56 +0300400 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200401 });
402
AviZi280f8012017-06-09 02:39:56 +0300403 it('Validating open Software Products Processes for editing', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200404 const store = storeCreator();
405 deepFreeze(store.getState());
406
407 let process = {name: 'aa', description: 'xx'};
408 deepFreeze(process);
409
410 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesEditor.data', process);
411
412 SoftwareProductProcessesActionHelper.openEditor(store.dispatch, process);
AviZi280f8012017-06-09 02:39:56 +0300413 expect(store.getState().softwareProduct.softwareProductProcesses.processesEditor.data).toEqual(expectedStore.softwareProduct.softwareProductProcesses.processesEditor.data);
Michael Landoefa037d2017-02-19 12:57:33 +0200414
Michael Landoefa037d2017-02-19 12:57:33 +0200415 });
416
Michael Landoefa037d2017-02-19 12:57:33 +0200417});