blob: 6ea4e0924b039761e18e885974f69183a58d5f79 [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
svishnev8f133302018-08-06 23:08:39 +0300157 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
158 expect(baseUrl).toEqual(
159 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
160 version.id
161 }/entitlement-pools`
162 );
163 expect(data).toEqual(undefined);
164 expect(options).toEqual(undefined);
165 return { results: [] };
166 });
167
svishnev57c5c4a2018-04-22 14:14:31 +0300168 return EntitlementPoolsActionHelper.deleteEntitlementPool(
169 store.dispatch,
170 {
171 licenseModelId: LICENSE_MODEL_ID,
172 version,
173 entitlementPoolId: entitlementPoolsList[0].id
174 }
175 ).then(() => {
176 expect(store.getState()).toEqual(expectedStore);
177 });
178 });
Michael Landoefa037d2017-02-19 12:57:33 +0200179
svishnev57c5c4a2018-04-22 14:14:31 +0300180 it('Add Entitlement Pool', () => {
181 const store = storeCreator({
182 currentScreen: { ...itemPermissionAndProps }
183 });
184 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +0200185
svishnev57c5c4a2018-04-22 14:14:31 +0300186 const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200187
svishnev57c5c4a2018-04-22 14:14:31 +0300188 deepFreeze(EntitlementPoolPostRequest);
AviZi280f8012017-06-09 02:39:56 +0300189
svishnev57c5c4a2018-04-22 14:14:31 +0300190 const entitlementPoolIdFromResponse = 'ADDED_ID';
191 const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({
192 id: entitlementPoolIdFromResponse
193 });
194 deepFreeze(entitlementPoolAfterAdd);
AviZi280f8012017-06-09 02:39:56 +0300195
svishnev57c5c4a2018-04-22 14:14:31 +0300196 const expectedCurrentScreenProps = {
197 ...itemPermissionAndProps,
198 itemPermission: {
199 ...itemPermissionAndProps.itemPermission,
200 isDirty: true
201 }
202 };
Michael Landoefa037d2017-02-19 12:57:33 +0200203
svishnev57c5c4a2018-04-22 14:14:31 +0300204 let expectedStore = cloneAndSet(
205 store.getState(),
206 'licenseModel.entitlementPool.entitlementPoolsList',
207 [entitlementPoolAfterAdd]
208 );
209 expectedStore = cloneAndSet(
210 expectedStore,
211 'currentScreen.itemPermission',
212 expectedCurrentScreenProps.itemPermission
213 );
talig8e9c0652017-12-20 14:30:43 +0200214
svishnev57c5c4a2018-04-22 14:14:31 +0300215 mockRest.addHandler('post', ({ data, options, baseUrl }) => {
216 expect(baseUrl).toEqual(
217 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
218 version.id
219 }/entitlement-pools`
220 );
221 expect(data).toEqual(EntitlementPoolPostRequest);
222 expect(options).toEqual(undefined);
223 return {
224 returnCode: 'OK',
225 value: entitlementPoolIdFromResponse
226 };
227 });
Michael Landoefa037d2017-02-19 12:57:33 +0200228
svishnev57c5c4a2018-04-22 14:14:31 +0300229 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
230 expect(baseUrl).toEqual(
231 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
232 version.id
233 }`
234 );
235 expect(data).toEqual(undefined);
236 expect(options).toEqual(undefined);
237 return {
238 ...returnedVersionFields,
239 state: {
240 synchronizationState: SyncStates.UP_TO_DATE,
241 dirty: true
242 }
243 };
244 });
Michael Landoefa037d2017-02-19 12:57:33 +0200245
svishnev57c5c4a2018-04-22 14:14:31 +0300246 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
247 expect(baseUrl).toEqual(
248 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
249 );
250 expect(data).toEqual(undefined);
251 expect(options).toEqual(undefined);
252 return {
253 ...returnedVersionFields
254 };
255 });
talig8e9c0652017-12-20 14:30:43 +0200256
svishnev8f133302018-08-06 23:08:39 +0300257 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
258 expect(baseUrl).toEqual(
259 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
260 version.id
261 }/entitlement-pools`
262 );
263 expect(data).toEqual(undefined);
264 expect(options).toEqual(undefined);
265 return { results: [entitlementPoolAfterAdd] };
266 });
267
svishnev57c5c4a2018-04-22 14:14:31 +0300268 return EntitlementPoolsActionHelper.saveEntitlementPool(
269 store.dispatch,
270 {
271 licenseModelId: LICENSE_MODEL_ID,
272 version,
273 previousEntitlementPool: null,
274 entitlementPool: EntitlementPoolPostRequest
275 }
276 ).then(() => {
277 expect(store.getState()).toEqual(expectedStore);
278 });
279 });
svishnev091edfd2018-03-19 12:15:19 +0200280
svishnev57c5c4a2018-04-22 14:14:31 +0300281 it('Update Entitlement Pool', () => {
282 const entitlementPoolsList = buildListFromFactory(
283 EntitlementPoolStoreFactory,
284 1
285 );
286 deepFreeze(entitlementPoolsList);
Michael Landoefa037d2017-02-19 12:57:33 +0200287
svishnev57c5c4a2018-04-22 14:14:31 +0300288 const store = storeCreator({
289 currentScreen: { ...itemPermissionAndProps },
290 licenseModel: {
291 entitlementPool: {
292 entitlementPoolsList
293 }
294 }
295 });
AviZi280f8012017-06-09 02:39:56 +0300296
svishnev57c5c4a2018-04-22 14:14:31 +0300297 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +0200298
svishnev57c5c4a2018-04-22 14:14:31 +0300299 const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id;
300 const previousEntitlementPoolData = entitlementPoolsList[0];
301 const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({
302 name: 'ep1_UPDATED',
303 description: 'string_UPDATED',
304 id: toBeUpdatedEntitlementPoolId
305 });
306 deepFreeze(entitlementPoolUpdateData);
AviZi280f8012017-06-09 02:39:56 +0300307
svishnev57c5c4a2018-04-22 14:14:31 +0300308 const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({
309 name: 'ep1_UPDATED',
310 description: 'string_UPDATED'
311 });
312 deepFreeze(entitlementPoolPutRequest);
Michael Landoefa037d2017-02-19 12:57:33 +0200313
svishnev57c5c4a2018-04-22 14:14:31 +0300314 const expectedCurrentScreenProps = {
315 ...itemPermissionAndProps,
316 itemPermission: {
317 ...itemPermissionAndProps.itemPermission,
318 isDirty: true
319 }
320 };
Michael Landoefa037d2017-02-19 12:57:33 +0200321
svishnev57c5c4a2018-04-22 14:14:31 +0300322 let expectedStore = cloneAndSet(
323 store.getState(),
324 'licenseModel.entitlementPool.entitlementPoolsList',
325 [entitlementPoolUpdateData]
326 );
327 expectedStore = cloneAndSet(
328 expectedStore,
329 'currentScreen.itemPermission',
330 expectedCurrentScreenProps.itemPermission
331 );
Michael Landoefa037d2017-02-19 12:57:33 +0200332
svishnev57c5c4a2018-04-22 14:14:31 +0300333 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
334 expect(baseUrl).toEqual(
335 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
336 version.id
337 }/entitlement-pools/${toBeUpdatedEntitlementPoolId}`
338 );
339 expect(data).toEqual(entitlementPoolPutRequest);
340 expect(options).toEqual(undefined);
341 return { returnCode: 'OK' };
342 });
talig8e9c0652017-12-20 14:30:43 +0200343
svishnev57c5c4a2018-04-22 14:14:31 +0300344 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
345 expect(baseUrl).toEqual(
346 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
347 version.id
348 }`
349 );
350 expect(data).toEqual(undefined);
351 expect(options).toEqual(undefined);
352 return {
353 ...returnedVersionFields,
354 state: {
355 synchronizationState: SyncStates.UP_TO_DATE,
356 dirty: true
357 }
358 };
359 });
Michael Landoefa037d2017-02-19 12:57:33 +0200360
svishnev57c5c4a2018-04-22 14:14:31 +0300361 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
362 expect(baseUrl).toEqual(
363 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
364 );
365 expect(data).toEqual(undefined);
366 expect(options).toEqual(undefined);
367 return {
368 ...returnedVersionFields
369 };
370 });
Michael Landoefa037d2017-02-19 12:57:33 +0200371
svishnev8f133302018-08-06 23:08:39 +0300372 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
373 expect(baseUrl).toEqual(
374 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
375 version.id
376 }/entitlement-pools`
377 );
378 expect(data).toEqual(undefined);
379 expect(options).toEqual(undefined);
380 return { results: [entitlementPoolUpdateData] };
381 });
382
svishnev57c5c4a2018-04-22 14:14:31 +0300383 return EntitlementPoolsActionHelper.saveEntitlementPool(
384 store.dispatch,
385 {
386 licenseModelId: LICENSE_MODEL_ID,
387 version,
388 previousEntitlementPool: previousEntitlementPoolData,
389 entitlementPool: entitlementPoolUpdateData
390 }
391 ).then(() => {
392 expect(store.getState()).toEqual(expectedStore);
393 });
394 });
Michael Landoefa037d2017-02-19 12:57:33 +0200395
svishnev57c5c4a2018-04-22 14:14:31 +0300396 it('Load Limits List', () => {
397 const limitsList = LimitItemFactory.buildList(3);
398 deepFreeze(limitsList);
399 const store = storeCreator();
400 deepFreeze(store.getState());
talig8e9c0652017-12-20 14:30:43 +0200401
svishnev57c5c4a2018-04-22 14:14:31 +0300402 const expectedStore = cloneAndSet(
403 store.getState(),
404 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList',
405 limitsList
406 );
407 const entitlementPool = EntitlementPoolStoreFactory.build();
408 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
409 expect(baseUrl).toEqual(
410 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
411 version.id
412 }/entitlement-pools/${entitlementPool.id}/limits`
413 );
414 expect(data).toEqual(undefined);
415 expect(options).toEqual(undefined);
416 return { results: limitsList };
417 });
Michael Landoefa037d2017-02-19 12:57:33 +0200418
svishnev57c5c4a2018-04-22 14:14:31 +0300419 return EntitlementPoolsActionHelper.fetchLimits(store.dispatch, {
420 licenseModelId: LICENSE_MODEL_ID,
421 version,
422 entitlementPool
423 }).then(() => {
424 expect(store.getState()).toEqual(expectedStore);
425 });
426 });
Avi Ziv61070c92017-07-26 17:37:57 +0300427
svishnev57c5c4a2018-04-22 14:14:31 +0300428 it('Add Limit', () => {
429 const store = storeCreator({
430 currentScreen: { ...itemPermissionAndProps }
431 });
432 deepFreeze(store.getState());
Avi Ziv61070c92017-07-26 17:37:57 +0300433
svishnev57c5c4a2018-04-22 14:14:31 +0300434 const limitToAdd = LimitPostFactory.build();
435 let limitFromBE = { ...limitToAdd };
436 limitFromBE.metric = getStrValue(limitFromBE.metric);
437 limitFromBE.unit = getStrValue(limitFromBE.unit);
talig8e9c0652017-12-20 14:30:43 +0200438
svishnev57c5c4a2018-04-22 14:14:31 +0300439 deepFreeze(limitToAdd);
440 deepFreeze(limitFromBE);
Avi Ziv61070c92017-07-26 17:37:57 +0300441
svishnev57c5c4a2018-04-22 14:14:31 +0300442 const LimitIdFromResponse = 'ADDED_ID';
443 const limitAddedItem = { ...limitToAdd, id: LimitIdFromResponse };
444 deepFreeze(limitAddedItem);
445 const entitlementPool = EntitlementPoolStoreFactory.build();
Avi Ziv61070c92017-07-26 17:37:57 +0300446
svishnev57c5c4a2018-04-22 14:14:31 +0300447 const expectedCurrentScreenProps = {
448 ...itemPermissionAndProps,
449 itemPermission: {
450 ...itemPermissionAndProps.itemPermission,
451 isDirty: true
452 }
453 };
Avi Ziv61070c92017-07-26 17:37:57 +0300454
svishnev57c5c4a2018-04-22 14:14:31 +0300455 let expectedStore = cloneAndSet(
456 store.getState(),
457 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList',
458 [limitAddedItem]
459 );
460 expectedStore = cloneAndSet(
461 expectedStore,
462 'currentScreen.itemPermission',
463 expectedCurrentScreenProps.itemPermission
464 );
talig8e9c0652017-12-20 14:30:43 +0200465
svishnev57c5c4a2018-04-22 14:14:31 +0300466 mockRest.addHandler('post', ({ data, options, baseUrl }) => {
467 expect(baseUrl).toEqual(
468 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
469 version.id
470 }/entitlement-pools/${entitlementPool.id}/limits`
471 );
472 expect(data).toEqual(limitFromBE);
473 expect(options).toEqual(undefined);
474 return {
475 returnCode: 'OK',
476 value: LimitIdFromResponse
477 };
478 });
Avi Ziv61070c92017-07-26 17:37:57 +0300479
svishnev57c5c4a2018-04-22 14:14:31 +0300480 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
481 expect(baseUrl).toEqual(
482 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
483 version.id
484 }/entitlement-pools/${entitlementPool.id}/limits`
485 );
486 expect(data).toEqual(undefined);
487 expect(options).toEqual(undefined);
488 return { results: [limitAddedItem] };
489 });
Avi Ziv61070c92017-07-26 17:37:57 +0300490
svishnev57c5c4a2018-04-22 14:14:31 +0300491 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
492 expect(baseUrl).toEqual(
493 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
494 version.id
495 }`
496 );
497 expect(data).toEqual(undefined);
498 expect(options).toEqual(undefined);
499 return {
500 ...returnedVersionFields,
501 state: {
502 synchronizationState: SyncStates.UP_TO_DATE,
503 dirty: true
504 }
505 };
506 });
Avi Ziv61070c92017-07-26 17:37:57 +0300507
svishnev57c5c4a2018-04-22 14:14:31 +0300508 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
509 expect(baseUrl).toEqual(
510 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
511 );
512 expect(data).toEqual(undefined);
513 expect(options).toEqual(undefined);
514 return {
515 ...returnedVersionFields
516 };
517 });
az2497644017c2017-08-10 17:49:40 +0300518
svishnev57c5c4a2018-04-22 14:14:31 +0300519 return EntitlementPoolsActionHelper.submitLimit(store.dispatch, {
520 licenseModelId: LICENSE_MODEL_ID,
521 version,
522 entitlementPool,
523 limit: limitToAdd
524 }).then(() => {
525 expect(store.getState()).toEqual(expectedStore);
526 });
527 });
Avi Ziv61070c92017-07-26 17:37:57 +0300528
svishnev57c5c4a2018-04-22 14:14:31 +0300529 it('Delete Limit', () => {
530 const limitsList = LimitItemFactory.buildList(1);
531 deepFreeze(limitsList);
talig8e9c0652017-12-20 14:30:43 +0200532
svishnev57c5c4a2018-04-22 14:14:31 +0300533 const store = storeCreator({
534 currentScreen: { ...itemPermissionAndProps },
535 licenseModel: {
536 entitlementPool: {
537 entitlementPoolEditor: {
538 limitsList
539 }
540 }
541 }
542 });
543 deepFreeze(store.getState());
talig8e9c0652017-12-20 14:30:43 +0200544
svishnev57c5c4a2018-04-22 14:14:31 +0300545 const entitlementPool = EntitlementPoolStoreFactory.build();
Avi Ziv61070c92017-07-26 17:37:57 +0300546
svishnev57c5c4a2018-04-22 14:14:31 +0300547 const expectedCurrentScreenProps = {
548 ...itemPermissionAndProps,
549 itemPermission: {
550 ...itemPermissionAndProps.itemPermission,
551 isDirty: true
552 }
553 };
Avi Ziv61070c92017-07-26 17:37:57 +0300554
svishnev57c5c4a2018-04-22 14:14:31 +0300555 let expectedStore = cloneAndSet(
556 store.getState(),
557 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList',
558 []
559 );
560 expectedStore = cloneAndSet(
561 expectedStore,
562 'currentScreen.itemPermission',
563 expectedCurrentScreenProps.itemPermission
564 );
Avi Ziv61070c92017-07-26 17:37:57 +0300565
svishnev57c5c4a2018-04-22 14:14:31 +0300566 mockRest.addHandler('destroy', ({ data, options, baseUrl }) => {
567 expect(baseUrl).toEqual(
568 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
569 version.id
570 }/entitlement-pools/${entitlementPool.id}/limits/${
571 limitsList[0].id
572 }`
573 );
574 expect(data).toEqual(undefined);
575 expect(options).toEqual(undefined);
576 return {
577 results: {
578 returnCode: 'OK'
579 }
580 };
581 });
talig8e9c0652017-12-20 14:30:43 +0200582
svishnev57c5c4a2018-04-22 14:14:31 +0300583 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
584 expect(baseUrl).toEqual(
585 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
586 version.id
587 }/entitlement-pools/${entitlementPool.id}/limits`
588 );
589 expect(data).toEqual(undefined);
590 expect(options).toEqual(undefined);
591 return { results: [] };
592 });
Avi Ziv61070c92017-07-26 17:37:57 +0300593
svishnev57c5c4a2018-04-22 14:14:31 +0300594 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
595 expect(baseUrl).toEqual(
596 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
597 version.id
598 }`
599 );
600 expect(data).toEqual(undefined);
601 expect(options).toEqual(undefined);
602 return {
603 ...returnedVersionFields,
604 state: {
605 synchronizationState: SyncStates.UP_TO_DATE,
606 dirty: true
607 }
608 };
609 });
Avi Ziv61070c92017-07-26 17:37:57 +0300610
svishnev57c5c4a2018-04-22 14:14:31 +0300611 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
612 expect(baseUrl).toEqual(
613 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
614 );
615 expect(data).toEqual(undefined);
616 expect(options).toEqual(undefined);
617 return {
618 ...returnedVersionFields
619 };
620 });
Avi Ziv61070c92017-07-26 17:37:57 +0300621
svishnev57c5c4a2018-04-22 14:14:31 +0300622 return EntitlementPoolsActionHelper.deleteLimit(store.dispatch, {
623 licenseModelId: LICENSE_MODEL_ID,
624 version,
625 entitlementPool,
626 limit: limitsList[0]
627 }).then(() => {
628 expect(store.getState()).toEqual(expectedStore);
629 });
630 });
Avi Ziv61070c92017-07-26 17:37:57 +0300631
svishnev57c5c4a2018-04-22 14:14:31 +0300632 it('Update Limit', () => {
633 const limitsList = LimitItemFactory.buildList(1);
634 deepFreeze(limitsList);
635 const entitlementPool = EntitlementPoolStoreFactory.build();
636 const store = storeCreator({
637 currentScreen: { ...itemPermissionAndProps },
638 licenseModel: {
639 entitlementPool: {
640 entitlementPoolEditor: {
641 limitsList
642 }
643 }
644 }
645 });
az2497644017c2017-08-10 17:49:40 +0300646
svishnev57c5c4a2018-04-22 14:14:31 +0300647 deepFreeze(store.getState());
az2497644017c2017-08-10 17:49:40 +0300648
svishnev57c5c4a2018-04-22 14:14:31 +0300649 const previousData = limitsList[0];
Avi Ziv61070c92017-07-26 17:37:57 +0300650
svishnev57c5c4a2018-04-22 14:14:31 +0300651 deepFreeze(previousData);
652 const limitId = limitsList[0].id;
az2497644017c2017-08-10 17:49:40 +0300653
svishnev57c5c4a2018-04-22 14:14:31 +0300654 let updatedLimit = { ...previousData, name: 'updatedLimit' };
az2497644017c2017-08-10 17:49:40 +0300655
svishnev57c5c4a2018-04-22 14:14:31 +0300656 const updatedLimitForPut = { ...updatedLimit, id: undefined };
657 updatedLimit.metric = { choice: updatedLimit.metric, other: '' };
658 updatedLimit.unit = { choice: updatedLimit.unit, other: '' };
659 deepFreeze(updatedLimit);
talig8e9c0652017-12-20 14:30:43 +0200660
svishnev57c5c4a2018-04-22 14:14:31 +0300661 const expectedCurrentScreenProps = {
662 ...itemPermissionAndProps,
663 itemPermission: {
664 ...itemPermissionAndProps.itemPermission,
665 isDirty: true
666 }
667 };
Avi Ziv61070c92017-07-26 17:37:57 +0300668
svishnev57c5c4a2018-04-22 14:14:31 +0300669 let expectedStore = cloneAndSet(
670 store.getState(),
671 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList',
672 [updatedLimitForPut]
673 );
674 expectedStore = cloneAndSet(
675 expectedStore,
676 'currentScreen.itemPermission',
677 expectedCurrentScreenProps.itemPermission
678 );
Avi Ziv61070c92017-07-26 17:37:57 +0300679
svishnev57c5c4a2018-04-22 14:14:31 +0300680 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
681 expect(baseUrl).toEqual(
682 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
683 version.id
684 }/entitlement-pools/${entitlementPool.id}/limits/${limitId}`
685 );
686 expect(data).toEqual(updatedLimitForPut);
687 expect(options).toEqual(undefined);
688 return { returnCode: 'OK' };
689 });
Avi Ziv61070c92017-07-26 17:37:57 +0300690
svishnev57c5c4a2018-04-22 14:14:31 +0300691 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
692 expect(baseUrl).toEqual(
693 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
694 version.id
695 }/entitlement-pools/${entitlementPool.id}/limits`
696 );
697 expect(data).toEqual(undefined);
698 expect(options).toEqual(undefined);
699 return { results: [updatedLimitForPut] };
700 });
Avi Ziv61070c92017-07-26 17:37:57 +0300701
svishnev57c5c4a2018-04-22 14:14:31 +0300702 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
703 expect(baseUrl).toEqual(
704 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
705 version.id
706 }`
707 );
708 expect(data).toEqual(undefined);
709 expect(options).toEqual(undefined);
710 return {
711 ...returnedVersionFields,
712 state: {
713 synchronizationState: SyncStates.UP_TO_DATE,
714 dirty: true
715 }
716 };
717 });
talig8e9c0652017-12-20 14:30:43 +0200718
svishnev57c5c4a2018-04-22 14:14:31 +0300719 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
720 expect(baseUrl).toEqual(
721 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
722 );
723 expect(data).toEqual(undefined);
724 expect(options).toEqual(undefined);
725 return {
726 ...returnedVersionFields
727 };
728 });
Avi Ziv61070c92017-07-26 17:37:57 +0300729
svishnev57c5c4a2018-04-22 14:14:31 +0300730 return EntitlementPoolsActionHelper.submitLimit(store.dispatch, {
731 licenseModelId: LICENSE_MODEL_ID,
732 version,
733 entitlementPool,
734 limit: updatedLimit
735 }).then(() => {
736 expect(store.getState()).toEqual(expectedStore);
737 });
738 });
Michael Landoefa037d2017-02-19 12:57:33 +0200739});