blob: 63eab1f7b9738fe7f1c9f82f1ebdb32bbb79f730 [file] [log] [blame]
svishnev57c5c4a2018-04-22 14:14:31 +03001/*
2 * Copyright © 2016-2018 European Support Limited
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
svishnev57c5c4a2018-04-22 14:14:31 +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,
svishnev57c5c4a2018-04-22 14:14:31 +030012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * 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';
svishnev57c5c4a2018-04-22 14:14:31 +030018import { cloneAndSet, buildListFromFactory } from 'test-utils/Util.js';
19import { storeCreator } from 'sdc-app/AppStore.js';
Michael Landoefa037d2017-02-19 12:57:33 +020020import EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
svishnev57c5c4a2018-04-22 14:14:31 +030021import {
22 EntitlementPoolStoreFactory,
23 EntitlementPoolPostFactory
24} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js';
talig8e9c0652017-12-20 14:30:43 +020025import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
svishnev57c5c4a2018-04-22 14:14:31 +030026import {
27 LimitItemFactory,
28 LimitPostFactory
29} from 'test-utils/factories/licenseModel/LimitFactories.js';
30import { getStrValue } from 'nfvo-utils/getValue.js';
31import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js';
talig8e9c0652017-12-20 14:30:43 +020032import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
Michael Landoefa037d2017-02-19 12:57:33 +020033
svishnev57c5c4a2018-04-22 14:14:31 +030034describe('Entitlement Pools Module Tests', function() {
35 const LICENSE_MODEL_ID = '555';
36 const version = VersionFactory.build();
37 const itemPermissionAndProps = CurrentScreenFactory.build({}, { version });
38 const returnedVersionFields = {
39 baseId: version.baseId,
40 description: version.description,
41 id: version.id,
42 name: version.name,
43 status: version.status
44 };
Michael Landoefa037d2017-02-19 12:57:33 +020045
svishnev57c5c4a2018-04-22 14:14:31 +030046 it('Load Entitlement Pools List', () => {
47 const entitlementPoolsList = buildListFromFactory(
48 EntitlementPoolStoreFactory
49 );
50 deepFreeze(entitlementPoolsList);
51 const store = storeCreator();
52 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +020053
svishnev57c5c4a2018-04-22 14:14:31 +030054 const expectedStore = cloneAndSet(
55 store.getState(),
56 'licenseModel.entitlementPool.entitlementPoolsList',
57 entitlementPoolsList
58 );
AviZi280f8012017-06-09 02:39:56 +030059
svishnev57c5c4a2018-04-22 14:14:31 +030060 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
61 expect(baseUrl).toEqual(
62 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
63 version.id
64 }/entitlement-pools`
65 );
66 expect(data).toEqual(undefined);
67 expect(options).toEqual(undefined);
68 return { results: entitlementPoolsList };
69 });
Michael Landoefa037d2017-02-19 12:57:33 +020070
svishnev57c5c4a2018-04-22 14:14:31 +030071 return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(
72 store.dispatch,
73 { licenseModelId: LICENSE_MODEL_ID, version }
74 ).then(() => {
75 expect(store.getState()).toEqual(expectedStore);
76 });
77 });
Michael Landoefa037d2017-02-19 12:57:33 +020078
svishnev57c5c4a2018-04-22 14:14:31 +030079 it('Delete Entitlement Pool', () => {
80 const entitlementPoolsList = buildListFromFactory(
81 EntitlementPoolStoreFactory,
82 1
83 );
84 deepFreeze(entitlementPoolsList);
85 const store = storeCreator({
86 currentScreen: { ...itemPermissionAndProps },
87 licenseModel: {
88 entitlementPool: {
89 entitlementPoolsList
90 }
91 }
92 });
93 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +020094
svishnev57c5c4a2018-04-22 14:14:31 +030095 const expectedCurrentScreenProps = {
96 ...itemPermissionAndProps,
97 itemPermission: {
98 ...itemPermissionAndProps.itemPermission,
99 isDirty: true
100 }
101 };
Michael Landoefa037d2017-02-19 12:57:33 +0200102
svishnev57c5c4a2018-04-22 14:14:31 +0300103 let expectedStore = cloneAndSet(
104 store.getState(),
105 'licenseModel.entitlementPool.entitlementPoolsList',
106 []
107 );
108 expectedStore = cloneAndSet(
109 expectedStore,
110 'currentScreen.itemPermission',
111 expectedCurrentScreenProps.itemPermission
112 );
Michael Landoefa037d2017-02-19 12:57:33 +0200113
svishnev57c5c4a2018-04-22 14:14:31 +0300114 mockRest.addHandler('destroy', ({ data, options, baseUrl }) => {
115 expect(baseUrl).toEqual(
116 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
117 version.id
118 }/entitlement-pools/${entitlementPoolsList[0].id}`
119 );
120 expect(data).toEqual(undefined);
121 expect(options).toEqual(undefined);
122 return {
123 results: {
124 returnCode: 'OK'
125 }
126 };
127 });
Michael Landoefa037d2017-02-19 12:57:33 +0200128
svishnev57c5c4a2018-04-22 14:14:31 +0300129 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
130 expect(baseUrl).toEqual(
131 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
132 version.id
133 }`
134 );
135 expect(data).toEqual(undefined);
136 expect(options).toEqual(undefined);
137 return {
138 ...returnedVersionFields,
139 state: {
140 synchronizationState: SyncStates.UP_TO_DATE,
141 dirty: true
142 }
143 };
144 });
talig8e9c0652017-12-20 14:30:43 +0200145
svishnev57c5c4a2018-04-22 14:14:31 +0300146 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
147 expect(baseUrl).toEqual(
148 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
149 );
150 expect(data).toEqual(undefined);
151 expect(options).toEqual(undefined);
152 return {
153 ...returnedVersionFields
154 };
155 });
Michael Landoefa037d2017-02-19 12:57:33 +0200156
svishnev57c5c4a2018-04-22 14:14:31 +0300157 return EntitlementPoolsActionHelper.deleteEntitlementPool(
158 store.dispatch,
159 {
160 licenseModelId: LICENSE_MODEL_ID,
161 version,
162 entitlementPoolId: entitlementPoolsList[0].id
163 }
164 ).then(() => {
165 expect(store.getState()).toEqual(expectedStore);
166 });
167 });
Michael Landoefa037d2017-02-19 12:57:33 +0200168
svishnev57c5c4a2018-04-22 14:14:31 +0300169 it('Add Entitlement Pool', () => {
170 const store = storeCreator({
171 currentScreen: { ...itemPermissionAndProps }
172 });
173 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +0200174
svishnev57c5c4a2018-04-22 14:14:31 +0300175 const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200176
svishnev57c5c4a2018-04-22 14:14:31 +0300177 deepFreeze(EntitlementPoolPostRequest);
AviZi280f8012017-06-09 02:39:56 +0300178
svishnev57c5c4a2018-04-22 14:14:31 +0300179 const entitlementPoolIdFromResponse = 'ADDED_ID';
180 const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({
181 id: entitlementPoolIdFromResponse
182 });
183 deepFreeze(entitlementPoolAfterAdd);
AviZi280f8012017-06-09 02:39:56 +0300184
svishnev57c5c4a2018-04-22 14:14:31 +0300185 const expectedCurrentScreenProps = {
186 ...itemPermissionAndProps,
187 itemPermission: {
188 ...itemPermissionAndProps.itemPermission,
189 isDirty: true
190 }
191 };
Michael Landoefa037d2017-02-19 12:57:33 +0200192
svishnev57c5c4a2018-04-22 14:14:31 +0300193 let expectedStore = cloneAndSet(
194 store.getState(),
195 'licenseModel.entitlementPool.entitlementPoolsList',
196 [entitlementPoolAfterAdd]
197 );
198 expectedStore = cloneAndSet(
199 expectedStore,
200 'currentScreen.itemPermission',
201 expectedCurrentScreenProps.itemPermission
202 );
talig8e9c0652017-12-20 14:30:43 +0200203
svishnev57c5c4a2018-04-22 14:14:31 +0300204 mockRest.addHandler('post', ({ data, options, baseUrl }) => {
205 expect(baseUrl).toEqual(
206 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
207 version.id
208 }/entitlement-pools`
209 );
210 expect(data).toEqual(EntitlementPoolPostRequest);
211 expect(options).toEqual(undefined);
212 return {
213 returnCode: 'OK',
214 value: entitlementPoolIdFromResponse
215 };
216 });
Michael Landoefa037d2017-02-19 12:57:33 +0200217
svishnev57c5c4a2018-04-22 14:14:31 +0300218 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
219 expect(baseUrl).toEqual(
220 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
221 version.id
222 }`
223 );
224 expect(data).toEqual(undefined);
225 expect(options).toEqual(undefined);
226 return {
227 ...returnedVersionFields,
228 state: {
229 synchronizationState: SyncStates.UP_TO_DATE,
230 dirty: true
231 }
232 };
233 });
Michael Landoefa037d2017-02-19 12:57:33 +0200234
svishnev57c5c4a2018-04-22 14:14:31 +0300235 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
236 expect(baseUrl).toEqual(
237 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
238 );
239 expect(data).toEqual(undefined);
240 expect(options).toEqual(undefined);
241 return {
242 ...returnedVersionFields
243 };
244 });
talig8e9c0652017-12-20 14:30:43 +0200245
svishnev57c5c4a2018-04-22 14:14:31 +0300246 return EntitlementPoolsActionHelper.saveEntitlementPool(
247 store.dispatch,
248 {
249 licenseModelId: LICENSE_MODEL_ID,
250 version,
251 previousEntitlementPool: null,
252 entitlementPool: EntitlementPoolPostRequest
253 }
254 ).then(() => {
255 expect(store.getState()).toEqual(expectedStore);
256 });
257 });
svishnev091edfd2018-03-19 12:15:19 +0200258
svishnev57c5c4a2018-04-22 14:14:31 +0300259 it('Update Entitlement Pool', () => {
260 const entitlementPoolsList = buildListFromFactory(
261 EntitlementPoolStoreFactory,
262 1
263 );
264 deepFreeze(entitlementPoolsList);
Michael Landoefa037d2017-02-19 12:57:33 +0200265
svishnev57c5c4a2018-04-22 14:14:31 +0300266 const store = storeCreator({
267 currentScreen: { ...itemPermissionAndProps },
268 licenseModel: {
269 entitlementPool: {
270 entitlementPoolsList
271 }
272 }
273 });
AviZi280f8012017-06-09 02:39:56 +0300274
svishnev57c5c4a2018-04-22 14:14:31 +0300275 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +0200276
svishnev57c5c4a2018-04-22 14:14:31 +0300277 const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id;
278 const previousEntitlementPoolData = entitlementPoolsList[0];
279 const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({
280 name: 'ep1_UPDATED',
281 description: 'string_UPDATED',
282 id: toBeUpdatedEntitlementPoolId
283 });
284 deepFreeze(entitlementPoolUpdateData);
AviZi280f8012017-06-09 02:39:56 +0300285
svishnev57c5c4a2018-04-22 14:14:31 +0300286 const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({
287 name: 'ep1_UPDATED',
288 description: 'string_UPDATED'
289 });
290 deepFreeze(entitlementPoolPutRequest);
Michael Landoefa037d2017-02-19 12:57:33 +0200291
svishnev57c5c4a2018-04-22 14:14:31 +0300292 const expectedCurrentScreenProps = {
293 ...itemPermissionAndProps,
294 itemPermission: {
295 ...itemPermissionAndProps.itemPermission,
296 isDirty: true
297 }
298 };
Michael Landoefa037d2017-02-19 12:57:33 +0200299
svishnev57c5c4a2018-04-22 14:14:31 +0300300 let expectedStore = cloneAndSet(
301 store.getState(),
302 'licenseModel.entitlementPool.entitlementPoolsList',
303 [entitlementPoolUpdateData]
304 );
305 expectedStore = cloneAndSet(
306 expectedStore,
307 'currentScreen.itemPermission',
308 expectedCurrentScreenProps.itemPermission
309 );
Michael Landoefa037d2017-02-19 12:57:33 +0200310
svishnev57c5c4a2018-04-22 14:14:31 +0300311 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
312 expect(baseUrl).toEqual(
313 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
314 version.id
315 }/entitlement-pools/${toBeUpdatedEntitlementPoolId}`
316 );
317 expect(data).toEqual(entitlementPoolPutRequest);
318 expect(options).toEqual(undefined);
319 return { returnCode: 'OK' };
320 });
talig8e9c0652017-12-20 14:30:43 +0200321
svishnev57c5c4a2018-04-22 14:14:31 +0300322 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
323 expect(baseUrl).toEqual(
324 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
325 version.id
326 }`
327 );
328 expect(data).toEqual(undefined);
329 expect(options).toEqual(undefined);
330 return {
331 ...returnedVersionFields,
332 state: {
333 synchronizationState: SyncStates.UP_TO_DATE,
334 dirty: true
335 }
336 };
337 });
Michael Landoefa037d2017-02-19 12:57:33 +0200338
svishnev57c5c4a2018-04-22 14:14:31 +0300339 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
340 expect(baseUrl).toEqual(
341 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
342 );
343 expect(data).toEqual(undefined);
344 expect(options).toEqual(undefined);
345 return {
346 ...returnedVersionFields
347 };
348 });
Michael Landoefa037d2017-02-19 12:57:33 +0200349
svishnev57c5c4a2018-04-22 14:14:31 +0300350 return EntitlementPoolsActionHelper.saveEntitlementPool(
351 store.dispatch,
352 {
353 licenseModelId: LICENSE_MODEL_ID,
354 version,
355 previousEntitlementPool: previousEntitlementPoolData,
356 entitlementPool: entitlementPoolUpdateData
357 }
358 ).then(() => {
359 expect(store.getState()).toEqual(expectedStore);
360 });
361 });
Michael Landoefa037d2017-02-19 12:57:33 +0200362
svishnev57c5c4a2018-04-22 14:14:31 +0300363 it('Load Limits List', () => {
364 const limitsList = LimitItemFactory.buildList(3);
365 deepFreeze(limitsList);
366 const store = storeCreator();
367 deepFreeze(store.getState());
talig8e9c0652017-12-20 14:30:43 +0200368
svishnev57c5c4a2018-04-22 14:14:31 +0300369 const expectedStore = cloneAndSet(
370 store.getState(),
371 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList',
372 limitsList
373 );
374 const entitlementPool = EntitlementPoolStoreFactory.build();
375 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
376 expect(baseUrl).toEqual(
377 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
378 version.id
379 }/entitlement-pools/${entitlementPool.id}/limits`
380 );
381 expect(data).toEqual(undefined);
382 expect(options).toEqual(undefined);
383 return { results: limitsList };
384 });
Michael Landoefa037d2017-02-19 12:57:33 +0200385
svishnev57c5c4a2018-04-22 14:14:31 +0300386 return EntitlementPoolsActionHelper.fetchLimits(store.dispatch, {
387 licenseModelId: LICENSE_MODEL_ID,
388 version,
389 entitlementPool
390 }).then(() => {
391 expect(store.getState()).toEqual(expectedStore);
392 });
393 });
Avi Ziv61070c92017-07-26 17:37:57 +0300394
svishnev57c5c4a2018-04-22 14:14:31 +0300395 it('Add Limit', () => {
396 const store = storeCreator({
397 currentScreen: { ...itemPermissionAndProps }
398 });
399 deepFreeze(store.getState());
Avi Ziv61070c92017-07-26 17:37:57 +0300400
svishnev57c5c4a2018-04-22 14:14:31 +0300401 const limitToAdd = LimitPostFactory.build();
402 let limitFromBE = { ...limitToAdd };
403 limitFromBE.metric = getStrValue(limitFromBE.metric);
404 limitFromBE.unit = getStrValue(limitFromBE.unit);
talig8e9c0652017-12-20 14:30:43 +0200405
svishnev57c5c4a2018-04-22 14:14:31 +0300406 deepFreeze(limitToAdd);
407 deepFreeze(limitFromBE);
Avi Ziv61070c92017-07-26 17:37:57 +0300408
svishnev57c5c4a2018-04-22 14:14:31 +0300409 const LimitIdFromResponse = 'ADDED_ID';
410 const limitAddedItem = { ...limitToAdd, id: LimitIdFromResponse };
411 deepFreeze(limitAddedItem);
412 const entitlementPool = EntitlementPoolStoreFactory.build();
Avi Ziv61070c92017-07-26 17:37:57 +0300413
svishnev57c5c4a2018-04-22 14:14:31 +0300414 const expectedCurrentScreenProps = {
415 ...itemPermissionAndProps,
416 itemPermission: {
417 ...itemPermissionAndProps.itemPermission,
418 isDirty: true
419 }
420 };
Avi Ziv61070c92017-07-26 17:37:57 +0300421
svishnev57c5c4a2018-04-22 14:14:31 +0300422 let expectedStore = cloneAndSet(
423 store.getState(),
424 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList',
425 [limitAddedItem]
426 );
427 expectedStore = cloneAndSet(
428 expectedStore,
429 'currentScreen.itemPermission',
430 expectedCurrentScreenProps.itemPermission
431 );
talig8e9c0652017-12-20 14:30:43 +0200432
svishnev57c5c4a2018-04-22 14:14:31 +0300433 mockRest.addHandler('post', ({ data, options, baseUrl }) => {
434 expect(baseUrl).toEqual(
435 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
436 version.id
437 }/entitlement-pools/${entitlementPool.id}/limits`
438 );
439 expect(data).toEqual(limitFromBE);
440 expect(options).toEqual(undefined);
441 return {
442 returnCode: 'OK',
443 value: LimitIdFromResponse
444 };
445 });
Avi Ziv61070c92017-07-26 17:37:57 +0300446
svishnev57c5c4a2018-04-22 14:14:31 +0300447 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
448 expect(baseUrl).toEqual(
449 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
450 version.id
451 }/entitlement-pools/${entitlementPool.id}/limits`
452 );
453 expect(data).toEqual(undefined);
454 expect(options).toEqual(undefined);
455 return { results: [limitAddedItem] };
456 });
Avi Ziv61070c92017-07-26 17:37:57 +0300457
svishnev57c5c4a2018-04-22 14:14:31 +0300458 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
459 expect(baseUrl).toEqual(
460 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
461 version.id
462 }`
463 );
464 expect(data).toEqual(undefined);
465 expect(options).toEqual(undefined);
466 return {
467 ...returnedVersionFields,
468 state: {
469 synchronizationState: SyncStates.UP_TO_DATE,
470 dirty: true
471 }
472 };
473 });
Avi Ziv61070c92017-07-26 17:37:57 +0300474
svishnev57c5c4a2018-04-22 14:14:31 +0300475 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
476 expect(baseUrl).toEqual(
477 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
478 );
479 expect(data).toEqual(undefined);
480 expect(options).toEqual(undefined);
481 return {
482 ...returnedVersionFields
483 };
484 });
az2497644017c2017-08-10 17:49:40 +0300485
svishnev57c5c4a2018-04-22 14:14:31 +0300486 return EntitlementPoolsActionHelper.submitLimit(store.dispatch, {
487 licenseModelId: LICENSE_MODEL_ID,
488 version,
489 entitlementPool,
490 limit: limitToAdd
491 }).then(() => {
492 expect(store.getState()).toEqual(expectedStore);
493 });
494 });
Avi Ziv61070c92017-07-26 17:37:57 +0300495
svishnev57c5c4a2018-04-22 14:14:31 +0300496 it('Delete Limit', () => {
497 const limitsList = LimitItemFactory.buildList(1);
498 deepFreeze(limitsList);
talig8e9c0652017-12-20 14:30:43 +0200499
svishnev57c5c4a2018-04-22 14:14:31 +0300500 const store = storeCreator({
501 currentScreen: { ...itemPermissionAndProps },
502 licenseModel: {
503 entitlementPool: {
504 entitlementPoolEditor: {
505 limitsList
506 }
507 }
508 }
509 });
510 deepFreeze(store.getState());
talig8e9c0652017-12-20 14:30:43 +0200511
svishnev57c5c4a2018-04-22 14:14:31 +0300512 const entitlementPool = EntitlementPoolStoreFactory.build();
Avi Ziv61070c92017-07-26 17:37:57 +0300513
svishnev57c5c4a2018-04-22 14:14:31 +0300514 const expectedCurrentScreenProps = {
515 ...itemPermissionAndProps,
516 itemPermission: {
517 ...itemPermissionAndProps.itemPermission,
518 isDirty: true
519 }
520 };
Avi Ziv61070c92017-07-26 17:37:57 +0300521
svishnev57c5c4a2018-04-22 14:14:31 +0300522 let expectedStore = cloneAndSet(
523 store.getState(),
524 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList',
525 []
526 );
527 expectedStore = cloneAndSet(
528 expectedStore,
529 'currentScreen.itemPermission',
530 expectedCurrentScreenProps.itemPermission
531 );
Avi Ziv61070c92017-07-26 17:37:57 +0300532
svishnev57c5c4a2018-04-22 14:14:31 +0300533 mockRest.addHandler('destroy', ({ data, options, baseUrl }) => {
534 expect(baseUrl).toEqual(
535 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
536 version.id
537 }/entitlement-pools/${entitlementPool.id}/limits/${
538 limitsList[0].id
539 }`
540 );
541 expect(data).toEqual(undefined);
542 expect(options).toEqual(undefined);
543 return {
544 results: {
545 returnCode: 'OK'
546 }
547 };
548 });
talig8e9c0652017-12-20 14:30:43 +0200549
svishnev57c5c4a2018-04-22 14:14:31 +0300550 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
551 expect(baseUrl).toEqual(
552 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
553 version.id
554 }/entitlement-pools/${entitlementPool.id}/limits`
555 );
556 expect(data).toEqual(undefined);
557 expect(options).toEqual(undefined);
558 return { results: [] };
559 });
Avi Ziv61070c92017-07-26 17:37:57 +0300560
svishnev57c5c4a2018-04-22 14:14:31 +0300561 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
562 expect(baseUrl).toEqual(
563 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
564 version.id
565 }`
566 );
567 expect(data).toEqual(undefined);
568 expect(options).toEqual(undefined);
569 return {
570 ...returnedVersionFields,
571 state: {
572 synchronizationState: SyncStates.UP_TO_DATE,
573 dirty: true
574 }
575 };
576 });
Avi Ziv61070c92017-07-26 17:37:57 +0300577
svishnev57c5c4a2018-04-22 14:14:31 +0300578 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
579 expect(baseUrl).toEqual(
580 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
581 );
582 expect(data).toEqual(undefined);
583 expect(options).toEqual(undefined);
584 return {
585 ...returnedVersionFields
586 };
587 });
Avi Ziv61070c92017-07-26 17:37:57 +0300588
svishnev57c5c4a2018-04-22 14:14:31 +0300589 return EntitlementPoolsActionHelper.deleteLimit(store.dispatch, {
590 licenseModelId: LICENSE_MODEL_ID,
591 version,
592 entitlementPool,
593 limit: limitsList[0]
594 }).then(() => {
595 expect(store.getState()).toEqual(expectedStore);
596 });
597 });
Avi Ziv61070c92017-07-26 17:37:57 +0300598
svishnev57c5c4a2018-04-22 14:14:31 +0300599 it('Update Limit', () => {
600 const limitsList = LimitItemFactory.buildList(1);
601 deepFreeze(limitsList);
602 const entitlementPool = EntitlementPoolStoreFactory.build();
603 const store = storeCreator({
604 currentScreen: { ...itemPermissionAndProps },
605 licenseModel: {
606 entitlementPool: {
607 entitlementPoolEditor: {
608 limitsList
609 }
610 }
611 }
612 });
az2497644017c2017-08-10 17:49:40 +0300613
svishnev57c5c4a2018-04-22 14:14:31 +0300614 deepFreeze(store.getState());
az2497644017c2017-08-10 17:49:40 +0300615
svishnev57c5c4a2018-04-22 14:14:31 +0300616 const previousData = limitsList[0];
Avi Ziv61070c92017-07-26 17:37:57 +0300617
svishnev57c5c4a2018-04-22 14:14:31 +0300618 deepFreeze(previousData);
619 const limitId = limitsList[0].id;
az2497644017c2017-08-10 17:49:40 +0300620
svishnev57c5c4a2018-04-22 14:14:31 +0300621 let updatedLimit = { ...previousData, name: 'updatedLimit' };
az2497644017c2017-08-10 17:49:40 +0300622
svishnev57c5c4a2018-04-22 14:14:31 +0300623 const updatedLimitForPut = { ...updatedLimit, id: undefined };
624 updatedLimit.metric = { choice: updatedLimit.metric, other: '' };
625 updatedLimit.unit = { choice: updatedLimit.unit, other: '' };
626 deepFreeze(updatedLimit);
talig8e9c0652017-12-20 14:30:43 +0200627
svishnev57c5c4a2018-04-22 14:14:31 +0300628 const expectedCurrentScreenProps = {
629 ...itemPermissionAndProps,
630 itemPermission: {
631 ...itemPermissionAndProps.itemPermission,
632 isDirty: true
633 }
634 };
Avi Ziv61070c92017-07-26 17:37:57 +0300635
svishnev57c5c4a2018-04-22 14:14:31 +0300636 let expectedStore = cloneAndSet(
637 store.getState(),
638 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList',
639 [updatedLimitForPut]
640 );
641 expectedStore = cloneAndSet(
642 expectedStore,
643 'currentScreen.itemPermission',
644 expectedCurrentScreenProps.itemPermission
645 );
Avi Ziv61070c92017-07-26 17:37:57 +0300646
svishnev57c5c4a2018-04-22 14:14:31 +0300647 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
648 expect(baseUrl).toEqual(
649 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
650 version.id
651 }/entitlement-pools/${entitlementPool.id}/limits/${limitId}`
652 );
653 expect(data).toEqual(updatedLimitForPut);
654 expect(options).toEqual(undefined);
655 return { returnCode: 'OK' };
656 });
Avi Ziv61070c92017-07-26 17:37:57 +0300657
svishnev57c5c4a2018-04-22 14:14:31 +0300658 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
659 expect(baseUrl).toEqual(
660 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
661 version.id
662 }/entitlement-pools/${entitlementPool.id}/limits`
663 );
664 expect(data).toEqual(undefined);
665 expect(options).toEqual(undefined);
666 return { results: [updatedLimitForPut] };
667 });
Avi Ziv61070c92017-07-26 17:37:57 +0300668
svishnev57c5c4a2018-04-22 14:14:31 +0300669 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
670 expect(baseUrl).toEqual(
671 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
672 version.id
673 }`
674 );
675 expect(data).toEqual(undefined);
676 expect(options).toEqual(undefined);
677 return {
678 ...returnedVersionFields,
679 state: {
680 synchronizationState: SyncStates.UP_TO_DATE,
681 dirty: true
682 }
683 };
684 });
talig8e9c0652017-12-20 14:30:43 +0200685
svishnev57c5c4a2018-04-22 14:14:31 +0300686 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
687 expect(baseUrl).toEqual(
688 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
689 );
690 expect(data).toEqual(undefined);
691 expect(options).toEqual(undefined);
692 return {
693 ...returnedVersionFields
694 };
695 });
Avi Ziv61070c92017-07-26 17:37:57 +0300696
svishnev57c5c4a2018-04-22 14:14:31 +0300697 return EntitlementPoolsActionHelper.submitLimit(store.dispatch, {
698 licenseModelId: LICENSE_MODEL_ID,
699 version,
700 entitlementPool,
701 limit: updatedLimit
702 }).then(() => {
703 expect(store.getState()).toEqual(expectedStore);
704 });
705 });
Michael Landoefa037d2017-02-19 12:57:33 +0200706});