svishnev | 57c5c4a | 2018-04-22 14:14:31 +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 |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 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, |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +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'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 17 | import mockRest from 'test-utils/MockRest.js'; |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 18 | import { cloneAndSet, buildListFromFactory } 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 EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js'; |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 21 | import { |
| 22 | EntitlementPoolStoreFactory, |
| 23 | EntitlementPoolPostFactory |
| 24 | } from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 25 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 26 | import { |
| 27 | LimitItemFactory, |
| 28 | LimitPostFactory |
| 29 | } from 'test-utils/factories/licenseModel/LimitFactories.js'; |
| 30 | import { getStrValue } from 'nfvo-utils/getValue.js'; |
| 31 | import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 32 | import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 33 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 34 | describe('Entitlement Pools Module Tests', function() { |
| 35 | const LICENSE_MODEL_ID = '555'; |
| 36 | const version = VersionFactory.build(); |
| 37 | const itemPermissionAndProps = CurrentScreenFactory.build({}, { version }); |
| 38 | const returnedVersionFields = { |
| 39 | baseId: version.baseId, |
| 40 | description: version.description, |
| 41 | id: version.id, |
| 42 | name: version.name, |
| 43 | status: version.status |
| 44 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 45 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 46 | it('Load Entitlement Pools List', () => { |
| 47 | const entitlementPoolsList = buildListFromFactory( |
| 48 | EntitlementPoolStoreFactory |
| 49 | ); |
| 50 | deepFreeze(entitlementPoolsList); |
| 51 | const store = storeCreator(); |
| 52 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 53 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 54 | const expectedStore = cloneAndSet( |
| 55 | store.getState(), |
| 56 | 'licenseModel.entitlementPool.entitlementPoolsList', |
| 57 | entitlementPoolsList |
| 58 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 59 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 60 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 61 | expect(baseUrl).toEqual( |
| 62 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 63 | version.id |
| 64 | }/entitlement-pools` |
| 65 | ); |
| 66 | expect(data).toEqual(undefined); |
| 67 | expect(options).toEqual(undefined); |
| 68 | return { results: entitlementPoolsList }; |
| 69 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 70 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 71 | return EntitlementPoolsActionHelper.fetchEntitlementPoolsList( |
| 72 | store.dispatch, |
| 73 | { licenseModelId: LICENSE_MODEL_ID, version } |
| 74 | ).then(() => { |
| 75 | expect(store.getState()).toEqual(expectedStore); |
| 76 | }); |
| 77 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 78 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 79 | it('Delete Entitlement Pool', () => { |
| 80 | const entitlementPoolsList = buildListFromFactory( |
| 81 | EntitlementPoolStoreFactory, |
| 82 | 1 |
| 83 | ); |
| 84 | deepFreeze(entitlementPoolsList); |
| 85 | const store = storeCreator({ |
| 86 | currentScreen: { ...itemPermissionAndProps }, |
| 87 | licenseModel: { |
| 88 | entitlementPool: { |
| 89 | entitlementPoolsList |
| 90 | } |
| 91 | } |
| 92 | }); |
| 93 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 94 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 95 | const expectedCurrentScreenProps = { |
| 96 | ...itemPermissionAndProps, |
| 97 | itemPermission: { |
| 98 | ...itemPermissionAndProps.itemPermission, |
| 99 | isDirty: true |
| 100 | } |
| 101 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 102 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 103 | let expectedStore = cloneAndSet( |
| 104 | store.getState(), |
| 105 | 'licenseModel.entitlementPool.entitlementPoolsList', |
| 106 | [] |
| 107 | ); |
| 108 | expectedStore = cloneAndSet( |
| 109 | expectedStore, |
| 110 | 'currentScreen.itemPermission', |
| 111 | expectedCurrentScreenProps.itemPermission |
| 112 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 113 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 114 | mockRest.addHandler('destroy', ({ data, options, baseUrl }) => { |
| 115 | expect(baseUrl).toEqual( |
| 116 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 117 | version.id |
| 118 | }/entitlement-pools/${entitlementPoolsList[0].id}` |
| 119 | ); |
| 120 | expect(data).toEqual(undefined); |
| 121 | expect(options).toEqual(undefined); |
| 122 | return { |
| 123 | results: { |
| 124 | returnCode: 'OK' |
| 125 | } |
| 126 | }; |
| 127 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 128 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 129 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 130 | expect(baseUrl).toEqual( |
| 131 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 132 | version.id |
| 133 | }` |
| 134 | ); |
| 135 | expect(data).toEqual(undefined); |
| 136 | expect(options).toEqual(undefined); |
| 137 | return { |
| 138 | ...returnedVersionFields, |
| 139 | state: { |
| 140 | synchronizationState: SyncStates.UP_TO_DATE, |
| 141 | dirty: true |
| 142 | } |
| 143 | }; |
| 144 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 145 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 146 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 147 | expect(baseUrl).toEqual( |
| 148 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 149 | ); |
| 150 | expect(data).toEqual(undefined); |
| 151 | expect(options).toEqual(undefined); |
| 152 | return { |
| 153 | ...returnedVersionFields |
| 154 | }; |
| 155 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 156 | |
svishnev | 8f13330 | 2018-08-06 23:08:39 +0300 | [diff] [blame] | 157 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 158 | expect(baseUrl).toEqual( |
| 159 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 160 | version.id |
| 161 | }/entitlement-pools` |
| 162 | ); |
| 163 | expect(data).toEqual(undefined); |
| 164 | expect(options).toEqual(undefined); |
| 165 | return { results: [] }; |
| 166 | }); |
| 167 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 168 | return EntitlementPoolsActionHelper.deleteEntitlementPool( |
| 169 | store.dispatch, |
| 170 | { |
| 171 | licenseModelId: LICENSE_MODEL_ID, |
| 172 | version, |
| 173 | entitlementPoolId: entitlementPoolsList[0].id |
| 174 | } |
| 175 | ).then(() => { |
| 176 | expect(store.getState()).toEqual(expectedStore); |
| 177 | }); |
| 178 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 179 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 180 | it('Add Entitlement Pool', () => { |
| 181 | const store = storeCreator({ |
| 182 | currentScreen: { ...itemPermissionAndProps } |
| 183 | }); |
| 184 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 185 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 186 | const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 187 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 188 | deepFreeze(EntitlementPoolPostRequest); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 189 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 190 | const entitlementPoolIdFromResponse = 'ADDED_ID'; |
| 191 | const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({ |
| 192 | id: entitlementPoolIdFromResponse |
| 193 | }); |
| 194 | deepFreeze(entitlementPoolAfterAdd); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 195 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 196 | const expectedCurrentScreenProps = { |
| 197 | ...itemPermissionAndProps, |
| 198 | itemPermission: { |
| 199 | ...itemPermissionAndProps.itemPermission, |
| 200 | isDirty: true |
| 201 | } |
| 202 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 203 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 204 | let expectedStore = cloneAndSet( |
| 205 | store.getState(), |
| 206 | 'licenseModel.entitlementPool.entitlementPoolsList', |
| 207 | [entitlementPoolAfterAdd] |
| 208 | ); |
| 209 | expectedStore = cloneAndSet( |
| 210 | expectedStore, |
| 211 | 'currentScreen.itemPermission', |
| 212 | expectedCurrentScreenProps.itemPermission |
| 213 | ); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 214 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 215 | mockRest.addHandler('post', ({ data, options, baseUrl }) => { |
| 216 | expect(baseUrl).toEqual( |
| 217 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 218 | version.id |
| 219 | }/entitlement-pools` |
| 220 | ); |
| 221 | expect(data).toEqual(EntitlementPoolPostRequest); |
| 222 | expect(options).toEqual(undefined); |
| 223 | return { |
| 224 | returnCode: 'OK', |
| 225 | value: entitlementPoolIdFromResponse |
| 226 | }; |
| 227 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 228 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 229 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 230 | expect(baseUrl).toEqual( |
| 231 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 232 | version.id |
| 233 | }` |
| 234 | ); |
| 235 | expect(data).toEqual(undefined); |
| 236 | expect(options).toEqual(undefined); |
| 237 | return { |
| 238 | ...returnedVersionFields, |
| 239 | state: { |
| 240 | synchronizationState: SyncStates.UP_TO_DATE, |
| 241 | dirty: true |
| 242 | } |
| 243 | }; |
| 244 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 245 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 246 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 247 | expect(baseUrl).toEqual( |
| 248 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 249 | ); |
| 250 | expect(data).toEqual(undefined); |
| 251 | expect(options).toEqual(undefined); |
| 252 | return { |
| 253 | ...returnedVersionFields |
| 254 | }; |
| 255 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 256 | |
svishnev | 8f13330 | 2018-08-06 23:08:39 +0300 | [diff] [blame] | 257 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 258 | expect(baseUrl).toEqual( |
| 259 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 260 | version.id |
| 261 | }/entitlement-pools` |
| 262 | ); |
| 263 | expect(data).toEqual(undefined); |
| 264 | expect(options).toEqual(undefined); |
| 265 | return { results: [entitlementPoolAfterAdd] }; |
| 266 | }); |
| 267 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 268 | return EntitlementPoolsActionHelper.saveEntitlementPool( |
| 269 | store.dispatch, |
| 270 | { |
| 271 | licenseModelId: LICENSE_MODEL_ID, |
| 272 | version, |
| 273 | previousEntitlementPool: null, |
| 274 | entitlementPool: EntitlementPoolPostRequest |
| 275 | } |
| 276 | ).then(() => { |
| 277 | expect(store.getState()).toEqual(expectedStore); |
| 278 | }); |
| 279 | }); |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 280 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 281 | it('Update Entitlement Pool', () => { |
| 282 | const entitlementPoolsList = buildListFromFactory( |
| 283 | EntitlementPoolStoreFactory, |
| 284 | 1 |
| 285 | ); |
| 286 | deepFreeze(entitlementPoolsList); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 287 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 288 | const store = storeCreator({ |
| 289 | currentScreen: { ...itemPermissionAndProps }, |
| 290 | licenseModel: { |
| 291 | entitlementPool: { |
| 292 | entitlementPoolsList |
| 293 | } |
| 294 | } |
| 295 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 296 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 297 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 298 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 299 | const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id; |
| 300 | const previousEntitlementPoolData = entitlementPoolsList[0]; |
| 301 | const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({ |
| 302 | name: 'ep1_UPDATED', |
| 303 | description: 'string_UPDATED', |
| 304 | id: toBeUpdatedEntitlementPoolId |
| 305 | }); |
| 306 | deepFreeze(entitlementPoolUpdateData); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 307 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 308 | const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({ |
| 309 | name: 'ep1_UPDATED', |
| 310 | description: 'string_UPDATED' |
| 311 | }); |
| 312 | deepFreeze(entitlementPoolPutRequest); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 313 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 314 | const expectedCurrentScreenProps = { |
| 315 | ...itemPermissionAndProps, |
| 316 | itemPermission: { |
| 317 | ...itemPermissionAndProps.itemPermission, |
| 318 | isDirty: true |
| 319 | } |
| 320 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 321 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 322 | let expectedStore = cloneAndSet( |
| 323 | store.getState(), |
| 324 | 'licenseModel.entitlementPool.entitlementPoolsList', |
| 325 | [entitlementPoolUpdateData] |
| 326 | ); |
| 327 | expectedStore = cloneAndSet( |
| 328 | expectedStore, |
| 329 | 'currentScreen.itemPermission', |
| 330 | expectedCurrentScreenProps.itemPermission |
| 331 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 332 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 333 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 334 | expect(baseUrl).toEqual( |
| 335 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 336 | version.id |
| 337 | }/entitlement-pools/${toBeUpdatedEntitlementPoolId}` |
| 338 | ); |
| 339 | expect(data).toEqual(entitlementPoolPutRequest); |
| 340 | expect(options).toEqual(undefined); |
| 341 | return { returnCode: 'OK' }; |
| 342 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 343 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 344 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 345 | expect(baseUrl).toEqual( |
| 346 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 347 | version.id |
| 348 | }` |
| 349 | ); |
| 350 | expect(data).toEqual(undefined); |
| 351 | expect(options).toEqual(undefined); |
| 352 | return { |
| 353 | ...returnedVersionFields, |
| 354 | state: { |
| 355 | synchronizationState: SyncStates.UP_TO_DATE, |
| 356 | dirty: true |
| 357 | } |
| 358 | }; |
| 359 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 360 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 361 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 362 | expect(baseUrl).toEqual( |
| 363 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 364 | ); |
| 365 | expect(data).toEqual(undefined); |
| 366 | expect(options).toEqual(undefined); |
| 367 | return { |
| 368 | ...returnedVersionFields |
| 369 | }; |
| 370 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 371 | |
svishnev | 8f13330 | 2018-08-06 23:08:39 +0300 | [diff] [blame] | 372 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 373 | expect(baseUrl).toEqual( |
| 374 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 375 | version.id |
| 376 | }/entitlement-pools` |
| 377 | ); |
| 378 | expect(data).toEqual(undefined); |
| 379 | expect(options).toEqual(undefined); |
| 380 | return { results: [entitlementPoolUpdateData] }; |
| 381 | }); |
| 382 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 383 | return EntitlementPoolsActionHelper.saveEntitlementPool( |
| 384 | store.dispatch, |
| 385 | { |
| 386 | licenseModelId: LICENSE_MODEL_ID, |
| 387 | version, |
| 388 | previousEntitlementPool: previousEntitlementPoolData, |
| 389 | entitlementPool: entitlementPoolUpdateData |
| 390 | } |
| 391 | ).then(() => { |
| 392 | expect(store.getState()).toEqual(expectedStore); |
| 393 | }); |
| 394 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 395 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 396 | it('Load Limits List', () => { |
| 397 | const limitsList = LimitItemFactory.buildList(3); |
| 398 | deepFreeze(limitsList); |
| 399 | const store = storeCreator(); |
| 400 | deepFreeze(store.getState()); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 401 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 402 | const expectedStore = cloneAndSet( |
| 403 | store.getState(), |
| 404 | 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', |
| 405 | limitsList |
| 406 | ); |
| 407 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 408 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 409 | expect(baseUrl).toEqual( |
| 410 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 411 | version.id |
| 412 | }/entitlement-pools/${entitlementPool.id}/limits` |
| 413 | ); |
| 414 | expect(data).toEqual(undefined); |
| 415 | expect(options).toEqual(undefined); |
| 416 | return { results: limitsList }; |
| 417 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 418 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 419 | return EntitlementPoolsActionHelper.fetchLimits(store.dispatch, { |
| 420 | licenseModelId: LICENSE_MODEL_ID, |
| 421 | version, |
| 422 | entitlementPool |
| 423 | }).then(() => { |
| 424 | expect(store.getState()).toEqual(expectedStore); |
| 425 | }); |
| 426 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 427 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 428 | it('Add Limit', () => { |
| 429 | const store = storeCreator({ |
| 430 | currentScreen: { ...itemPermissionAndProps } |
| 431 | }); |
| 432 | deepFreeze(store.getState()); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 433 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 434 | const limitToAdd = LimitPostFactory.build(); |
| 435 | let limitFromBE = { ...limitToAdd }; |
| 436 | limitFromBE.metric = getStrValue(limitFromBE.metric); |
| 437 | limitFromBE.unit = getStrValue(limitFromBE.unit); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 438 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 439 | deepFreeze(limitToAdd); |
| 440 | deepFreeze(limitFromBE); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 441 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 442 | const LimitIdFromResponse = 'ADDED_ID'; |
| 443 | const limitAddedItem = { ...limitToAdd, id: LimitIdFromResponse }; |
| 444 | deepFreeze(limitAddedItem); |
| 445 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 446 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 447 | const expectedCurrentScreenProps = { |
| 448 | ...itemPermissionAndProps, |
| 449 | itemPermission: { |
| 450 | ...itemPermissionAndProps.itemPermission, |
| 451 | isDirty: true |
| 452 | } |
| 453 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 454 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 455 | let expectedStore = cloneAndSet( |
| 456 | store.getState(), |
| 457 | 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', |
| 458 | [limitAddedItem] |
| 459 | ); |
| 460 | expectedStore = cloneAndSet( |
| 461 | expectedStore, |
| 462 | 'currentScreen.itemPermission', |
| 463 | expectedCurrentScreenProps.itemPermission |
| 464 | ); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 465 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 466 | mockRest.addHandler('post', ({ data, options, baseUrl }) => { |
| 467 | expect(baseUrl).toEqual( |
| 468 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 469 | version.id |
| 470 | }/entitlement-pools/${entitlementPool.id}/limits` |
| 471 | ); |
| 472 | expect(data).toEqual(limitFromBE); |
| 473 | expect(options).toEqual(undefined); |
| 474 | return { |
| 475 | returnCode: 'OK', |
| 476 | value: LimitIdFromResponse |
| 477 | }; |
| 478 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 479 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 480 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 481 | expect(baseUrl).toEqual( |
| 482 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 483 | version.id |
| 484 | }/entitlement-pools/${entitlementPool.id}/limits` |
| 485 | ); |
| 486 | expect(data).toEqual(undefined); |
| 487 | expect(options).toEqual(undefined); |
| 488 | return { results: [limitAddedItem] }; |
| 489 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 490 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 491 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 492 | expect(baseUrl).toEqual( |
| 493 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 494 | version.id |
| 495 | }` |
| 496 | ); |
| 497 | expect(data).toEqual(undefined); |
| 498 | expect(options).toEqual(undefined); |
| 499 | return { |
| 500 | ...returnedVersionFields, |
| 501 | state: { |
| 502 | synchronizationState: SyncStates.UP_TO_DATE, |
| 503 | dirty: true |
| 504 | } |
| 505 | }; |
| 506 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 507 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 508 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 509 | expect(baseUrl).toEqual( |
| 510 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 511 | ); |
| 512 | expect(data).toEqual(undefined); |
| 513 | expect(options).toEqual(undefined); |
| 514 | return { |
| 515 | ...returnedVersionFields |
| 516 | }; |
| 517 | }); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 518 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 519 | return EntitlementPoolsActionHelper.submitLimit(store.dispatch, { |
| 520 | licenseModelId: LICENSE_MODEL_ID, |
| 521 | version, |
| 522 | entitlementPool, |
| 523 | limit: limitToAdd |
| 524 | }).then(() => { |
| 525 | expect(store.getState()).toEqual(expectedStore); |
| 526 | }); |
| 527 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 528 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 529 | it('Delete Limit', () => { |
| 530 | const limitsList = LimitItemFactory.buildList(1); |
| 531 | deepFreeze(limitsList); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 532 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 533 | const store = storeCreator({ |
| 534 | currentScreen: { ...itemPermissionAndProps }, |
| 535 | licenseModel: { |
| 536 | entitlementPool: { |
| 537 | entitlementPoolEditor: { |
| 538 | limitsList |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | }); |
| 543 | deepFreeze(store.getState()); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 544 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 545 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 546 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 547 | const expectedCurrentScreenProps = { |
| 548 | ...itemPermissionAndProps, |
| 549 | itemPermission: { |
| 550 | ...itemPermissionAndProps.itemPermission, |
| 551 | isDirty: true |
| 552 | } |
| 553 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 554 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 555 | let expectedStore = cloneAndSet( |
| 556 | store.getState(), |
| 557 | 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', |
| 558 | [] |
| 559 | ); |
| 560 | expectedStore = cloneAndSet( |
| 561 | expectedStore, |
| 562 | 'currentScreen.itemPermission', |
| 563 | expectedCurrentScreenProps.itemPermission |
| 564 | ); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 565 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 566 | mockRest.addHandler('destroy', ({ data, options, baseUrl }) => { |
| 567 | expect(baseUrl).toEqual( |
| 568 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 569 | version.id |
| 570 | }/entitlement-pools/${entitlementPool.id}/limits/${ |
| 571 | limitsList[0].id |
| 572 | }` |
| 573 | ); |
| 574 | expect(data).toEqual(undefined); |
| 575 | expect(options).toEqual(undefined); |
| 576 | return { |
| 577 | results: { |
| 578 | returnCode: 'OK' |
| 579 | } |
| 580 | }; |
| 581 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 582 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 583 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 584 | expect(baseUrl).toEqual( |
| 585 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 586 | version.id |
| 587 | }/entitlement-pools/${entitlementPool.id}/limits` |
| 588 | ); |
| 589 | expect(data).toEqual(undefined); |
| 590 | expect(options).toEqual(undefined); |
| 591 | return { results: [] }; |
| 592 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 593 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 594 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 595 | expect(baseUrl).toEqual( |
| 596 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 597 | version.id |
| 598 | }` |
| 599 | ); |
| 600 | expect(data).toEqual(undefined); |
| 601 | expect(options).toEqual(undefined); |
| 602 | return { |
| 603 | ...returnedVersionFields, |
| 604 | state: { |
| 605 | synchronizationState: SyncStates.UP_TO_DATE, |
| 606 | dirty: true |
| 607 | } |
| 608 | }; |
| 609 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 610 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 611 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 612 | expect(baseUrl).toEqual( |
| 613 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 614 | ); |
| 615 | expect(data).toEqual(undefined); |
| 616 | expect(options).toEqual(undefined); |
| 617 | return { |
| 618 | ...returnedVersionFields |
| 619 | }; |
| 620 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 621 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 622 | return EntitlementPoolsActionHelper.deleteLimit(store.dispatch, { |
| 623 | licenseModelId: LICENSE_MODEL_ID, |
| 624 | version, |
| 625 | entitlementPool, |
| 626 | limit: limitsList[0] |
| 627 | }).then(() => { |
| 628 | expect(store.getState()).toEqual(expectedStore); |
| 629 | }); |
| 630 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 631 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 632 | it('Update Limit', () => { |
| 633 | const limitsList = LimitItemFactory.buildList(1); |
| 634 | deepFreeze(limitsList); |
| 635 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 636 | const store = storeCreator({ |
| 637 | currentScreen: { ...itemPermissionAndProps }, |
| 638 | licenseModel: { |
| 639 | entitlementPool: { |
| 640 | entitlementPoolEditor: { |
| 641 | limitsList |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | }); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 646 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 647 | deepFreeze(store.getState()); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 648 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 649 | const previousData = limitsList[0]; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 650 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 651 | deepFreeze(previousData); |
| 652 | const limitId = limitsList[0].id; |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 653 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 654 | let updatedLimit = { ...previousData, name: 'updatedLimit' }; |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 655 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 656 | const updatedLimitForPut = { ...updatedLimit, id: undefined }; |
| 657 | updatedLimit.metric = { choice: updatedLimit.metric, other: '' }; |
| 658 | updatedLimit.unit = { choice: updatedLimit.unit, other: '' }; |
| 659 | deepFreeze(updatedLimit); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 660 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 661 | const expectedCurrentScreenProps = { |
| 662 | ...itemPermissionAndProps, |
| 663 | itemPermission: { |
| 664 | ...itemPermissionAndProps.itemPermission, |
| 665 | isDirty: true |
| 666 | } |
| 667 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 668 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 669 | let expectedStore = cloneAndSet( |
| 670 | store.getState(), |
| 671 | 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', |
| 672 | [updatedLimitForPut] |
| 673 | ); |
| 674 | expectedStore = cloneAndSet( |
| 675 | expectedStore, |
| 676 | 'currentScreen.itemPermission', |
| 677 | expectedCurrentScreenProps.itemPermission |
| 678 | ); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 679 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 680 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 681 | expect(baseUrl).toEqual( |
| 682 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 683 | version.id |
| 684 | }/entitlement-pools/${entitlementPool.id}/limits/${limitId}` |
| 685 | ); |
| 686 | expect(data).toEqual(updatedLimitForPut); |
| 687 | expect(options).toEqual(undefined); |
| 688 | return { returnCode: 'OK' }; |
| 689 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 690 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 691 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 692 | expect(baseUrl).toEqual( |
| 693 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 694 | version.id |
| 695 | }/entitlement-pools/${entitlementPool.id}/limits` |
| 696 | ); |
| 697 | expect(data).toEqual(undefined); |
| 698 | expect(options).toEqual(undefined); |
| 699 | return { results: [updatedLimitForPut] }; |
| 700 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 701 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 702 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 703 | expect(baseUrl).toEqual( |
| 704 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 705 | version.id |
| 706 | }` |
| 707 | ); |
| 708 | expect(data).toEqual(undefined); |
| 709 | expect(options).toEqual(undefined); |
| 710 | return { |
| 711 | ...returnedVersionFields, |
| 712 | state: { |
| 713 | synchronizationState: SyncStates.UP_TO_DATE, |
| 714 | dirty: true |
| 715 | } |
| 716 | }; |
| 717 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 718 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 719 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 720 | expect(baseUrl).toEqual( |
| 721 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 722 | ); |
| 723 | expect(data).toEqual(undefined); |
| 724 | expect(options).toEqual(undefined); |
| 725 | return { |
| 726 | ...returnedVersionFields |
| 727 | }; |
| 728 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 729 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 730 | return EntitlementPoolsActionHelper.submitLimit(store.dispatch, { |
| 731 | licenseModelId: LICENSE_MODEL_ID, |
| 732 | version, |
| 733 | entitlementPool, |
| 734 | limit: updatedLimit |
| 735 | }).then(() => { |
| 736 | expect(store.getState()).toEqual(expectedStore); |
| 737 | }); |
| 738 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 739 | }); |