AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
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 | * |
| 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, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | * or implied. See the License for the specific language governing |
| 14 | * permissions and limitations under the License. |
Michael 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'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 18 | import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 19 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 20 | import EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 21 | import {EntitlementPoolStoreFactory, EntitlementPoolPostFactory} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js'; |
| 22 | import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 23 | import {LimitItemFactory, LimitPostFactory} from 'test-utils/factories/licenseModel/LimitFactories.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 24 | |
| 25 | describe('Entitlement Pools Module Tests', function () { |
| 26 | |
| 27 | const LICENSE_MODEL_ID = '555'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 28 | const version = VersionControllerUtilsFactory.build().version; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 29 | |
| 30 | it('Load Entitlement Pools List', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 31 | |
| 32 | const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 33 | deepFreeze(entitlementPoolsList); |
| 34 | const store = storeCreator(); |
| 35 | deepFreeze(store.getState()); |
| 36 | |
| 37 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', entitlementPoolsList); |
| 38 | |
| 39 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 40 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`); |
| 41 | expect(data).toEqual(undefined); |
| 42 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 43 | return {results: entitlementPoolsList}; |
| 44 | }); |
| 45 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 46 | return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { |
| 47 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 48 | }); |
| 49 | }); |
| 50 | |
| 51 | it('Delete Entitlement Pool', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 52 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 53 | const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory,1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 54 | deepFreeze(entitlementPoolsList); |
| 55 | const store = storeCreator({ |
| 56 | licenseModel: { |
| 57 | entitlementPool: { |
| 58 | entitlementPoolsList |
| 59 | } |
| 60 | } |
| 61 | }); |
| 62 | deepFreeze(store.getState()); |
| 63 | |
| 64 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', []); |
| 65 | |
| 66 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 67 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPoolsList[0].id}`); |
| 68 | expect(data).toEqual(undefined); |
| 69 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 70 | return { |
| 71 | results: { |
| 72 | returnCode: 'OK' |
| 73 | } |
| 74 | }; |
| 75 | }); |
| 76 | |
| 77 | return EntitlementPoolsActionHelper.deleteEntitlementPool(store.dispatch, { |
| 78 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 79 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 80 | entitlementPoolId: entitlementPoolsList[0].id |
| 81 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 82 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 83 | }); |
| 84 | }); |
| 85 | |
| 86 | it('Add Entitlement Pool', () => { |
| 87 | |
| 88 | const store = storeCreator(); |
| 89 | deepFreeze(store.getState()); |
| 90 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 91 | const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build(); |
| 92 | |
| 93 | deepFreeze(EntitlementPoolPostRequest); |
| 94 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 95 | const entitlementPoolIdFromResponse = 'ADDED_ID'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 96 | const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({id: entitlementPoolIdFromResponse}); |
| 97 | deepFreeze(entitlementPoolAfterAdd); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 98 | |
| 99 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolAfterAdd]); |
| 100 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 101 | mockRest.addHandler('post', ({data, options, baseUrl}) => { |
| 102 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`); |
| 103 | expect(data).toEqual(EntitlementPoolPostRequest); |
| 104 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 105 | return { |
| 106 | returnCode: 'OK', |
| 107 | value: entitlementPoolIdFromResponse |
| 108 | }; |
| 109 | }); |
| 110 | |
| 111 | return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, |
| 112 | { |
| 113 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 114 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 115 | previousEntitlementPool: null, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 116 | entitlementPool: EntitlementPoolPostRequest |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 117 | } |
| 118 | ).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 119 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 120 | }); |
| 121 | }); |
| 122 | |
| 123 | it('Update Entitlement Pool', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 124 | |
| 125 | const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory, 1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 126 | deepFreeze(entitlementPoolsList); |
| 127 | |
| 128 | const store = storeCreator({ |
| 129 | licenseModel: { |
| 130 | entitlementPool: { |
| 131 | entitlementPoolsList |
| 132 | } |
| 133 | } |
| 134 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 135 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 136 | deepFreeze(store.getState()); |
| 137 | |
| 138 | const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id; |
| 139 | const previousEntitlementPoolData = entitlementPoolsList[0]; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 140 | const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED', id: toBeUpdatedEntitlementPoolId}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 141 | deepFreeze(entitlementPoolUpdateData); |
| 142 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 143 | const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED'}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 144 | deepFreeze(entitlementPoolPutRequest); |
| 145 | |
| 146 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]); |
| 147 | |
| 148 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 149 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 150 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${toBeUpdatedEntitlementPoolId}`); |
| 151 | expect(data).toEqual(entitlementPoolPutRequest); |
| 152 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 153 | return {returnCode: 'OK'}; |
| 154 | }); |
| 155 | |
| 156 | return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, { |
| 157 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 158 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 159 | previousEntitlementPool: previousEntitlementPoolData, |
| 160 | entitlementPool: entitlementPoolUpdateData |
| 161 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 162 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 163 | }); |
| 164 | }); |
| 165 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 166 | it('Load Limits List', () => { |
| 167 | |
| 168 | const limitsList = LimitItemFactory.buildList(3); |
| 169 | deepFreeze(limitsList); |
| 170 | const store = storeCreator(); |
| 171 | deepFreeze(store.getState()); |
| 172 | |
| 173 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', limitsList); |
| 174 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 175 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 176 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 177 | expect(data).toEqual(undefined); |
| 178 | expect(options).toEqual(undefined); |
| 179 | return {results: limitsList}; |
| 180 | }); |
| 181 | |
| 182 | return EntitlementPoolsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, entitlementPool}).then(() => { |
| 183 | expect(store.getState()).toEqual(expectedStore); |
| 184 | }); |
| 185 | }); |
| 186 | |
| 187 | it('Add Limit', () => { |
| 188 | |
| 189 | const store = storeCreator(); |
| 190 | deepFreeze(store.getState()); |
| 191 | |
| 192 | const limitToAdd = LimitPostFactory.build(); |
| 193 | |
| 194 | deepFreeze(limitToAdd); |
| 195 | |
| 196 | const LimitIdFromResponse = 'ADDED_ID'; |
| 197 | const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse}; |
| 198 | deepFreeze(limitAddedItem); |
| 199 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 200 | |
| 201 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [limitAddedItem]); |
| 202 | |
| 203 | mockRest.addHandler('post', ({data, options, baseUrl}) => { |
| 204 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 205 | expect(data).toEqual(limitToAdd); |
| 206 | expect(options).toEqual(undefined); |
| 207 | return { |
| 208 | returnCode: 'OK', |
| 209 | value: LimitIdFromResponse |
| 210 | }; |
| 211 | }); |
| 212 | |
| 213 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 214 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 215 | expect(data).toEqual(undefined); |
| 216 | expect(options).toEqual(undefined); |
| 217 | return {results: [limitAddedItem]}; |
| 218 | }); |
| 219 | |
| 220 | return EntitlementPoolsActionHelper.submitLimit(store.dispatch, |
| 221 | { |
| 222 | licenseModelId: LICENSE_MODEL_ID, |
| 223 | version, |
| 224 | entitlementPool, |
| 225 | limit: limitToAdd |
| 226 | } |
| 227 | ).then(() => { |
| 228 | expect(store.getState()).toEqual(expectedStore); |
| 229 | }); |
| 230 | }); |
| 231 | |
| 232 | |
| 233 | it('Delete Limit', () => { |
| 234 | |
| 235 | const limitsList = LimitItemFactory.buildList(1); |
| 236 | deepFreeze(limitsList); |
| 237 | |
| 238 | const store = storeCreator({ |
| 239 | licenseModel: { |
| 240 | entitlementPool: { |
| 241 | entitlementPoolEditor: { |
| 242 | limitsList |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | }); |
| 247 | deepFreeze(store.getState()); |
| 248 | |
| 249 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 250 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', []); |
| 251 | |
| 252 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
| 253 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits/${limitsList[0].id}`); |
| 254 | expect(data).toEqual(undefined); |
| 255 | expect(options).toEqual(undefined); |
| 256 | return { |
| 257 | results: { |
| 258 | returnCode: 'OK' |
| 259 | } |
| 260 | }; |
| 261 | }); |
| 262 | |
| 263 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 264 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 265 | expect(data).toEqual(undefined); |
| 266 | expect(options).toEqual(undefined); |
| 267 | return {results: []}; |
| 268 | }); |
| 269 | |
| 270 | return EntitlementPoolsActionHelper.deleteLimit(store.dispatch, { |
| 271 | licenseModelId: LICENSE_MODEL_ID, |
| 272 | version, |
| 273 | entitlementPool, |
| 274 | limit: limitsList[0] |
| 275 | }).then(() => { |
| 276 | expect(store.getState()).toEqual(expectedStore); |
| 277 | }); |
| 278 | }); |
| 279 | |
| 280 | it('Update Limit', () => { |
| 281 | |
| 282 | const limitsList = LimitItemFactory.buildList(1); |
| 283 | deepFreeze(limitsList); |
| 284 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 285 | const store = storeCreator({ |
| 286 | licenseModel: { |
| 287 | entitlementPool: { |
| 288 | entitlementPoolEditor: { |
| 289 | limitsList |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | }); |
| 294 | |
| 295 | deepFreeze(store.getState()); |
| 296 | |
| 297 | |
| 298 | const previousData = limitsList[0]; |
| 299 | deepFreeze(previousData); |
| 300 | const limitId = limitsList[0].id; |
| 301 | |
| 302 | const updatedLimit = {...previousData, name: 'updatedLimit'}; |
| 303 | deepFreeze(updatedLimit); |
| 304 | const updatedLimitForPut = {...updatedLimit, id: undefined}; |
| 305 | |
| 306 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [updatedLimit]); |
| 307 | |
| 308 | |
| 309 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 310 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits/${limitId}`); |
| 311 | expect(data).toEqual(updatedLimitForPut); |
| 312 | expect(options).toEqual(undefined); |
| 313 | return {returnCode: 'OK'}; |
| 314 | }); |
| 315 | |
| 316 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 317 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 318 | expect(data).toEqual(undefined); |
| 319 | expect(options).toEqual(undefined); |
| 320 | return {results: [updatedLimit]}; |
| 321 | }); |
| 322 | |
| 323 | return EntitlementPoolsActionHelper.submitLimit(store.dispatch, |
| 324 | { |
| 325 | licenseModelId: LICENSE_MODEL_ID, |
| 326 | version, |
| 327 | entitlementPool, |
| 328 | limit: updatedLimit |
| 329 | } |
| 330 | ).then(() => { |
| 331 | expect(store.getState()).toEqual(expectedStore); |
| 332 | }); |
| 333 | }); |
| 334 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 335 | }); |