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'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 22 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 23 | import {LimitItemFactory, LimitPostFactory} from 'test-utils/factories/licenseModel/LimitFactories.js'; |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 24 | import {getStrValue} from 'nfvo-utils/getValue.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 25 | import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js'; |
| 26 | import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 27 | |
| 28 | describe('Entitlement Pools Module Tests', function () { |
| 29 | |
| 30 | const LICENSE_MODEL_ID = '555'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 31 | const version = VersionFactory.build(); |
| 32 | const itemPermissionAndProps = CurrentScreenFactory.build({}, {version}); |
| 33 | const returnedVersionFields = {baseId: version.baseId, description: version.description, id: version.id, name: version.name, status: version.status}; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 34 | |
| 35 | it('Load Entitlement Pools List', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 36 | |
| 37 | const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 38 | deepFreeze(entitlementPoolsList); |
| 39 | const store = storeCreator(); |
| 40 | deepFreeze(store.getState()); |
| 41 | |
| 42 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', entitlementPoolsList); |
| 43 | |
| 44 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 45 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`); |
| 46 | expect(data).toEqual(undefined); |
| 47 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 48 | return {results: entitlementPoolsList}; |
| 49 | }); |
| 50 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 51 | return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { |
| 52 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 53 | }); |
| 54 | }); |
| 55 | |
| 56 | it('Delete Entitlement Pool', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 57 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 58 | const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory,1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 59 | deepFreeze(entitlementPoolsList); |
| 60 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 61 | currentScreen: {...itemPermissionAndProps}, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 62 | licenseModel: { |
| 63 | entitlementPool: { |
| 64 | entitlementPoolsList |
| 65 | } |
| 66 | } |
| 67 | }); |
| 68 | deepFreeze(store.getState()); |
| 69 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 70 | const expectedCurrentScreenProps = { |
| 71 | ...itemPermissionAndProps, |
| 72 | itemPermission: { |
| 73 | ...itemPermissionAndProps.itemPermission, |
| 74 | isDirty: true |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', []); |
| 79 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 80 | |
| 81 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 82 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPoolsList[0].id}`); |
| 83 | expect(data).toEqual(undefined); |
| 84 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 85 | return { |
| 86 | results: { |
| 87 | returnCode: 'OK' |
| 88 | } |
| 89 | }; |
| 90 | }); |
| 91 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 92 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 93 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 94 | expect(data).toEqual(undefined); |
| 95 | expect(options).toEqual(undefined); |
| 96 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 97 | }); |
| 98 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 99 | return EntitlementPoolsActionHelper.deleteEntitlementPool(store.dispatch, { |
| 100 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 101 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 102 | entitlementPoolId: entitlementPoolsList[0].id |
| 103 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 104 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 105 | }); |
| 106 | }); |
| 107 | |
| 108 | it('Add Entitlement Pool', () => { |
| 109 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 110 | const store = storeCreator({ |
| 111 | currentScreen: {...itemPermissionAndProps} |
| 112 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 113 | deepFreeze(store.getState()); |
| 114 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 115 | const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build(); |
| 116 | |
| 117 | deepFreeze(EntitlementPoolPostRequest); |
| 118 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 119 | const entitlementPoolIdFromResponse = 'ADDED_ID'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 120 | const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({id: entitlementPoolIdFromResponse}); |
| 121 | deepFreeze(entitlementPoolAfterAdd); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 122 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 123 | const expectedCurrentScreenProps = { |
| 124 | ...itemPermissionAndProps, |
| 125 | itemPermission: { |
| 126 | ...itemPermissionAndProps.itemPermission, |
| 127 | isDirty: true |
| 128 | } |
| 129 | }; |
| 130 | |
| 131 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolAfterAdd]); |
| 132 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 133 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 134 | mockRest.addHandler('post', ({data, options, baseUrl}) => { |
| 135 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`); |
| 136 | expect(data).toEqual(EntitlementPoolPostRequest); |
| 137 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 138 | return { |
| 139 | returnCode: 'OK', |
| 140 | value: entitlementPoolIdFromResponse |
| 141 | }; |
| 142 | }); |
| 143 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 144 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 145 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 146 | expect(data).toEqual(undefined); |
| 147 | expect(options).toEqual(undefined); |
| 148 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 149 | }); |
| 150 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 151 | return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, |
| 152 | { |
| 153 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 154 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 155 | previousEntitlementPool: null, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 156 | entitlementPool: EntitlementPoolPostRequest |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 157 | } |
| 158 | ).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 159 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 160 | }); |
| 161 | }); |
| 162 | |
| 163 | it('Update Entitlement Pool', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 164 | |
| 165 | const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory, 1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 166 | deepFreeze(entitlementPoolsList); |
| 167 | |
| 168 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 169 | currentScreen: {...itemPermissionAndProps}, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 170 | licenseModel: { |
| 171 | entitlementPool: { |
| 172 | entitlementPoolsList |
| 173 | } |
| 174 | } |
| 175 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 176 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 177 | deepFreeze(store.getState()); |
| 178 | |
| 179 | const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id; |
| 180 | const previousEntitlementPoolData = entitlementPoolsList[0]; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 181 | const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED', id: toBeUpdatedEntitlementPoolId}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 182 | deepFreeze(entitlementPoolUpdateData); |
| 183 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 184 | const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED'}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 185 | deepFreeze(entitlementPoolPutRequest); |
| 186 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 187 | const expectedCurrentScreenProps = { |
| 188 | ...itemPermissionAndProps, |
| 189 | itemPermission: { |
| 190 | ...itemPermissionAndProps.itemPermission, |
| 191 | isDirty: true |
| 192 | } |
| 193 | }; |
| 194 | |
| 195 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]); |
| 196 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 197 | |
| 198 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 199 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 200 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${toBeUpdatedEntitlementPoolId}`); |
| 201 | expect(data).toEqual(entitlementPoolPutRequest); |
| 202 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 203 | return {returnCode: 'OK'}; |
| 204 | }); |
| 205 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 206 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 207 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 208 | expect(data).toEqual(undefined); |
| 209 | expect(options).toEqual(undefined); |
| 210 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 211 | }); |
| 212 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 213 | return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, { |
| 214 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 215 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 216 | previousEntitlementPool: previousEntitlementPoolData, |
| 217 | entitlementPool: entitlementPoolUpdateData |
| 218 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 219 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 220 | }); |
| 221 | }); |
| 222 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 223 | it('Load Limits List', () => { |
| 224 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 225 | const limitsList = LimitItemFactory.buildList(3); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 226 | deepFreeze(limitsList); |
| 227 | const store = storeCreator(); |
| 228 | deepFreeze(store.getState()); |
| 229 | |
| 230 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', limitsList); |
| 231 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 232 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 233 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 234 | expect(data).toEqual(undefined); |
| 235 | expect(options).toEqual(undefined); |
| 236 | return {results: limitsList}; |
| 237 | }); |
| 238 | |
| 239 | return EntitlementPoolsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, entitlementPool}).then(() => { |
| 240 | expect(store.getState()).toEqual(expectedStore); |
| 241 | }); |
| 242 | }); |
| 243 | |
| 244 | it('Add Limit', () => { |
| 245 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 246 | const store = storeCreator({ |
| 247 | currentScreen: {...itemPermissionAndProps} |
| 248 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 249 | deepFreeze(store.getState()); |
| 250 | |
| 251 | const limitToAdd = LimitPostFactory.build(); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 252 | let limitFromBE = {...limitToAdd}; |
| 253 | limitFromBE.metric = getStrValue(limitFromBE.metric); |
| 254 | limitFromBE.unit = getStrValue(limitFromBE.unit); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 255 | |
| 256 | deepFreeze(limitToAdd); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 257 | deepFreeze(limitFromBE); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 258 | |
| 259 | const LimitIdFromResponse = 'ADDED_ID'; |
| 260 | const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse}; |
| 261 | deepFreeze(limitAddedItem); |
| 262 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 263 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 264 | const expectedCurrentScreenProps = { |
| 265 | ...itemPermissionAndProps, |
| 266 | itemPermission: { |
| 267 | ...itemPermissionAndProps.itemPermission, |
| 268 | isDirty: true |
| 269 | } |
| 270 | }; |
| 271 | |
| 272 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [limitAddedItem]); |
| 273 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 274 | |
| 275 | mockRest.addHandler('post', ({data, options, baseUrl}) => { |
| 276 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 277 | expect(data).toEqual(limitFromBE); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 278 | expect(options).toEqual(undefined); |
| 279 | return { |
| 280 | returnCode: 'OK', |
| 281 | value: LimitIdFromResponse |
| 282 | }; |
| 283 | }); |
| 284 | |
| 285 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 286 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 287 | expect(data).toEqual(undefined); |
| 288 | expect(options).toEqual(undefined); |
| 289 | return {results: [limitAddedItem]}; |
| 290 | }); |
| 291 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 292 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 293 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 294 | expect(data).toEqual(undefined); |
| 295 | expect(options).toEqual(undefined); |
| 296 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 297 | }); |
| 298 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 299 | return EntitlementPoolsActionHelper.submitLimit(store.dispatch, |
| 300 | { |
| 301 | licenseModelId: LICENSE_MODEL_ID, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 302 | version, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 303 | entitlementPool, |
| 304 | limit: limitToAdd |
| 305 | } |
| 306 | ).then(() => { |
| 307 | expect(store.getState()).toEqual(expectedStore); |
| 308 | }); |
| 309 | }); |
| 310 | |
| 311 | |
| 312 | it('Delete Limit', () => { |
| 313 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 314 | const limitsList = LimitItemFactory.buildList(1); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 315 | deepFreeze(limitsList); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 316 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 317 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 318 | currentScreen: {...itemPermissionAndProps}, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 319 | licenseModel: { |
| 320 | entitlementPool: { |
| 321 | entitlementPoolEditor: { |
| 322 | limitsList |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | }); |
| 327 | deepFreeze(store.getState()); |
| 328 | |
| 329 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 330 | |
| 331 | const expectedCurrentScreenProps = { |
| 332 | ...itemPermissionAndProps, |
| 333 | itemPermission: { |
| 334 | ...itemPermissionAndProps.itemPermission, |
| 335 | isDirty: true |
| 336 | } |
| 337 | }; |
| 338 | |
| 339 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', []); |
| 340 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 341 | |
| 342 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
| 343 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits/${limitsList[0].id}`); |
| 344 | expect(data).toEqual(undefined); |
| 345 | expect(options).toEqual(undefined); |
| 346 | return { |
| 347 | results: { |
| 348 | returnCode: 'OK' |
| 349 | } |
| 350 | }; |
| 351 | }); |
| 352 | |
| 353 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 354 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 355 | expect(data).toEqual(undefined); |
| 356 | expect(options).toEqual(undefined); |
| 357 | return {results: []}; |
| 358 | }); |
| 359 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 360 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 361 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 362 | expect(data).toEqual(undefined); |
| 363 | expect(options).toEqual(undefined); |
| 364 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 365 | }); |
| 366 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 367 | return EntitlementPoolsActionHelper.deleteLimit(store.dispatch, { |
| 368 | licenseModelId: LICENSE_MODEL_ID, |
| 369 | version, |
| 370 | entitlementPool, |
| 371 | limit: limitsList[0] |
| 372 | }).then(() => { |
| 373 | expect(store.getState()).toEqual(expectedStore); |
| 374 | }); |
| 375 | }); |
| 376 | |
| 377 | it('Update Limit', () => { |
| 378 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 379 | const limitsList = LimitItemFactory.buildList(1); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 380 | deepFreeze(limitsList); |
| 381 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 382 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 383 | currentScreen: {...itemPermissionAndProps}, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 384 | licenseModel: { |
| 385 | entitlementPool: { |
| 386 | entitlementPoolEditor: { |
| 387 | limitsList |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | }); |
| 392 | |
| 393 | deepFreeze(store.getState()); |
| 394 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 395 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 396 | const previousData = limitsList[0]; |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 397 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 398 | deepFreeze(previousData); |
| 399 | const limitId = limitsList[0].id; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 400 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 401 | let updatedLimit = {...previousData, name: 'updatedLimit'}; |
| 402 | |
| 403 | const updatedLimitForPut = {...updatedLimit, id: undefined}; |
| 404 | updatedLimit.metric = {choice: updatedLimit.metric, other: ''}; |
| 405 | updatedLimit.unit = {choice: updatedLimit.unit, other: ''}; |
| 406 | deepFreeze(updatedLimit); |
| 407 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 408 | const expectedCurrentScreenProps = { |
| 409 | ...itemPermissionAndProps, |
| 410 | itemPermission: { |
| 411 | ...itemPermissionAndProps.itemPermission, |
| 412 | isDirty: true |
| 413 | } |
| 414 | }; |
| 415 | |
| 416 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [updatedLimitForPut]); |
| 417 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 418 | |
| 419 | |
| 420 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 421 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits/${limitId}`); |
| 422 | expect(data).toEqual(updatedLimitForPut); |
| 423 | expect(options).toEqual(undefined); |
| 424 | return {returnCode: 'OK'}; |
| 425 | }); |
| 426 | |
| 427 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 428 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 429 | expect(data).toEqual(undefined); |
| 430 | expect(options).toEqual(undefined); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 431 | return {results: [updatedLimitForPut]}; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 432 | }); |
| 433 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 434 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 435 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 436 | expect(data).toEqual(undefined); |
| 437 | expect(options).toEqual(undefined); |
| 438 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 439 | }); |
| 440 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 441 | return EntitlementPoolsActionHelper.submitLimit(store.dispatch, |
| 442 | { |
| 443 | licenseModelId: LICENSE_MODEL_ID, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 444 | version, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 445 | entitlementPool, |
| 446 | limit: updatedLimit |
| 447 | } |
| 448 | ).then(() => { |
| 449 | expect(store.getState()).toEqual(expectedStore); |
| 450 | }); |
| 451 | }); |
| 452 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 453 | }); |