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 | }); |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 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 | }); |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 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 | |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 151 | |
| 152 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 153 | return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, |
| 154 | { |
| 155 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 156 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 157 | previousEntitlementPool: null, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 158 | entitlementPool: EntitlementPoolPostRequest |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 159 | } |
| 160 | ).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 161 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 162 | }); |
| 163 | }); |
| 164 | |
| 165 | it('Update Entitlement Pool', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 166 | |
| 167 | const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory, 1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 168 | deepFreeze(entitlementPoolsList); |
| 169 | |
| 170 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 171 | currentScreen: {...itemPermissionAndProps}, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 172 | licenseModel: { |
| 173 | entitlementPool: { |
| 174 | entitlementPoolsList |
| 175 | } |
| 176 | } |
| 177 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 178 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 179 | deepFreeze(store.getState()); |
| 180 | |
| 181 | const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id; |
| 182 | const previousEntitlementPoolData = entitlementPoolsList[0]; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 183 | const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED', id: toBeUpdatedEntitlementPoolId}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 184 | deepFreeze(entitlementPoolUpdateData); |
| 185 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 186 | const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED'}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 187 | deepFreeze(entitlementPoolPutRequest); |
| 188 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 189 | const expectedCurrentScreenProps = { |
| 190 | ...itemPermissionAndProps, |
| 191 | itemPermission: { |
| 192 | ...itemPermissionAndProps.itemPermission, |
| 193 | isDirty: true |
| 194 | } |
| 195 | }; |
| 196 | |
| 197 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]); |
| 198 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 199 | |
| 200 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 201 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 202 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${toBeUpdatedEntitlementPoolId}`); |
| 203 | expect(data).toEqual(entitlementPoolPutRequest); |
| 204 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 205 | return {returnCode: 'OK'}; |
| 206 | }); |
| 207 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 208 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 209 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 210 | expect(data).toEqual(undefined); |
| 211 | expect(options).toEqual(undefined); |
| 212 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 213 | }); |
| 214 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 215 | return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, { |
| 216 | licenseModelId: LICENSE_MODEL_ID, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 217 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 218 | previousEntitlementPool: previousEntitlementPoolData, |
| 219 | entitlementPool: entitlementPoolUpdateData |
| 220 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 221 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 222 | }); |
| 223 | }); |
| 224 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 225 | it('Load Limits List', () => { |
| 226 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 227 | const limitsList = LimitItemFactory.buildList(3); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 228 | deepFreeze(limitsList); |
| 229 | const store = storeCreator(); |
| 230 | deepFreeze(store.getState()); |
| 231 | |
| 232 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', limitsList); |
| 233 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 234 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 235 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 236 | expect(data).toEqual(undefined); |
| 237 | expect(options).toEqual(undefined); |
| 238 | return {results: limitsList}; |
| 239 | }); |
| 240 | |
| 241 | return EntitlementPoolsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, entitlementPool}).then(() => { |
| 242 | expect(store.getState()).toEqual(expectedStore); |
| 243 | }); |
| 244 | }); |
| 245 | |
| 246 | it('Add Limit', () => { |
| 247 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 248 | const store = storeCreator({ |
| 249 | currentScreen: {...itemPermissionAndProps} |
| 250 | }); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 251 | deepFreeze(store.getState()); |
| 252 | |
| 253 | const limitToAdd = LimitPostFactory.build(); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 254 | let limitFromBE = {...limitToAdd}; |
| 255 | limitFromBE.metric = getStrValue(limitFromBE.metric); |
| 256 | limitFromBE.unit = getStrValue(limitFromBE.unit); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 257 | |
| 258 | deepFreeze(limitToAdd); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 259 | deepFreeze(limitFromBE); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 260 | |
| 261 | const LimitIdFromResponse = 'ADDED_ID'; |
| 262 | const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse}; |
| 263 | deepFreeze(limitAddedItem); |
| 264 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 265 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 266 | const expectedCurrentScreenProps = { |
| 267 | ...itemPermissionAndProps, |
| 268 | itemPermission: { |
| 269 | ...itemPermissionAndProps.itemPermission, |
| 270 | isDirty: true |
| 271 | } |
| 272 | }; |
| 273 | |
| 274 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [limitAddedItem]); |
| 275 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 276 | |
| 277 | mockRest.addHandler('post', ({data, options, baseUrl}) => { |
| 278 | 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] | 279 | expect(data).toEqual(limitFromBE); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 280 | expect(options).toEqual(undefined); |
| 281 | return { |
| 282 | returnCode: 'OK', |
| 283 | value: LimitIdFromResponse |
| 284 | }; |
| 285 | }); |
| 286 | |
| 287 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 288 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 289 | expect(data).toEqual(undefined); |
| 290 | expect(options).toEqual(undefined); |
| 291 | return {results: [limitAddedItem]}; |
| 292 | }); |
| 293 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 294 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 295 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 296 | expect(data).toEqual(undefined); |
| 297 | expect(options).toEqual(undefined); |
| 298 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 299 | }); |
| 300 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 301 | return EntitlementPoolsActionHelper.submitLimit(store.dispatch, |
| 302 | { |
| 303 | licenseModelId: LICENSE_MODEL_ID, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 304 | version, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 305 | entitlementPool, |
| 306 | limit: limitToAdd |
| 307 | } |
| 308 | ).then(() => { |
| 309 | expect(store.getState()).toEqual(expectedStore); |
| 310 | }); |
| 311 | }); |
| 312 | |
| 313 | |
| 314 | it('Delete Limit', () => { |
| 315 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 316 | const limitsList = LimitItemFactory.buildList(1); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 317 | deepFreeze(limitsList); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 318 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 319 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 320 | currentScreen: {...itemPermissionAndProps}, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 321 | licenseModel: { |
| 322 | entitlementPool: { |
| 323 | entitlementPoolEditor: { |
| 324 | limitsList |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | }); |
| 329 | deepFreeze(store.getState()); |
| 330 | |
| 331 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 332 | |
| 333 | const expectedCurrentScreenProps = { |
| 334 | ...itemPermissionAndProps, |
| 335 | itemPermission: { |
| 336 | ...itemPermissionAndProps.itemPermission, |
| 337 | isDirty: true |
| 338 | } |
| 339 | }; |
| 340 | |
| 341 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', []); |
| 342 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 343 | |
| 344 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
| 345 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits/${limitsList[0].id}`); |
| 346 | expect(data).toEqual(undefined); |
| 347 | expect(options).toEqual(undefined); |
| 348 | return { |
| 349 | results: { |
| 350 | returnCode: 'OK' |
| 351 | } |
| 352 | }; |
| 353 | }); |
| 354 | |
| 355 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 356 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 357 | expect(data).toEqual(undefined); |
| 358 | expect(options).toEqual(undefined); |
| 359 | return {results: []}; |
| 360 | }); |
| 361 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 362 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 363 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 364 | expect(data).toEqual(undefined); |
| 365 | expect(options).toEqual(undefined); |
| 366 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 367 | }); |
| 368 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 369 | return EntitlementPoolsActionHelper.deleteLimit(store.dispatch, { |
| 370 | licenseModelId: LICENSE_MODEL_ID, |
| 371 | version, |
| 372 | entitlementPool, |
| 373 | limit: limitsList[0] |
| 374 | }).then(() => { |
| 375 | expect(store.getState()).toEqual(expectedStore); |
| 376 | }); |
| 377 | }); |
| 378 | |
| 379 | it('Update Limit', () => { |
| 380 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 381 | const limitsList = LimitItemFactory.buildList(1); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 382 | deepFreeze(limitsList); |
| 383 | const entitlementPool = EntitlementPoolStoreFactory.build(); |
| 384 | const store = storeCreator({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 385 | currentScreen: {...itemPermissionAndProps}, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 386 | licenseModel: { |
| 387 | entitlementPool: { |
| 388 | entitlementPoolEditor: { |
| 389 | limitsList |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | }); |
| 394 | |
| 395 | deepFreeze(store.getState()); |
| 396 | |
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 | const previousData = limitsList[0]; |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 399 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 400 | deepFreeze(previousData); |
| 401 | const limitId = limitsList[0].id; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 402 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 403 | let updatedLimit = {...previousData, name: 'updatedLimit'}; |
| 404 | |
| 405 | const updatedLimitForPut = {...updatedLimit, id: undefined}; |
| 406 | updatedLimit.metric = {choice: updatedLimit.metric, other: ''}; |
| 407 | updatedLimit.unit = {choice: updatedLimit.unit, other: ''}; |
| 408 | deepFreeze(updatedLimit); |
| 409 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 410 | const expectedCurrentScreenProps = { |
| 411 | ...itemPermissionAndProps, |
| 412 | itemPermission: { |
| 413 | ...itemPermissionAndProps.itemPermission, |
| 414 | isDirty: true |
| 415 | } |
| 416 | }; |
| 417 | |
| 418 | let expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [updatedLimitForPut]); |
| 419 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 420 | |
| 421 | |
| 422 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 423 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits/${limitId}`); |
| 424 | expect(data).toEqual(updatedLimitForPut); |
| 425 | expect(options).toEqual(undefined); |
| 426 | return {returnCode: 'OK'}; |
| 427 | }); |
| 428 | |
| 429 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 430 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`); |
| 431 | expect(data).toEqual(undefined); |
| 432 | expect(options).toEqual(undefined); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 433 | return {results: [updatedLimitForPut]}; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 434 | }); |
| 435 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 436 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 437 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`); |
| 438 | expect(data).toEqual(undefined); |
| 439 | expect(options).toEqual(undefined); |
| 440 | return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}}; |
| 441 | }); |
| 442 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 443 | return EntitlementPoolsActionHelper.submitLimit(store.dispatch, |
| 444 | { |
| 445 | licenseModelId: LICENSE_MODEL_ID, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 446 | version, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 447 | entitlementPool, |
| 448 | limit: updatedLimit |
| 449 | } |
| 450 | ).then(() => { |
| 451 | expect(store.getState()).toEqual(expectedStore); |
| 452 | }); |
| 453 | }); |
| 454 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 455 | }); |