Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 1 | /*- |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * SDC |
| 4 | * ================================================================================ |
| 5 | * Copyright (C) 2017 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 |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 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========================================================= |
| 19 | */ |
| 20 | |
| 21 | import {expect} from 'chai'; |
| 22 | import deepFreeze from 'deep-freeze'; |
| 23 | import mockRest from 'test-utils/MockRest.js'; |
| 24 | import {cloneAndSet} from 'test-utils/Util.js'; |
| 25 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 26 | import Configuration from 'sdc-app/config/Configuration.js'; |
| 27 | import SoftwareProductProcessesActionHelper from 'sdc-app/onboarding/softwareProduct/processes/SoftwareProductProcessesActionHelper.js'; |
| 28 | |
| 29 | const softwareProductId = '123'; |
| 30 | |
| 31 | describe('Software Product Processes Module Tests', function () { |
| 32 | |
| 33 | let restPrefix = ''; |
| 34 | |
| 35 | before(function() { |
| 36 | restPrefix = Configuration.get('restPrefix'); |
| 37 | deepFreeze(restPrefix); |
| 38 | }); |
| 39 | |
| 40 | //** |
| 41 | //** ADD |
| 42 | //** |
| 43 | it('Add Software Products Processes', () => { |
| 44 | |
| 45 | const store = storeCreator(); |
| 46 | deepFreeze(store.getState()); |
| 47 | |
| 48 | const softwareProductPostRequest = { |
| 49 | name: 'Pr1', |
| 50 | description: 'string' |
| 51 | }; |
| 52 | const softwareProductProcessToAdd = { |
| 53 | name: 'Pr1', |
| 54 | description: 'string' |
| 55 | }; |
| 56 | const softwareProductProcessFromResponse = 'ADDED_ID'; |
| 57 | const softwareProductProcessAfterAdd = { |
| 58 | ...softwareProductProcessToAdd, |
| 59 | id: softwareProductProcessFromResponse |
| 60 | }; |
| 61 | |
| 62 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', [softwareProductProcessAfterAdd]); |
| 63 | |
| 64 | mockRest.addHandler('create', ({data, options, baseUrl}) => { |
| 65 | |
| 66 | expect(baseUrl).to.equal(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/processes`); |
| 67 | expect(data).to.deep.equal(softwareProductPostRequest); |
| 68 | expect(options).to.equal(undefined); |
| 69 | return { |
| 70 | returnCode: 'OK', |
| 71 | value: softwareProductProcessFromResponse |
| 72 | }; |
| 73 | }); |
| 74 | |
| 75 | return SoftwareProductProcessesActionHelper.saveProcess(store.dispatch, |
| 76 | { |
| 77 | softwareProductId: softwareProductId, |
| 78 | previousProcess: null, |
| 79 | process: softwareProductProcessToAdd |
| 80 | } |
| 81 | ).then(() => { |
| 82 | expect(store.getState()).to.deep.equal(expectedStore); |
| 83 | }); |
| 84 | }); |
| 85 | |
| 86 | it('Add Software Products Processes with uploaded file', () => { |
| 87 | |
| 88 | const store = storeCreator(); |
| 89 | deepFreeze(store.getState()); |
| 90 | |
| 91 | const softwareProductPostRequest = { |
| 92 | name: 'Pr1', |
| 93 | description: 'string' |
| 94 | }; |
| 95 | const softwareProductProcessToAdd = { |
| 96 | name: 'Pr1', |
| 97 | description: 'string', |
| 98 | formData: { |
| 99 | name: 'new artifact name' |
| 100 | } |
| 101 | }; |
| 102 | const softwareProductProcessFromResponse = 'ADDED_ID'; |
| 103 | const softwareProductProcessAfterAdd = { |
| 104 | ...softwareProductProcessToAdd, |
| 105 | id: softwareProductProcessFromResponse |
| 106 | }; |
| 107 | |
| 108 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', [softwareProductProcessAfterAdd]); |
| 109 | |
| 110 | mockRest.addHandler('create', ({data, options, baseUrl}) => { |
| 111 | expect(baseUrl).to.equal(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/processes`); |
| 112 | expect(data).to.deep.equal(softwareProductPostRequest); |
| 113 | expect(options).to.equal(undefined); |
| 114 | return { |
| 115 | returnCode: 'OK', |
| 116 | value: softwareProductProcessFromResponse |
| 117 | }; |
| 118 | }); |
| 119 | |
| 120 | mockRest.addHandler('create', ({data, options, baseUrl}) => { |
| 121 | expect(baseUrl).to.equal(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/processes/${softwareProductProcessAfterAdd.id}/upload`); |
| 122 | expect(data).to.deep.equal(softwareProductProcessToAdd.formData); |
| 123 | expect(options).to.equal(undefined); |
| 124 | return {returnCode: 'OK'}; |
| 125 | }); |
| 126 | |
| 127 | return SoftwareProductProcessesActionHelper.saveProcess(store.dispatch, |
| 128 | { |
| 129 | softwareProductId: softwareProductId, |
| 130 | previousProcess: null, |
| 131 | process: softwareProductProcessToAdd |
| 132 | } |
| 133 | ).then(() => { |
| 134 | expect(store.getState()).to.deep.equal(expectedStore); |
| 135 | }); |
| 136 | }); |
| 137 | |
| 138 | //** |
| 139 | //** UPDATE |
| 140 | //** |
| 141 | it('Update Software Products Processes', () => { |
| 142 | const softwareProductProcessesList = [ |
| 143 | { |
| 144 | name: 'Pr1', |
| 145 | description: 'string', |
| 146 | id: 'EBADF561B7FA4A788075E1840D0B5971', |
| 147 | artifactName: 'artifact' |
| 148 | } |
| 149 | ]; |
| 150 | deepFreeze(softwareProductProcessesList); |
| 151 | |
| 152 | const store = storeCreator({ |
| 153 | softwareProduct: { |
| 154 | softwareProductProcesses: { |
| 155 | processesList: softwareProductProcessesList |
| 156 | } |
| 157 | } |
| 158 | }); |
| 159 | deepFreeze(store.getState()); |
| 160 | |
| 161 | const toBeUpdatedProcessId = softwareProductProcessesList[0].id; |
| 162 | const previousProcessData = softwareProductProcessesList[0]; |
| 163 | const processUpdateData = { |
| 164 | ...softwareProductProcessesList[0], |
| 165 | name: 'Pr1_UPDATED', |
| 166 | description: 'string_UPDATED' |
| 167 | }; |
| 168 | deepFreeze(processUpdateData); |
| 169 | |
| 170 | const processPutRequest = { |
| 171 | name: 'Pr1_UPDATED', |
| 172 | description: 'string_UPDATED' |
| 173 | }; |
| 174 | deepFreeze(processPutRequest); |
| 175 | |
| 176 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', [processUpdateData]); |
| 177 | |
| 178 | |
| 179 | mockRest.addHandler('save', ({data, options, baseUrl}) => { |
| 180 | expect(baseUrl).to.equal(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/processes/${toBeUpdatedProcessId}`); |
| 181 | expect(data).to.deep.equal(processPutRequest); |
| 182 | expect(options).to.equal(undefined); |
| 183 | return {returnCode: 'OK'}; |
| 184 | }); |
| 185 | |
| 186 | return SoftwareProductProcessesActionHelper.saveProcess(store.dispatch, |
| 187 | { |
| 188 | softwareProductId: softwareProductId, |
| 189 | previousProcess: previousProcessData, |
| 190 | process: processUpdateData |
| 191 | } |
| 192 | ).then(() => { |
| 193 | expect(store.getState()).to.deep.equal(expectedStore); |
| 194 | }); |
| 195 | }); |
| 196 | |
| 197 | it('Update Software Products Processes and uploaded file', () => { |
| 198 | const previousProcessData = { |
| 199 | id: 'EBADF561B7FA4A788075E1840D0B5971', |
| 200 | name: 'p1', |
| 201 | description: 'string', |
| 202 | artifactName: 'artifact' |
| 203 | }; |
| 204 | deepFreeze(previousProcessData); |
| 205 | |
| 206 | const store = storeCreator({ |
| 207 | softwareProduct: { |
| 208 | softwareProductProcesses: { |
| 209 | processesList: [previousProcessData] |
| 210 | } |
| 211 | } |
| 212 | }); |
| 213 | deepFreeze(store.getState()); |
| 214 | |
| 215 | const newProcessToUpdate = { |
| 216 | ...previousProcessData, |
| 217 | name: 'new name', |
| 218 | formData: { |
| 219 | name: 'new artifact name' |
| 220 | } |
| 221 | }; |
| 222 | deepFreeze(newProcessToUpdate); |
| 223 | |
| 224 | const newProcessToPutRequest = { |
| 225 | name: newProcessToUpdate.name, |
| 226 | description: previousProcessData.description |
| 227 | }; |
| 228 | deepFreeze(newProcessToPutRequest); |
| 229 | |
| 230 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', [newProcessToUpdate]); |
| 231 | |
| 232 | mockRest.addHandler('save', ({data, options, baseUrl}) => { |
| 233 | expect(baseUrl).to.equal(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/processes/${previousProcessData.id}`); |
| 234 | expect(data).to.deep.equal(newProcessToPutRequest); |
| 235 | expect(options).to.equal(undefined); |
| 236 | return {returnCode: 'OK'}; |
| 237 | }); |
| 238 | |
| 239 | mockRest.addHandler('create', ({data, options, baseUrl}) => { |
| 240 | expect(baseUrl).to.equal(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/processes/${previousProcessData.id}/upload`); |
| 241 | expect(data).to.deep.equal(newProcessToUpdate.formData); |
| 242 | expect(options).to.equal(undefined); |
| 243 | return {returnCode: 'OK'}; |
| 244 | }); |
| 245 | |
| 246 | return SoftwareProductProcessesActionHelper.saveProcess(store.dispatch, |
| 247 | { |
| 248 | softwareProductId: softwareProductId, |
| 249 | previousProcess: previousProcessData, |
| 250 | process: newProcessToUpdate |
| 251 | } |
| 252 | ).then(() => { |
| 253 | expect(store.getState()).to.deep.equal(expectedStore); |
| 254 | }); |
| 255 | }); |
| 256 | |
| 257 | //** |
| 258 | //** GET |
| 259 | //** |
| 260 | it('Get Software Products Processes List', () => { |
| 261 | const store = storeCreator(); |
| 262 | deepFreeze(store.getState()); |
| 263 | |
| 264 | const softwareProductProcessesList = [ |
| 265 | { |
| 266 | name: 'Pr1', |
| 267 | description: 'hjhj', |
| 268 | id: 'EBADF561B7FA4A788075E1840D0B5971', |
| 269 | artifactName: 'artifact' |
| 270 | }, |
| 271 | { |
| 272 | name: 'Pr1', |
| 273 | description: 'hjhj', |
| 274 | id: '2F47447D22DB4C53B020CA1E66201EF2', |
| 275 | artifactName: 'artifact' |
| 276 | } |
| 277 | ]; |
| 278 | |
| 279 | deepFreeze(softwareProductProcessesList); |
| 280 | |
| 281 | deepFreeze(store.getState()); |
| 282 | |
| 283 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', softwareProductProcessesList); |
| 284 | |
| 285 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 286 | expect(baseUrl).to.equal(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/processes`); |
| 287 | expect(data).to.deep.equal(undefined); |
| 288 | expect(options).to.equal(undefined); |
| 289 | return {results: softwareProductProcessesList}; |
| 290 | }); |
| 291 | |
| 292 | return SoftwareProductProcessesActionHelper.fetchProcessesList(store.dispatch, {softwareProductId}).then(() => { |
| 293 | expect(store.getState()).to.deep.equal(expectedStore); |
| 294 | }); |
| 295 | }); |
| 296 | |
| 297 | //** |
| 298 | //** DELETE |
| 299 | //** |
| 300 | it('Delete Software Products Processes', () => { |
| 301 | const softwareProductProcessesList = [ |
| 302 | { |
| 303 | name: 'Pr1', |
| 304 | description: 'hjhj', |
| 305 | id: 'EBADF561B7FA4A788075E1840D0B5971', |
| 306 | artifactName: 'artifact' |
| 307 | } |
| 308 | ]; |
| 309 | |
| 310 | deepFreeze(softwareProductProcessesList); |
| 311 | const store = storeCreator({ |
| 312 | softwareProduct: { |
| 313 | softwareProductProcesses: { |
| 314 | processesList: softwareProductProcessesList |
| 315 | } |
| 316 | } |
| 317 | }); |
| 318 | |
| 319 | const processId = 'EBADF561B7FA4A788075E1840D0B5971'; |
| 320 | deepFreeze(store.getState()); |
| 321 | |
| 322 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesList', []); |
| 323 | |
| 324 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
| 325 | expect(baseUrl).to.equal(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/processes/${processId}`); |
| 326 | expect(data).to.equal(undefined); |
| 327 | expect(options).to.equal(undefined); |
| 328 | return { |
| 329 | results: { |
| 330 | returnCode: 'OK' |
| 331 | } |
| 332 | }; |
| 333 | }); |
| 334 | |
| 335 | return SoftwareProductProcessesActionHelper.deleteProcess(store.dispatch, { |
| 336 | process: softwareProductProcessesList[0], |
| 337 | softwareProductId |
| 338 | }).then(() => { |
| 339 | expect(store.getState()).to.deep.equal(expectedStore); |
| 340 | }); |
| 341 | }); |
| 342 | |
| 343 | it('Validating Software Products Processes Delete confirmation', done => { |
| 344 | const store = storeCreator(); |
| 345 | deepFreeze(store.getState()); |
| 346 | |
| 347 | let process = { |
| 348 | id: 'p_id', |
| 349 | name: 'p_name' |
| 350 | }; |
| 351 | deepFreeze(process); |
| 352 | |
| 353 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processToDelete', process); |
| 354 | |
| 355 | SoftwareProductProcessesActionHelper.openDeleteProcessesConfirm(store.dispatch, {process}); |
| 356 | |
| 357 | setTimeout(function(){ |
| 358 | expect(store.getState()).to.deep.equal(expectedStore); |
| 359 | 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(){ |
| 372 | expect(store.getState()).to.deep.equal(expectedStore); |
| 373 | done(); |
| 374 | }, 100); |
| 375 | }); |
| 376 | |
| 377 | //** |
| 378 | //** CREATE/EDIT |
| 379 | //** |
| 380 | it('Validating open Software Products Processes for create', done => { |
| 381 | 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); |
| 390 | |
| 391 | setTimeout(function(){ |
| 392 | expect(store.getState()).to.deep.equal(expectedStore); |
| 393 | done(); |
| 394 | }, 100); |
| 395 | }); |
| 396 | |
| 397 | it('Validating close Software Products Processes from editing mode', done => { |
| 398 | const store = storeCreator(); |
| 399 | deepFreeze(store.getState()); |
| 400 | |
| 401 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesEditor', {}); |
| 402 | |
| 403 | SoftwareProductProcessesActionHelper.closeEditor(store.dispatch); |
| 404 | |
| 405 | setTimeout(function(){ |
| 406 | expect(store.getState()).to.deep.equal(expectedStore); |
| 407 | done(); |
| 408 | }, 100); |
| 409 | }); |
| 410 | |
| 411 | it('Validating open Software Products Processes for editing', done => { |
| 412 | const store = storeCreator(); |
| 413 | deepFreeze(store.getState()); |
| 414 | |
| 415 | let process = {name: 'aa', description: 'xx'}; |
| 416 | deepFreeze(process); |
| 417 | |
| 418 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesEditor.data', process); |
| 419 | |
| 420 | SoftwareProductProcessesActionHelper.openEditor(store.dispatch, process); |
| 421 | |
| 422 | setTimeout(function(){ |
| 423 | expect(store.getState()).to.deep.equal(expectedStore); |
| 424 | done(); |
| 425 | }, 100); |
| 426 | }); |
| 427 | |
| 428 | it('Validating Software Products Processes dataChanged event', done => { |
| 429 | let process = {name: 'aa', description: 'xx'}; |
| 430 | deepFreeze(process); |
| 431 | |
| 432 | const store = storeCreator({ |
| 433 | softwareProduct: { |
| 434 | softwareProductProcesses: { |
| 435 | processesEditor: { |
| 436 | data: process |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | }); |
| 441 | deepFreeze(store.getState()); |
| 442 | |
| 443 | let deltaData = {name: 'bb'}; |
| 444 | deepFreeze(deltaData); |
| 445 | |
| 446 | let expectedProcess = {name: 'bb', description: 'xx'}; |
| 447 | deepFreeze(expectedProcess); |
| 448 | |
| 449 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductProcesses.processesEditor.data', expectedProcess); |
| 450 | |
| 451 | SoftwareProductProcessesActionHelper.processEditorDataChanged(store.dispatch, {deltaData}); |
| 452 | |
| 453 | setTimeout(function(){ |
| 454 | expect(store.getState()).to.deep.equal(expectedStore); |
| 455 | done(); |
| 456 | }, 100); |
| 457 | }); |
| 458 | }); |
| 459 | |