Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 4 | * 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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 7 | * |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import deepFreeze from 'deep-freeze'; |
| 17 | import mockRest from 'test-utils/MockRest.js'; |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 18 | import { cloneAndSet } from 'test-utils/Util.js'; |
| 19 | import { storeCreator } from 'sdc-app/AppStore.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 20 | import Configuration from 'sdc-app/config/Configuration.js'; |
| 21 | import SoftwareProductProcessesActionHelper from 'sdc-app/onboarding/softwareProduct/processes/SoftwareProductProcessesActionHelper.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 22 | import { |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 23 | VSPProcessPostFactory, |
| 24 | VSPProcessStoreFactory, |
| 25 | VSPProcessPostFactoryWithType, |
| 26 | VSPProcessStoreFactoryWithType, |
| 27 | VSPProcessStoreWithFormDataFactory, |
| 28 | VSPProcessPostWithFormDataFactory, |
| 29 | VSPProcessStoreWithArtifactNameFactory |
| 30 | } from 'test-utils/factories/softwareProduct/SoftwareProductProcessFactories.js'; |
| 31 | import { buildFromExistingObject } from 'test-utils/Util.js'; |
| 32 | import { VSPEditorFactory } from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 33 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 34 | |
| 35 | const softwareProductId = '123'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 36 | const version = VersionFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 37 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 38 | describe('Software Product Processes Module Tests', function() { |
| 39 | let restPrefix = ''; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 40 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 41 | beforeAll(function() { |
| 42 | restPrefix = Configuration.get('restPrefix'); |
| 43 | deepFreeze(restPrefix); |
| 44 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 45 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 46 | //** |
| 47 | //** ADD |
| 48 | //** |
| 49 | it('Add Software Products Processes', () => { |
| 50 | const store = storeCreator(); |
| 51 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 52 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 53 | const softwareProductProcessFromResponse = 'ADDED_ID'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 54 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 55 | const softwareProductProcessAfterAdd = VSPProcessStoreFactory.build({ |
| 56 | id: softwareProductProcessFromResponse |
| 57 | }); |
| 58 | const softwareProductPostRequest = buildFromExistingObject( |
| 59 | VSPProcessPostFactory, |
| 60 | softwareProductProcessAfterAdd |
| 61 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 62 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 63 | const expectedStore = cloneAndSet( |
| 64 | store.getState(), |
| 65 | 'softwareProduct.softwareProductProcesses.processesList', |
| 66 | [softwareProductProcessAfterAdd] |
| 67 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 68 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 69 | mockRest.addHandler('post', ({ data, options, baseUrl }) => { |
| 70 | expect(baseUrl).toEqual( |
| 71 | `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${ |
| 72 | version.id |
| 73 | }/processes` |
| 74 | ); |
| 75 | expect(data).toEqual(softwareProductPostRequest); |
| 76 | expect(options).toEqual(undefined); |
| 77 | return { |
| 78 | returnCode: 'OK', |
| 79 | value: softwareProductProcessFromResponse |
| 80 | }; |
| 81 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 82 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 83 | return SoftwareProductProcessesActionHelper.saveProcess( |
| 84 | store.dispatch, |
| 85 | { |
| 86 | softwareProductId, |
| 87 | version, |
| 88 | previousProcess: null, |
| 89 | process: softwareProductPostRequest |
| 90 | } |
| 91 | ).then(() => { |
| 92 | expect(store.getState()).toEqual(expectedStore); |
| 93 | }); |
| 94 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 95 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 96 | it('Add Software Products Processes with type', () => { |
| 97 | const store = storeCreator(); |
| 98 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 99 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 100 | const softwareProductProcessFromResponse = 'ADDED_ID'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 101 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 102 | const softwareProductProcessAfterAdd = VSPProcessStoreFactoryWithType.build( |
| 103 | { id: softwareProductProcessFromResponse } |
| 104 | ); |
| 105 | const softwareProductPostRequest = buildFromExistingObject( |
| 106 | VSPProcessPostFactoryWithType, |
| 107 | softwareProductProcessAfterAdd |
| 108 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 109 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 110 | const expectedStore = cloneAndSet( |
| 111 | store.getState(), |
| 112 | 'softwareProduct.softwareProductProcesses.processesList', |
| 113 | [softwareProductProcessAfterAdd] |
| 114 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 115 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 116 | mockRest.addHandler('post', ({ data, options, baseUrl }) => { |
| 117 | expect(baseUrl).toEqual( |
| 118 | `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${ |
| 119 | version.id |
| 120 | }/processes` |
| 121 | ); |
| 122 | expect(data).toEqual(softwareProductPostRequest); |
| 123 | expect(options).toEqual(undefined); |
| 124 | return { |
| 125 | returnCode: 'OK', |
| 126 | value: softwareProductProcessFromResponse |
| 127 | }; |
| 128 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 129 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 130 | return SoftwareProductProcessesActionHelper.saveProcess( |
| 131 | store.dispatch, |
| 132 | { |
| 133 | softwareProductId, |
| 134 | version, |
| 135 | previousProcess: null, |
| 136 | process: softwareProductPostRequest |
| 137 | } |
| 138 | ).then(() => { |
| 139 | expect(store.getState()).toEqual(expectedStore); |
| 140 | }); |
| 141 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 142 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 143 | it('Add Software Products Processes with uploaded file', () => { |
| 144 | const store = storeCreator(); |
| 145 | deepFreeze(store.getState()); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 146 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 147 | const softwareProductPostRequest = VSPProcessPostFactoryWithType.build(); |
| 148 | const softwareProductProcessToAdd = VSPProcessPostWithFormDataFactory.build( |
| 149 | softwareProductPostRequest |
| 150 | ); |
| 151 | const softwareProductProcessAfterAdd = VSPProcessStoreWithFormDataFactory.build(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 152 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 153 | const expectedStore = cloneAndSet( |
| 154 | store.getState(), |
| 155 | 'softwareProduct.softwareProductProcesses.processesList', |
| 156 | [softwareProductProcessAfterAdd] |
| 157 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 158 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 159 | mockRest.addHandler('post', ({ data, options, baseUrl }) => { |
| 160 | expect(baseUrl).toEqual( |
| 161 | `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${ |
| 162 | version.id |
| 163 | }/processes` |
| 164 | ); |
| 165 | expect(data).toEqual(softwareProductPostRequest); |
| 166 | expect(options).toEqual(undefined); |
| 167 | return { |
| 168 | returnCode: 'OK', |
| 169 | value: softwareProductProcessAfterAdd.id |
| 170 | }; |
| 171 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 172 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 173 | mockRest.addHandler('post', ({ data, options, baseUrl }) => { |
| 174 | expect(baseUrl).toEqual( |
| 175 | `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${ |
| 176 | version.id |
| 177 | }/processes/${softwareProductProcessAfterAdd.id}/upload` |
| 178 | ); |
| 179 | expect(data).toEqual(softwareProductProcessToAdd.formData); |
| 180 | expect(options).toEqual(undefined); |
| 181 | return { returnCode: 'OK' }; |
| 182 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 183 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 184 | return SoftwareProductProcessesActionHelper.saveProcess( |
| 185 | store.dispatch, |
| 186 | { |
| 187 | softwareProductId, |
| 188 | version, |
| 189 | previousProcess: null, |
| 190 | process: softwareProductProcessToAdd |
| 191 | } |
| 192 | ).then(() => { |
| 193 | expect(store.getState()).toEqual(expectedStore); |
| 194 | }); |
| 195 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 196 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 197 | //** |
| 198 | //** UPDATE |
| 199 | //** |
| 200 | it('Update Software Products Processes', () => { |
| 201 | const softwareProductProcessesList = VSPProcessStoreWithArtifactNameFactory.buildList( |
| 202 | 1 |
| 203 | ); |
| 204 | deepFreeze(softwareProductProcessesList); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 205 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 206 | const store = storeCreator({ |
| 207 | softwareProduct: { |
| 208 | softwareProductProcesses: { |
| 209 | processesList: softwareProductProcessesList |
| 210 | } |
| 211 | } |
| 212 | }); |
| 213 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 214 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 215 | const toBeUpdatedProcessId = softwareProductProcessesList[0].id; |
| 216 | const previousProcessData = softwareProductProcessesList[0]; |
| 217 | const processUpdateData = VSPProcessStoreWithArtifactNameFactory.build({ |
| 218 | ...previousProcessData, |
| 219 | name: 'Pr1_UPDATED', |
| 220 | description: 'string_UPDATED', |
| 221 | type: 'Other' |
| 222 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 223 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 224 | deepFreeze(processUpdateData); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 225 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 226 | const processPutRequest = VSPProcessPostFactory.build({ |
| 227 | name: 'Pr1_UPDATED', |
| 228 | description: 'string_UPDATED', |
| 229 | type: 'Other' |
| 230 | }); |
| 231 | deepFreeze(processPutRequest); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 232 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 233 | const expectedStore = cloneAndSet( |
| 234 | store.getState(), |
| 235 | 'softwareProduct.softwareProductProcesses.processesList', |
| 236 | [processUpdateData] |
| 237 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 238 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 239 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 240 | expect(baseUrl).toEqual( |
| 241 | `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${ |
| 242 | version.id |
| 243 | }/processes/${toBeUpdatedProcessId}` |
| 244 | ); |
| 245 | expect(data).toEqual(processPutRequest); |
| 246 | expect(options).toEqual(undefined); |
| 247 | return { returnCode: 'OK' }; |
| 248 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 249 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 250 | return SoftwareProductProcessesActionHelper.saveProcess( |
| 251 | store.dispatch, |
| 252 | { |
| 253 | softwareProductId, |
| 254 | version, |
| 255 | previousProcess: previousProcessData, |
| 256 | process: processUpdateData |
| 257 | } |
| 258 | ).then(() => { |
| 259 | expect(store.getState()).toEqual(expectedStore); |
| 260 | }); |
| 261 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 262 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 263 | it('Update Software Products Processes and uploaded file', () => { |
| 264 | const previousProcessData = VSPProcessStoreWithArtifactNameFactory.build(); |
| 265 | deepFreeze(previousProcessData); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 266 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 267 | const store = storeCreator({ |
| 268 | softwareProduct: { |
| 269 | softwareProductProcesses: { |
| 270 | processesList: [previousProcessData] |
| 271 | } |
| 272 | } |
| 273 | }); |
| 274 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 275 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 276 | const newProcessToUpdate = VSPProcessStoreWithFormDataFactory.build({ |
| 277 | ...previousProcessData, |
| 278 | name: 'new name', |
| 279 | formData: { |
| 280 | name: 'new artifact name' |
| 281 | } |
| 282 | }); |
| 283 | deepFreeze(newProcessToUpdate); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 284 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 285 | const newProcessToPutRequest = VSPProcessPostFactory.build({ |
| 286 | name: newProcessToUpdate.name, |
| 287 | description: previousProcessData.description, |
| 288 | type: previousProcessData.type |
| 289 | }); |
| 290 | deepFreeze(newProcessToPutRequest); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 291 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 292 | const expectedStore = cloneAndSet( |
| 293 | store.getState(), |
| 294 | 'softwareProduct.softwareProductProcesses.processesList', |
| 295 | [newProcessToUpdate] |
| 296 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 297 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 298 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 299 | expect(baseUrl).toEqual( |
| 300 | `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${ |
| 301 | version.id |
| 302 | }/processes/${newProcessToUpdate.id}` |
| 303 | ); |
| 304 | expect(data).toEqual(newProcessToPutRequest); |
| 305 | expect(options).toEqual(undefined); |
| 306 | return { returnCode: 'OK' }; |
| 307 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 308 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 309 | mockRest.addHandler('post', ({ data, options, baseUrl }) => { |
| 310 | expect(baseUrl).toEqual( |
| 311 | `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${ |
| 312 | version.id |
| 313 | }/processes/${newProcessToUpdate.id}/upload` |
| 314 | ); |
| 315 | expect(data).toEqual(newProcessToUpdate.formData); |
| 316 | expect(options).toEqual(undefined); |
| 317 | return { returnCode: 'OK' }; |
| 318 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 319 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 320 | return SoftwareProductProcessesActionHelper.saveProcess( |
| 321 | store.dispatch, |
| 322 | { |
| 323 | softwareProductId, |
| 324 | version, |
| 325 | previousProcess: previousProcessData, |
| 326 | process: newProcessToUpdate |
| 327 | } |
| 328 | ).then(() => { |
| 329 | expect(store.getState()).toEqual(expectedStore); |
| 330 | }); |
| 331 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 332 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 333 | //** |
| 334 | //** GET |
| 335 | //** |
| 336 | it('Get Software Products Processes List', () => { |
| 337 | const store = storeCreator(); |
| 338 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 339 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 340 | const softwareProductProcessesList = VSPProcessStoreFactory.buildList( |
| 341 | 2 |
| 342 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 343 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 344 | deepFreeze(softwareProductProcessesList); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 345 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 346 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 347 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 348 | const expectedStore = cloneAndSet( |
| 349 | store.getState(), |
| 350 | 'softwareProduct.softwareProductProcesses.processesList', |
| 351 | softwareProductProcessesList |
| 352 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 353 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 354 | mockRest.addHandler('fetch', ({ options, data, baseUrl }) => { |
| 355 | expect(baseUrl).toEqual( |
| 356 | `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${ |
| 357 | version.id |
| 358 | }/processes` |
| 359 | ); |
| 360 | expect(data).toEqual(undefined); |
| 361 | expect(options).toEqual(undefined); |
| 362 | return { results: softwareProductProcessesList }; |
| 363 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 364 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 365 | return SoftwareProductProcessesActionHelper.fetchProcessesList( |
| 366 | store.dispatch, |
| 367 | { softwareProductId, version } |
| 368 | ).then(() => { |
| 369 | expect(store.getState()).toEqual(expectedStore); |
| 370 | }); |
| 371 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 372 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 373 | //** |
| 374 | //** DELETE |
| 375 | //** |
| 376 | it('Delete Software Products Processes', () => { |
| 377 | const softwareProductProcessesList = VSPProcessStoreWithArtifactNameFactory.buildList( |
| 378 | 1 |
| 379 | ); |
| 380 | const currentSoftwareProduct = VSPEditorFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 381 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 382 | deepFreeze(softwareProductProcessesList); |
| 383 | const store = storeCreator({ |
| 384 | softwareProduct: { |
| 385 | softwareProductProcesses: { |
| 386 | processesList: softwareProductProcessesList |
| 387 | }, |
| 388 | softwareProductEditor: { |
| 389 | data: currentSoftwareProduct |
| 390 | } |
| 391 | } |
| 392 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 393 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 394 | const processId = softwareProductProcessesList[0].id; |
| 395 | const versionId = version.id; |
| 396 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 397 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 398 | const expectedStore = cloneAndSet( |
| 399 | store.getState(), |
| 400 | 'softwareProduct.softwareProductProcesses.processesList', |
| 401 | [] |
| 402 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 403 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 404 | mockRest.addHandler('destroy', ({ data, options, baseUrl }) => { |
| 405 | expect(baseUrl).toEqual( |
| 406 | `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/processes/${processId}` |
| 407 | ); |
| 408 | expect(data).toEqual(undefined); |
| 409 | expect(options).toEqual(undefined); |
| 410 | return { |
| 411 | results: { |
| 412 | returnCode: 'OK' |
| 413 | } |
| 414 | }; |
| 415 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 416 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 417 | return SoftwareProductProcessesActionHelper.deleteProcess( |
| 418 | store.dispatch, |
| 419 | { |
| 420 | process: softwareProductProcessesList[0], |
| 421 | softwareProductId, |
| 422 | version |
| 423 | } |
| 424 | ).then(() => { |
| 425 | expect(store.getState()).toEqual(expectedStore); |
| 426 | }); |
| 427 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 428 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 429 | it('Validating Software Products Processes Delete confirmation', () => { |
| 430 | const store = storeCreator(); |
| 431 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 432 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 433 | let process = VSPProcessStoreFactory.build(); |
| 434 | deepFreeze(process); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 435 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 436 | const expectedStore = cloneAndSet( |
| 437 | store.getState(), |
| 438 | 'softwareProduct.softwareProductProcesses.processToDelete', |
| 439 | process |
| 440 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 441 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 442 | return SoftwareProductProcessesActionHelper.openDeleteProcessesConfirm( |
| 443 | store.dispatch, |
| 444 | { process } |
| 445 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 446 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 447 | expect(store.getState()).toEqual(expectedStore); |
| 448 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 449 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 450 | it('Validating Software Products Processes Cancel Delete', () => { |
| 451 | const store = storeCreator(); |
| 452 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 453 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 454 | const expectedStore = cloneAndSet( |
| 455 | store.getState(), |
| 456 | 'softwareProduct.softwareProductProcesses.processToDelete', |
| 457 | false |
| 458 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 459 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 460 | SoftwareProductProcessesActionHelper.hideDeleteConfirm(store.dispatch); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 461 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 462 | expect(store.getState()).toEqual(expectedStore); |
| 463 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 464 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 465 | //** |
| 466 | //** CREATE/EDIT |
| 467 | //** |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 468 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 469 | it('Validating close Software Products Processes from editing mode', () => { |
| 470 | const store = storeCreator(); |
| 471 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 472 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 473 | const expectedStore = cloneAndSet( |
| 474 | store.getState(), |
| 475 | 'softwareProduct.softwareProductProcesses.processesEditor', |
| 476 | {} |
| 477 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 478 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 479 | SoftwareProductProcessesActionHelper.closeEditor(store.dispatch); |
| 480 | expect(store.getState()).toEqual(expectedStore); |
| 481 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 482 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 483 | it('Validating open Software Products Processes for editing', () => { |
| 484 | const store = storeCreator(); |
| 485 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 486 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 487 | let process = { name: 'aa', description: 'xx' }; |
| 488 | deepFreeze(process); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 489 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 490 | const expectedStore = cloneAndSet( |
| 491 | store.getState(), |
| 492 | 'softwareProduct.softwareProductProcesses.processesEditor.data', |
| 493 | process |
| 494 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 495 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame^] | 496 | SoftwareProductProcessesActionHelper.openEditor(store.dispatch, { |
| 497 | process |
| 498 | }); |
| 499 | expect( |
| 500 | store.getState().softwareProduct.softwareProductProcesses |
| 501 | .processesEditor.data |
| 502 | ).toEqual( |
| 503 | expectedStore.softwareProduct.softwareProductProcesses |
| 504 | .processesEditor.data |
| 505 | ); |
| 506 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 507 | }); |