blob: dc56b11f1b5d7bd843287ef4f985cca038c6c18b [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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
AviZi280f8012017-06-09 02:39:56 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * 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 Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import deepFreeze from 'deep-freeze';
Michael Landoefa037d2017-02-19 12:57:33 +020017import mockRest from 'test-utils/MockRest.js';
AviZi280f8012017-06-09 02:39:56 +030018import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
Michael Landoefa037d2017-02-19 12:57:33 +020019import {storeCreator} from 'sdc-app/AppStore.js';
20import EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
AviZi280f8012017-06-09 02:39:56 +030021import {EntitlementPoolStoreFactory, EntitlementPoolPostFactory} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js';
talig8e9c0652017-12-20 14:30:43 +020022import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
Avi Ziv61070c92017-07-26 17:37:57 +030023import {LimitItemFactory, LimitPostFactory} from 'test-utils/factories/licenseModel/LimitFactories.js';
az2497644017c2017-08-10 17:49:40 +030024import {getStrValue} from 'nfvo-utils/getValue.js';
talig8e9c0652017-12-20 14:30:43 +020025import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js';
26import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
Michael Landoefa037d2017-02-19 12:57:33 +020027
28describe('Entitlement Pools Module Tests', function () {
29
30 const LICENSE_MODEL_ID = '555';
talig8e9c0652017-12-20 14:30:43 +020031 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 Landoefa037d2017-02-19 12:57:33 +020034
35 it('Load Entitlement Pools List', () => {
AviZi280f8012017-06-09 02:39:56 +030036
37 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory);
Michael Landoefa037d2017-02-19 12:57:33 +020038 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}) => {
AviZi280f8012017-06-09 02:39:56 +030045 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 Landoefa037d2017-02-19 12:57:33 +020048 return {results: entitlementPoolsList};
49 });
50
AviZi280f8012017-06-09 02:39:56 +030051 return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
52 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020053 });
54 });
55
56 it('Delete Entitlement Pool', () => {
Michael Landoefa037d2017-02-19 12:57:33 +020057
AviZi280f8012017-06-09 02:39:56 +030058 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory,1);
Michael Landoefa037d2017-02-19 12:57:33 +020059 deepFreeze(entitlementPoolsList);
60 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +020061 currentScreen: {...itemPermissionAndProps},
Michael Landoefa037d2017-02-19 12:57:33 +020062 licenseModel: {
63 entitlementPool: {
64 entitlementPoolsList
65 }
66 }
67 });
68 deepFreeze(store.getState());
69
talig8e9c0652017-12-20 14:30:43 +020070 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 Landoefa037d2017-02-19 12:57:33 +020080
81 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030082 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 Landoefa037d2017-02-19 12:57:33 +020085 return {
86 results: {
87 returnCode: 'OK'
88 }
89 };
90 });
svishnev091edfd2018-03-19 12:15:19 +020091
talig8e9c0652017-12-20 14:30:43 +020092 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 });
svishnev091edfd2018-03-19 12:15:19 +020098
Michael Landoefa037d2017-02-19 12:57:33 +020099 return EntitlementPoolsActionHelper.deleteEntitlementPool(store.dispatch, {
100 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300101 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200102 entitlementPoolId: entitlementPoolsList[0].id
103 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300104 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200105 });
106 });
107
108 it('Add Entitlement Pool', () => {
109
talig8e9c0652017-12-20 14:30:43 +0200110 const store = storeCreator({
111 currentScreen: {...itemPermissionAndProps}
112 });
Michael Landoefa037d2017-02-19 12:57:33 +0200113 deepFreeze(store.getState());
114
AviZi280f8012017-06-09 02:39:56 +0300115 const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build();
116
117 deepFreeze(EntitlementPoolPostRequest);
118
Michael Landoefa037d2017-02-19 12:57:33 +0200119 const entitlementPoolIdFromResponse = 'ADDED_ID';
AviZi280f8012017-06-09 02:39:56 +0300120 const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({id: entitlementPoolIdFromResponse});
121 deepFreeze(entitlementPoolAfterAdd);
Michael Landoefa037d2017-02-19 12:57:33 +0200122
talig8e9c0652017-12-20 14:30:43 +0200123 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 Landoefa037d2017-02-19 12:57:33 +0200133
AviZi280f8012017-06-09 02:39:56 +0300134 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 Landoefa037d2017-02-19 12:57:33 +0200138 return {
139 returnCode: 'OK',
140 value: entitlementPoolIdFromResponse
141 };
142 });
143
talig8e9c0652017-12-20 14:30:43 +0200144 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
svishnev091edfd2018-03-19 12:15:19 +0200151
152
Michael Landoefa037d2017-02-19 12:57:33 +0200153 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch,
154 {
155 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300156 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200157 previousEntitlementPool: null,
AviZi280f8012017-06-09 02:39:56 +0300158 entitlementPool: EntitlementPoolPostRequest
Michael Landoefa037d2017-02-19 12:57:33 +0200159 }
160 ).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300161 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200162 });
163 });
164
165 it('Update Entitlement Pool', () => {
AviZi280f8012017-06-09 02:39:56 +0300166
167 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory, 1);
Michael Landoefa037d2017-02-19 12:57:33 +0200168 deepFreeze(entitlementPoolsList);
169
170 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +0200171 currentScreen: {...itemPermissionAndProps},
Michael Landoefa037d2017-02-19 12:57:33 +0200172 licenseModel: {
173 entitlementPool: {
174 entitlementPoolsList
175 }
176 }
177 });
AviZi280f8012017-06-09 02:39:56 +0300178
Michael Landoefa037d2017-02-19 12:57:33 +0200179 deepFreeze(store.getState());
180
181 const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id;
182 const previousEntitlementPoolData = entitlementPoolsList[0];
AviZi280f8012017-06-09 02:39:56 +0300183 const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED', id: toBeUpdatedEntitlementPoolId});
Michael Landoefa037d2017-02-19 12:57:33 +0200184 deepFreeze(entitlementPoolUpdateData);
185
AviZi280f8012017-06-09 02:39:56 +0300186 const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED'});
Michael Landoefa037d2017-02-19 12:57:33 +0200187 deepFreeze(entitlementPoolPutRequest);
188
talig8e9c0652017-12-20 14:30:43 +0200189 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 Landoefa037d2017-02-19 12:57:33 +0200199
200
AviZi280f8012017-06-09 02:39:56 +0300201 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 Landoefa037d2017-02-19 12:57:33 +0200205 return {returnCode: 'OK'};
206 });
207
talig8e9c0652017-12-20 14:30:43 +0200208 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 Landoefa037d2017-02-19 12:57:33 +0200215 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, {
216 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300217 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200218 previousEntitlementPool: previousEntitlementPoolData,
219 entitlementPool: entitlementPoolUpdateData
220 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300221 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200222 });
223 });
224
Avi Ziv61070c92017-07-26 17:37:57 +0300225 it('Load Limits List', () => {
226
az2497644017c2017-08-10 17:49:40 +0300227 const limitsList = LimitItemFactory.buildList(3);
Avi Ziv61070c92017-07-26 17:37:57 +0300228 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
talig8e9c0652017-12-20 14:30:43 +0200248 const store = storeCreator({
249 currentScreen: {...itemPermissionAndProps}
250 });
Avi Ziv61070c92017-07-26 17:37:57 +0300251 deepFreeze(store.getState());
252
253 const limitToAdd = LimitPostFactory.build();
az2497644017c2017-08-10 17:49:40 +0300254 let limitFromBE = {...limitToAdd};
255 limitFromBE.metric = getStrValue(limitFromBE.metric);
256 limitFromBE.unit = getStrValue(limitFromBE.unit);
Avi Ziv61070c92017-07-26 17:37:57 +0300257
258 deepFreeze(limitToAdd);
az2497644017c2017-08-10 17:49:40 +0300259 deepFreeze(limitFromBE);
Avi Ziv61070c92017-07-26 17:37:57 +0300260
261 const LimitIdFromResponse = 'ADDED_ID';
262 const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse};
263 deepFreeze(limitAddedItem);
264 const entitlementPool = EntitlementPoolStoreFactory.build();
265
talig8e9c0652017-12-20 14:30:43 +0200266 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 Ziv61070c92017-07-26 17:37:57 +0300276
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`);
az2497644017c2017-08-10 17:49:40 +0300279 expect(data).toEqual(limitFromBE);
Avi Ziv61070c92017-07-26 17:37:57 +0300280 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
talig8e9c0652017-12-20 14:30:43 +0200294 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 Ziv61070c92017-07-26 17:37:57 +0300301 return EntitlementPoolsActionHelper.submitLimit(store.dispatch,
302 {
303 licenseModelId: LICENSE_MODEL_ID,
az2497644017c2017-08-10 17:49:40 +0300304 version,
Avi Ziv61070c92017-07-26 17:37:57 +0300305 entitlementPool,
306 limit: limitToAdd
307 }
308 ).then(() => {
309 expect(store.getState()).toEqual(expectedStore);
310 });
311 });
312
313
314 it('Delete Limit', () => {
315
az2497644017c2017-08-10 17:49:40 +0300316 const limitsList = LimitItemFactory.buildList(1);
Avi Ziv61070c92017-07-26 17:37:57 +0300317 deepFreeze(limitsList);
az2497644017c2017-08-10 17:49:40 +0300318
Avi Ziv61070c92017-07-26 17:37:57 +0300319 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +0200320 currentScreen: {...itemPermissionAndProps},
Avi Ziv61070c92017-07-26 17:37:57 +0300321 licenseModel: {
322 entitlementPool: {
323 entitlementPoolEditor: {
324 limitsList
325 }
326 }
327 }
328 });
329 deepFreeze(store.getState());
330
331 const entitlementPool = EntitlementPoolStoreFactory.build();
talig8e9c0652017-12-20 14:30:43 +0200332
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 Ziv61070c92017-07-26 17:37:57 +0300343
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
talig8e9c0652017-12-20 14:30:43 +0200362 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 Ziv61070c92017-07-26 17:37:57 +0300369 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
az2497644017c2017-08-10 17:49:40 +0300381 const limitsList = LimitItemFactory.buildList(1);
Avi Ziv61070c92017-07-26 17:37:57 +0300382 deepFreeze(limitsList);
383 const entitlementPool = EntitlementPoolStoreFactory.build();
384 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +0200385 currentScreen: {...itemPermissionAndProps},
Avi Ziv61070c92017-07-26 17:37:57 +0300386 licenseModel: {
387 entitlementPool: {
388 entitlementPoolEditor: {
389 limitsList
390 }
391 }
392 }
393 });
394
395 deepFreeze(store.getState());
396
az2497644017c2017-08-10 17:49:40 +0300397
Avi Ziv61070c92017-07-26 17:37:57 +0300398 const previousData = limitsList[0];
az2497644017c2017-08-10 17:49:40 +0300399
Avi Ziv61070c92017-07-26 17:37:57 +0300400 deepFreeze(previousData);
401 const limitId = limitsList[0].id;
Avi Ziv61070c92017-07-26 17:37:57 +0300402
az2497644017c2017-08-10 17:49:40 +0300403 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
talig8e9c0652017-12-20 14:30:43 +0200410 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 Ziv61070c92017-07-26 17:37:57 +0300420
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);
az2497644017c2017-08-10 17:49:40 +0300433 return {results: [updatedLimitForPut]};
Avi Ziv61070c92017-07-26 17:37:57 +0300434 });
435
talig8e9c0652017-12-20 14:30:43 +0200436 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 Ziv61070c92017-07-26 17:37:57 +0300443 return EntitlementPoolsActionHelper.submitLimit(store.dispatch,
444 {
445 licenseModelId: LICENSE_MODEL_ID,
az2497644017c2017-08-10 17:49:40 +0300446 version,
Avi Ziv61070c92017-07-26 17:37:57 +0300447 entitlementPool,
448 limit: updatedLimit
449 }
450 ).then(() => {
451 expect(store.getState()).toEqual(expectedStore);
452 });
453 });
454
Michael Landoefa037d2017-02-19 12:57:33 +0200455});