blob: 173384dc02ec23bfa1a7db0a62d0d48603548717 [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 });
91
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 });
98
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
Michael Landoefa037d2017-02-19 12:57:33 +0200151 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch,
152 {
153 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300154 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200155 previousEntitlementPool: null,
AviZi280f8012017-06-09 02:39:56 +0300156 entitlementPool: EntitlementPoolPostRequest
Michael Landoefa037d2017-02-19 12:57:33 +0200157 }
158 ).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300159 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200160 });
161 });
162
163 it('Update Entitlement Pool', () => {
AviZi280f8012017-06-09 02:39:56 +0300164
165 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory, 1);
Michael Landoefa037d2017-02-19 12:57:33 +0200166 deepFreeze(entitlementPoolsList);
167
168 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +0200169 currentScreen: {...itemPermissionAndProps},
Michael Landoefa037d2017-02-19 12:57:33 +0200170 licenseModel: {
171 entitlementPool: {
172 entitlementPoolsList
173 }
174 }
175 });
AviZi280f8012017-06-09 02:39:56 +0300176
Michael Landoefa037d2017-02-19 12:57:33 +0200177 deepFreeze(store.getState());
178
179 const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id;
180 const previousEntitlementPoolData = entitlementPoolsList[0];
AviZi280f8012017-06-09 02:39:56 +0300181 const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED', id: toBeUpdatedEntitlementPoolId});
Michael Landoefa037d2017-02-19 12:57:33 +0200182 deepFreeze(entitlementPoolUpdateData);
183
AviZi280f8012017-06-09 02:39:56 +0300184 const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED'});
Michael Landoefa037d2017-02-19 12:57:33 +0200185 deepFreeze(entitlementPoolPutRequest);
186
talig8e9c0652017-12-20 14:30:43 +0200187 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 Landoefa037d2017-02-19 12:57:33 +0200197
198
AviZi280f8012017-06-09 02:39:56 +0300199 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 Landoefa037d2017-02-19 12:57:33 +0200203 return {returnCode: 'OK'};
204 });
205
talig8e9c0652017-12-20 14:30:43 +0200206 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 Landoefa037d2017-02-19 12:57:33 +0200213 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, {
214 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300215 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200216 previousEntitlementPool: previousEntitlementPoolData,
217 entitlementPool: entitlementPoolUpdateData
218 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300219 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200220 });
221 });
222
Avi Ziv61070c92017-07-26 17:37:57 +0300223 it('Load Limits List', () => {
224
az2497644017c2017-08-10 17:49:40 +0300225 const limitsList = LimitItemFactory.buildList(3);
Avi Ziv61070c92017-07-26 17:37:57 +0300226 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
talig8e9c0652017-12-20 14:30:43 +0200246 const store = storeCreator({
247 currentScreen: {...itemPermissionAndProps}
248 });
Avi Ziv61070c92017-07-26 17:37:57 +0300249 deepFreeze(store.getState());
250
251 const limitToAdd = LimitPostFactory.build();
az2497644017c2017-08-10 17:49:40 +0300252 let limitFromBE = {...limitToAdd};
253 limitFromBE.metric = getStrValue(limitFromBE.metric);
254 limitFromBE.unit = getStrValue(limitFromBE.unit);
Avi Ziv61070c92017-07-26 17:37:57 +0300255
256 deepFreeze(limitToAdd);
az2497644017c2017-08-10 17:49:40 +0300257 deepFreeze(limitFromBE);
Avi Ziv61070c92017-07-26 17:37:57 +0300258
259 const LimitIdFromResponse = 'ADDED_ID';
260 const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse};
261 deepFreeze(limitAddedItem);
262 const entitlementPool = EntitlementPoolStoreFactory.build();
263
talig8e9c0652017-12-20 14:30:43 +0200264 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 Ziv61070c92017-07-26 17:37:57 +0300274
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`);
az2497644017c2017-08-10 17:49:40 +0300277 expect(data).toEqual(limitFromBE);
Avi Ziv61070c92017-07-26 17:37:57 +0300278 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
talig8e9c0652017-12-20 14:30:43 +0200292 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 Ziv61070c92017-07-26 17:37:57 +0300299 return EntitlementPoolsActionHelper.submitLimit(store.dispatch,
300 {
301 licenseModelId: LICENSE_MODEL_ID,
az2497644017c2017-08-10 17:49:40 +0300302 version,
Avi Ziv61070c92017-07-26 17:37:57 +0300303 entitlementPool,
304 limit: limitToAdd
305 }
306 ).then(() => {
307 expect(store.getState()).toEqual(expectedStore);
308 });
309 });
310
311
312 it('Delete Limit', () => {
313
az2497644017c2017-08-10 17:49:40 +0300314 const limitsList = LimitItemFactory.buildList(1);
Avi Ziv61070c92017-07-26 17:37:57 +0300315 deepFreeze(limitsList);
az2497644017c2017-08-10 17:49:40 +0300316
Avi Ziv61070c92017-07-26 17:37:57 +0300317 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +0200318 currentScreen: {...itemPermissionAndProps},
Avi Ziv61070c92017-07-26 17:37:57 +0300319 licenseModel: {
320 entitlementPool: {
321 entitlementPoolEditor: {
322 limitsList
323 }
324 }
325 }
326 });
327 deepFreeze(store.getState());
328
329 const entitlementPool = EntitlementPoolStoreFactory.build();
talig8e9c0652017-12-20 14:30:43 +0200330
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 Ziv61070c92017-07-26 17:37:57 +0300341
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
talig8e9c0652017-12-20 14:30:43 +0200360 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 Ziv61070c92017-07-26 17:37:57 +0300367 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
az2497644017c2017-08-10 17:49:40 +0300379 const limitsList = LimitItemFactory.buildList(1);
Avi Ziv61070c92017-07-26 17:37:57 +0300380 deepFreeze(limitsList);
381 const entitlementPool = EntitlementPoolStoreFactory.build();
382 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +0200383 currentScreen: {...itemPermissionAndProps},
Avi Ziv61070c92017-07-26 17:37:57 +0300384 licenseModel: {
385 entitlementPool: {
386 entitlementPoolEditor: {
387 limitsList
388 }
389 }
390 }
391 });
392
393 deepFreeze(store.getState());
394
az2497644017c2017-08-10 17:49:40 +0300395
Avi Ziv61070c92017-07-26 17:37:57 +0300396 const previousData = limitsList[0];
az2497644017c2017-08-10 17:49:40 +0300397
Avi Ziv61070c92017-07-26 17:37:57 +0300398 deepFreeze(previousData);
399 const limitId = limitsList[0].id;
Avi Ziv61070c92017-07-26 17:37:57 +0300400
az2497644017c2017-08-10 17:49:40 +0300401 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
talig8e9c0652017-12-20 14:30:43 +0200408 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 Ziv61070c92017-07-26 17:37:57 +0300418
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);
az2497644017c2017-08-10 17:49:40 +0300431 return {results: [updatedLimitForPut]};
Avi Ziv61070c92017-07-26 17:37:57 +0300432 });
433
talig8e9c0652017-12-20 14:30:43 +0200434 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 Ziv61070c92017-07-26 17:37:57 +0300441 return EntitlementPoolsActionHelper.submitLimit(store.dispatch,
442 {
443 licenseModelId: LICENSE_MODEL_ID,
az2497644017c2017-08-10 17:49:40 +0300444 version,
Avi Ziv61070c92017-07-26 17:37:57 +0300445 entitlementPool,
446 limit: updatedLimit
447 }
448 ).then(() => {
449 expect(store.getState()).toEqual(expectedStore);
450 });
451 });
452
Michael Landoefa037d2017-02-19 12:57:33 +0200453});