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 | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 157 | return EntitlementPoolsActionHelper.deleteEntitlementPool( |
| 158 | store.dispatch, |
| 159 | { |
| 160 | licenseModelId: LICENSE_MODEL_ID, |
| 161 | version, |
| 162 | entitlementPoolId: entitlementPoolsList[0].id |
| 163 | } |
| 164 | ).then(() => { |
| 165 | expect(store.getState()).toEqual(expectedStore); |
| 166 | }); |
| 167 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 168 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 169 | it('Add Entitlement Pool', () => { |
| 170 | const store = storeCreator({ |
| 171 | currentScreen: { ...itemPermissionAndProps } |
| 172 | }); |
| 173 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 174 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 175 | const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 176 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 177 | deepFreeze(EntitlementPoolPostRequest); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 178 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 179 | const entitlementPoolIdFromResponse = 'ADDED_ID'; |
| 180 | const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({ |
| 181 | id: entitlementPoolIdFromResponse |
| 182 | }); |
| 183 | deepFreeze(entitlementPoolAfterAdd); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 184 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 185 | const expectedCurrentScreenProps = { |
| 186 | ...itemPermissionAndProps, |
| 187 | itemPermission: { |
| 188 | ...itemPermissionAndProps.itemPermission, |
| 189 | isDirty: true |
| 190 | } |
| 191 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 192 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 193 | let expectedStore = cloneAndSet( |
| 194 | store.getState(), |
| 195 | 'licenseModel.entitlementPool.entitlementPoolsList', |
| 196 | [entitlementPoolAfterAdd] |
| 197 | ); |
| 198 | expectedStore = cloneAndSet( |
| 199 | expectedStore, |
| 200 | 'currentScreen.itemPermission', |
| 201 | expectedCurrentScreenProps.itemPermission |
| 202 | ); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 203 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 204 | mockRest.addHandler('post', ({ data, options, baseUrl }) => { |
| 205 | expect(baseUrl).toEqual( |
| 206 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 207 | version.id |
| 208 | }/entitlement-pools` |
| 209 | ); |
| 210 | expect(data).toEqual(EntitlementPoolPostRequest); |
| 211 | expect(options).toEqual(undefined); |
| 212 | return { |
| 213 | returnCode: 'OK', |
| 214 | value: entitlementPoolIdFromResponse |
| 215 | }; |
| 216 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 217 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 218 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 219 | expect(baseUrl).toEqual( |
| 220 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 221 | version.id |
| 222 | }` |
| 223 | ); |
| 224 | expect(data).toEqual(undefined); |
| 225 | expect(options).toEqual(undefined); |
| 226 | return { |
| 227 | ...returnedVersionFields, |
| 228 | state: { |
| 229 | synchronizationState: SyncStates.UP_TO_DATE, |
| 230 | dirty: true |
| 231 | } |
| 232 | }; |
| 233 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 234 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 235 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 236 | expect(baseUrl).toEqual( |
| 237 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 238 | ); |
| 239 | expect(data).toEqual(undefined); |
| 240 | expect(options).toEqual(undefined); |
| 241 | return { |
| 242 | ...returnedVersionFields |
| 243 | }; |
| 244 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 245 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 246 | return EntitlementPoolsActionHelper.saveEntitlementPool( |
| 247 | store.dispatch, |
| 248 | { |
| 249 | licenseModelId: LICENSE_MODEL_ID, |
| 250 | version, |
| 251 | previousEntitlementPool: null, |
| 252 | entitlementPool: EntitlementPoolPostRequest |
| 253 | } |
| 254 | ).then(() => { |
| 255 | expect(store.getState()).toEqual(expectedStore); |
| 256 | }); |
| 257 | }); |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 258 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 259 | it('Update Entitlement Pool', () => { |
| 260 | const entitlementPoolsList = buildListFromFactory( |
| 261 | EntitlementPoolStoreFactory, |
| 262 | 1 |
| 263 | ); |
| 264 | deepFreeze(entitlementPoolsList); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 265 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 266 | const store = storeCreator({ |
| 267 | currentScreen: { ...itemPermissionAndProps }, |
| 268 | licenseModel: { |
| 269 | entitlementPool: { |
| 270 | entitlementPoolsList |
| 271 | } |
| 272 | } |
| 273 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 274 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 275 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 276 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 277 | const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id; |
| 278 | const previousEntitlementPoolData = entitlementPoolsList[0]; |
| 279 | const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({ |
| 280 | name: 'ep1_UPDATED', |
| 281 | description: 'string_UPDATED', |
| 282 | id: toBeUpdatedEntitlementPoolId |
| 283 | }); |
| 284 | deepFreeze(entitlementPoolUpdateData); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 285 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 286 | const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({ |
| 287 | name: 'ep1_UPDATED', |
| 288 | description: 'string_UPDATED' |
| 289 | }); |
| 290 | deepFreeze(entitlementPoolPutRequest); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 291 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 292 | const expectedCurrentScreenProps = { |
| 293 | ...itemPermissionAndProps, |
| 294 | itemPermission: { |
| 295 | ...itemPermissionAndProps.itemPermission, |
| 296 | isDirty: true |
| 297 | } |
| 298 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 299 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 300 | let expectedStore = cloneAndSet( |
| 301 | store.getState(), |
| 302 | 'licenseModel.entitlementPool.entitlementPoolsList', |
| 303 | [entitlementPoolUpdateData] |
| 304 | ); |
| 305 | expectedStore = cloneAndSet( |
| 306 | expectedStore, |
| 307 | 'currentScreen.itemPermission', |
| 308 | expectedCurrentScreenProps.itemPermission |
| 309 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 310 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 311 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 312 | expect(baseUrl).toEqual( |
| 313 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 314 | version.id |
| 315 | }/entitlement-pools/${toBeUpdatedEntitlementPoolId}` |
| 316 | ); |
| 317 | expect(data).toEqual(entitlementPoolPutRequest); |
| 318 | expect(options).toEqual(undefined); |
| 319 | return { returnCode: 'OK' }; |
| 320 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 321 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 322 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 323 | expect(baseUrl).toEqual( |
| 324 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 325 | version.id |
| 326 | }` |
| 327 | ); |
| 328 | expect(data).toEqual(undefined); |
| 329 | expect(options).toEqual(undefined); |
| 330 | return { |
| 331 | ...returnedVersionFields, |
| 332 | state: { |
| 333 | synchronizationState: SyncStates.UP_TO_DATE, |
| 334 | dirty: true |
| 335 | } |
| 336 | }; |
| 337 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 338 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 339 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 340 | expect(baseUrl).toEqual( |
| 341 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 342 | ); |
| 343 | expect(data).toEqual(undefined); |
| 344 | expect(options).toEqual(undefined); |
| 345 | return { |
| 346 | ...returnedVersionFields |
| 347 | }; |
| 348 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 349 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 350 | return EntitlementPoolsActionHelper.saveEntitlementPool( |
| 351 | store.dispatch, |
| 352 | { |
| 353 | licenseModelId: LICENSE_MODEL_ID, |
| 354 | version, |
| 355 | previousEntitlementPool: previousEntitlementPoolData, |
| 356 | entitlementPool: entitlementPoolUpdateData |
| 357 | } |
| 358 | ).then(() => { |
| 359 | expect(store.getState()).toEqual(expectedStore); |
| 360 | }); |
| 361 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 362 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 363 | it('Load Limits List', () => { |
| 364 | const limitsList = LimitItemFactory.buildList(3); |
| 365 | deepFreeze(limitsList); |
| 366 | const store = storeCreator(); |
| 367 | deepFreeze(store.getState()); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 368 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 369 | const expectedStore = cloneAndSet( |
| 370 | store.getState(), |
| 371 | 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', |
| 372 | limitsList |
| 373 | ); |
| 374 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 375 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 376 | expect(baseUrl).toEqual( |
| 377 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 378 | version.id |
| 379 | }/entitlement-pools/${entitlementPool.id}/limits` |
| 380 | ); |
| 381 | expect(data).toEqual(undefined); |
| 382 | expect(options).toEqual(undefined); |
| 383 | return { results: limitsList }; |
| 384 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 385 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 386 | return EntitlementPoolsActionHelper.fetchLimits(store.dispatch, { |
| 387 | licenseModelId: LICENSE_MODEL_ID, |
| 388 | version, |
| 389 | entitlementPool |
| 390 | }).then(() => { |
| 391 | expect(store.getState()).toEqual(expectedStore); |
| 392 | }); |
| 393 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 394 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 395 | it('Add Limit', () => { |
| 396 | const store = storeCreator({ |
| 397 | currentScreen: { ...itemPermissionAndProps } |
| 398 | }); |
| 399 | deepFreeze(store.getState()); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 400 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 401 | const limitToAdd = LimitPostFactory.build(); |
| 402 | let limitFromBE = { ...limitToAdd }; |
| 403 | limitFromBE.metric = getStrValue(limitFromBE.metric); |
| 404 | limitFromBE.unit = getStrValue(limitFromBE.unit); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 405 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 406 | deepFreeze(limitToAdd); |
| 407 | deepFreeze(limitFromBE); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 408 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 409 | const LimitIdFromResponse = 'ADDED_ID'; |
| 410 | const limitAddedItem = { ...limitToAdd, id: LimitIdFromResponse }; |
| 411 | deepFreeze(limitAddedItem); |
| 412 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 413 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 414 | const expectedCurrentScreenProps = { |
| 415 | ...itemPermissionAndProps, |
| 416 | itemPermission: { |
| 417 | ...itemPermissionAndProps.itemPermission, |
| 418 | isDirty: true |
| 419 | } |
| 420 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 421 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 422 | let expectedStore = cloneAndSet( |
| 423 | store.getState(), |
| 424 | 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', |
| 425 | [limitAddedItem] |
| 426 | ); |
| 427 | expectedStore = cloneAndSet( |
| 428 | expectedStore, |
| 429 | 'currentScreen.itemPermission', |
| 430 | expectedCurrentScreenProps.itemPermission |
| 431 | ); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 432 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 433 | mockRest.addHandler('post', ({ data, options, baseUrl }) => { |
| 434 | expect(baseUrl).toEqual( |
| 435 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 436 | version.id |
| 437 | }/entitlement-pools/${entitlementPool.id}/limits` |
| 438 | ); |
| 439 | expect(data).toEqual(limitFromBE); |
| 440 | expect(options).toEqual(undefined); |
| 441 | return { |
| 442 | returnCode: 'OK', |
| 443 | value: LimitIdFromResponse |
| 444 | }; |
| 445 | }); |
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 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 448 | expect(baseUrl).toEqual( |
| 449 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 450 | version.id |
| 451 | }/entitlement-pools/${entitlementPool.id}/limits` |
| 452 | ); |
| 453 | expect(data).toEqual(undefined); |
| 454 | expect(options).toEqual(undefined); |
| 455 | return { results: [limitAddedItem] }; |
| 456 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 457 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 458 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 459 | expect(baseUrl).toEqual( |
| 460 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 461 | version.id |
| 462 | }` |
| 463 | ); |
| 464 | expect(data).toEqual(undefined); |
| 465 | expect(options).toEqual(undefined); |
| 466 | return { |
| 467 | ...returnedVersionFields, |
| 468 | state: { |
| 469 | synchronizationState: SyncStates.UP_TO_DATE, |
| 470 | dirty: true |
| 471 | } |
| 472 | }; |
| 473 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 474 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 475 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 476 | expect(baseUrl).toEqual( |
| 477 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 478 | ); |
| 479 | expect(data).toEqual(undefined); |
| 480 | expect(options).toEqual(undefined); |
| 481 | return { |
| 482 | ...returnedVersionFields |
| 483 | }; |
| 484 | }); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 485 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 486 | return EntitlementPoolsActionHelper.submitLimit(store.dispatch, { |
| 487 | licenseModelId: LICENSE_MODEL_ID, |
| 488 | version, |
| 489 | entitlementPool, |
| 490 | limit: limitToAdd |
| 491 | }).then(() => { |
| 492 | expect(store.getState()).toEqual(expectedStore); |
| 493 | }); |
| 494 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 495 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 496 | it('Delete Limit', () => { |
| 497 | const limitsList = LimitItemFactory.buildList(1); |
| 498 | deepFreeze(limitsList); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 499 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 500 | const store = storeCreator({ |
| 501 | currentScreen: { ...itemPermissionAndProps }, |
| 502 | licenseModel: { |
| 503 | entitlementPool: { |
| 504 | entitlementPoolEditor: { |
| 505 | limitsList |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | }); |
| 510 | deepFreeze(store.getState()); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 511 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 512 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 513 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 514 | const expectedCurrentScreenProps = { |
| 515 | ...itemPermissionAndProps, |
| 516 | itemPermission: { |
| 517 | ...itemPermissionAndProps.itemPermission, |
| 518 | isDirty: true |
| 519 | } |
| 520 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 521 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 522 | let expectedStore = cloneAndSet( |
| 523 | store.getState(), |
| 524 | 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', |
| 525 | [] |
| 526 | ); |
| 527 | expectedStore = cloneAndSet( |
| 528 | expectedStore, |
| 529 | 'currentScreen.itemPermission', |
| 530 | expectedCurrentScreenProps.itemPermission |
| 531 | ); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 532 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 533 | mockRest.addHandler('destroy', ({ data, options, baseUrl }) => { |
| 534 | expect(baseUrl).toEqual( |
| 535 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 536 | version.id |
| 537 | }/entitlement-pools/${entitlementPool.id}/limits/${ |
| 538 | limitsList[0].id |
| 539 | }` |
| 540 | ); |
| 541 | expect(data).toEqual(undefined); |
| 542 | expect(options).toEqual(undefined); |
| 543 | return { |
| 544 | results: { |
| 545 | returnCode: 'OK' |
| 546 | } |
| 547 | }; |
| 548 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 549 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 550 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 551 | expect(baseUrl).toEqual( |
| 552 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 553 | version.id |
| 554 | }/entitlement-pools/${entitlementPool.id}/limits` |
| 555 | ); |
| 556 | expect(data).toEqual(undefined); |
| 557 | expect(options).toEqual(undefined); |
| 558 | return { results: [] }; |
| 559 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 560 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 561 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 562 | expect(baseUrl).toEqual( |
| 563 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 564 | version.id |
| 565 | }` |
| 566 | ); |
| 567 | expect(data).toEqual(undefined); |
| 568 | expect(options).toEqual(undefined); |
| 569 | return { |
| 570 | ...returnedVersionFields, |
| 571 | state: { |
| 572 | synchronizationState: SyncStates.UP_TO_DATE, |
| 573 | dirty: true |
| 574 | } |
| 575 | }; |
| 576 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 577 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 578 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 579 | expect(baseUrl).toEqual( |
| 580 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 581 | ); |
| 582 | expect(data).toEqual(undefined); |
| 583 | expect(options).toEqual(undefined); |
| 584 | return { |
| 585 | ...returnedVersionFields |
| 586 | }; |
| 587 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 588 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 589 | return EntitlementPoolsActionHelper.deleteLimit(store.dispatch, { |
| 590 | licenseModelId: LICENSE_MODEL_ID, |
| 591 | version, |
| 592 | entitlementPool, |
| 593 | limit: limitsList[0] |
| 594 | }).then(() => { |
| 595 | expect(store.getState()).toEqual(expectedStore); |
| 596 | }); |
| 597 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 598 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 599 | it('Update Limit', () => { |
| 600 | const limitsList = LimitItemFactory.buildList(1); |
| 601 | deepFreeze(limitsList); |
| 602 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 603 | const store = storeCreator({ |
| 604 | currentScreen: { ...itemPermissionAndProps }, |
| 605 | licenseModel: { |
| 606 | entitlementPool: { |
| 607 | entitlementPoolEditor: { |
| 608 | limitsList |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | }); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 613 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 614 | deepFreeze(store.getState()); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 615 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 616 | const previousData = limitsList[0]; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 617 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 618 | deepFreeze(previousData); |
| 619 | const limitId = limitsList[0].id; |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 620 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 621 | let updatedLimit = { ...previousData, name: 'updatedLimit' }; |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 622 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 623 | const updatedLimitForPut = { ...updatedLimit, id: undefined }; |
| 624 | updatedLimit.metric = { choice: updatedLimit.metric, other: '' }; |
| 625 | updatedLimit.unit = { choice: updatedLimit.unit, other: '' }; |
| 626 | deepFreeze(updatedLimit); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 627 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 628 | const expectedCurrentScreenProps = { |
| 629 | ...itemPermissionAndProps, |
| 630 | itemPermission: { |
| 631 | ...itemPermissionAndProps.itemPermission, |
| 632 | isDirty: true |
| 633 | } |
| 634 | }; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 635 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 636 | let expectedStore = cloneAndSet( |
| 637 | store.getState(), |
| 638 | 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', |
| 639 | [updatedLimitForPut] |
| 640 | ); |
| 641 | expectedStore = cloneAndSet( |
| 642 | expectedStore, |
| 643 | 'currentScreen.itemPermission', |
| 644 | expectedCurrentScreenProps.itemPermission |
| 645 | ); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 646 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 647 | mockRest.addHandler('put', ({ data, options, baseUrl }) => { |
| 648 | expect(baseUrl).toEqual( |
| 649 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 650 | version.id |
| 651 | }/entitlement-pools/${entitlementPool.id}/limits/${limitId}` |
| 652 | ); |
| 653 | expect(data).toEqual(updatedLimitForPut); |
| 654 | expect(options).toEqual(undefined); |
| 655 | return { returnCode: 'OK' }; |
| 656 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 657 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 658 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 659 | expect(baseUrl).toEqual( |
| 660 | `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${ |
| 661 | version.id |
| 662 | }/entitlement-pools/${entitlementPool.id}/limits` |
| 663 | ); |
| 664 | expect(data).toEqual(undefined); |
| 665 | expect(options).toEqual(undefined); |
| 666 | return { results: [updatedLimitForPut] }; |
| 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 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 670 | expect(baseUrl).toEqual( |
| 671 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${ |
| 672 | version.id |
| 673 | }` |
| 674 | ); |
| 675 | expect(data).toEqual(undefined); |
| 676 | expect(options).toEqual(undefined); |
| 677 | return { |
| 678 | ...returnedVersionFields, |
| 679 | state: { |
| 680 | synchronizationState: SyncStates.UP_TO_DATE, |
| 681 | dirty: true |
| 682 | } |
| 683 | }; |
| 684 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 685 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 686 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 687 | expect(baseUrl).toEqual( |
| 688 | `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}` |
| 689 | ); |
| 690 | expect(data).toEqual(undefined); |
| 691 | expect(options).toEqual(undefined); |
| 692 | return { |
| 693 | ...returnedVersionFields |
| 694 | }; |
| 695 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 696 | |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 697 | return EntitlementPoolsActionHelper.submitLimit(store.dispatch, { |
| 698 | licenseModelId: LICENSE_MODEL_ID, |
| 699 | version, |
| 700 | entitlementPool, |
| 701 | limit: updatedLimit |
| 702 | }).then(() => { |
| 703 | expect(store.getState()).toEqual(expectedStore); |
| 704 | }); |
| 705 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 706 | }); |