blob: 6ad696ae85f0abc4ca1433508b2eaf4c30e4b29c [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';
talig8e9c0652017-12-20 14:30:43 +020032import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
Michael Landoefa037d2017-02-19 12:57:33 +020033
34const softwareProductId = '123';
talig8e9c0652017-12-20 14:30:43 +020035const version = VersionFactory.build();
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;
AviZi280f8012017-06-09 02:39:56 +0300320 const versionId = version.id;
Michael Landoefa037d2017-02-19 12:57:33 +0200321 deepFreeze(store.getState());
322
323 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', []);
324
325 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +0300326 expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/processes/${processId}`);
327 expect(data).toEqual(undefined);
328 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200329 return {
330 results: {
331 returnCode: 'OK'
332 }
333 };
334 });
335
336 return SoftwareProductProcessesActionHelper.deleteProcess(store.dispatch, {
337 process: softwareProductProcessesList[0],
AviZi280f8012017-06-09 02:39:56 +0300338 softwareProductId,
339 version
Michael Landoefa037d2017-02-19 12:57:33 +0200340 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300341 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200342 });
343 });
344
talig8e9c0652017-12-20 14:30:43 +0200345 it('Validating Software Products Processes Delete confirmation', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200346 const store = storeCreator();
347 deepFreeze(store.getState());
348
AviZi280f8012017-06-09 02:39:56 +0300349 let process = VSPProcessStoreFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200350 deepFreeze(process);
351
352 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processToDelete', process);
353
talig8e9c0652017-12-20 14:30:43 +0200354 return SoftwareProductProcessesActionHelper.openDeleteProcessesConfirm(store.dispatch, {process});
Michael Landoefa037d2017-02-19 12:57:33 +0200355
talig8e9c0652017-12-20 14:30:43 +0200356 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200357 });
358
talig8e9c0652017-12-20 14:30:43 +0200359 it('Validating Software Products Processes Cancel Delete', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200360 const store = storeCreator();
361 deepFreeze(store.getState());
362
363 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processToDelete', false);
364
365 SoftwareProductProcessesActionHelper.hideDeleteConfirm(store.dispatch);
366
talig8e9c0652017-12-20 14:30:43 +0200367 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200368 });
369
370 //**
371 //** CREATE/EDIT
372 //**
AviZi280f8012017-06-09 02:39:56 +0300373 it('Validating open Software Products Processes for create', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200374 const store = storeCreator();
375 deepFreeze(store.getState());
376
377 let process = {};
378 deepFreeze(process);
379
380 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesEditor.data', process);
381
382 SoftwareProductProcessesActionHelper.openEditor(store.dispatch);
AviZi280f8012017-06-09 02:39:56 +0300383 expect(store.getState().softwareProduct.softwareProductProcesses.processesEditor.data).toEqual(expectedStore.softwareProduct.softwareProductProcesses.processesEditor.data);
Michael Landoefa037d2017-02-19 12:57:33 +0200384 });
385
AviZi280f8012017-06-09 02:39:56 +0300386 it('Validating close Software Products Processes from editing mode', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200387 const store = storeCreator();
388 deepFreeze(store.getState());
389
390 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesEditor', {});
391
392 SoftwareProductProcessesActionHelper.closeEditor(store.dispatch);
AviZi280f8012017-06-09 02:39:56 +0300393 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200394 });
395
AviZi280f8012017-06-09 02:39:56 +0300396 it('Validating open Software Products Processes for editing', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200397 const store = storeCreator();
398 deepFreeze(store.getState());
399
400 let process = {name: 'aa', description: 'xx'};
401 deepFreeze(process);
402
403 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesEditor.data', process);
404
405 SoftwareProductProcessesActionHelper.openEditor(store.dispatch, process);
AviZi280f8012017-06-09 02:39:56 +0300406 expect(store.getState().softwareProduct.softwareProductProcesses.processesEditor.data).toEqual(expectedStore.softwareProduct.softwareProductProcesses.processesEditor.data);
Michael Landoefa037d2017-02-19 12:57:33 +0200407
Michael Landoefa037d2017-02-19 12:57:33 +0200408 });
409
Michael Landoefa037d2017-02-19 12:57:33 +0200410});