blob: 1326025e5d84115b9394837d607b7b1555920890 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
svishnev57c5c4a2018-04-22 14:14:31 +03002 * 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
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';
17import 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';
20import {
21 LicenseKeyGroupStoreFactory,
22 LicenseKeyGroupPostFactory
23} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js';
Michael Landoefa037d2017-02-19 12:57:33 +020024
25import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
talig8e9c0652017-12-20 14:30:43 +020026import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
27import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
svishnev57c5c4a2018-04-22 14:14:31 +030028import {
29 LimitItemFactory,
30 LimitPostFactory
31} from 'test-utils/factories/licenseModel/LimitFactories.js';
32import { getStrValue } from 'nfvo-utils/getValue.js';
33import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js';
Michael Landoefa037d2017-02-19 12:57:33 +020034
svishnev57c5c4a2018-04-22 14:14:31 +030035describe('License Key Groups Module Tests', function() {
36 const LICENSE_MODEL_ID = '555';
37 const version = VersionFactory.build();
38 const itemPermissionAndProps = CurrentScreenFactory.build({}, { version });
39 const returnedVersionFields = {
40 baseId: version.baseId,
41 description: version.description,
42 id: version.id,
43 name: version.name,
44 status: version.status
45 };
Michael Landoefa037d2017-02-19 12:57:33 +020046
svishnev57c5c4a2018-04-22 14:14:31 +030047 it('Load License Key Group', () => {
48 const licenseKeyGroupsList = buildListFromFactory(
49 LicenseKeyGroupStoreFactory
50 );
AviZi280f8012017-06-09 02:39:56 +030051
svishnev57c5c4a2018-04-22 14:14:31 +030052 deepFreeze(licenseKeyGroupsList);
53 const store = storeCreator();
54 deepFreeze(store.getState());
AviZi280f8012017-06-09 02:39:56 +030055
svishnev57c5c4a2018-04-22 14:14:31 +030056 const expectedStore = cloneAndSet(
57 store.getState(),
58 'licenseModel.licenseKeyGroup.licenseKeyGroupsList',
59 licenseKeyGroupsList
60 );
AviZi280f8012017-06-09 02:39:56 +030061
svishnev57c5c4a2018-04-22 14:14:31 +030062 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
63 expect(baseUrl).toEqual(
64 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
65 version.id
66 }/license-key-groups`
67 );
68 expect(data).toEqual(undefined);
69 expect(options).toEqual(undefined);
70 return { results: licenseKeyGroupsList };
71 });
Michael Landoefa037d2017-02-19 12:57:33 +020072
svishnev57c5c4a2018-04-22 14:14:31 +030073 return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(
74 store.dispatch,
75 { licenseModelId: LICENSE_MODEL_ID, version }
76 ).then(() => {
77 expect(store.getState()).toEqual(expectedStore);
78 });
79 });
Michael Landoefa037d2017-02-19 12:57:33 +020080
svishnev57c5c4a2018-04-22 14:14:31 +030081 it('Delete License Key Group', () => {
82 const licenseKeyGroupsList = buildListFromFactory(
83 LicenseKeyGroupStoreFactory,
84 1
85 );
Michael Landoefa037d2017-02-19 12:57:33 +020086
svishnev57c5c4a2018-04-22 14:14:31 +030087 deepFreeze(licenseKeyGroupsList);
88 const store = storeCreator({
89 currentScreen: { ...itemPermissionAndProps },
90 licenseModel: {
91 licenseKeyGroup: {
92 licenseKeyGroupsList
93 }
94 }
95 });
96 deepFreeze(store.getState());
97 const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
Michael Landoefa037d2017-02-19 12:57:33 +020098
svishnev57c5c4a2018-04-22 14:14:31 +030099 const expectedCurrentScreenProps = {
100 ...itemPermissionAndProps,
101 itemPermission: {
102 ...itemPermissionAndProps.itemPermission,
103 isDirty: true
104 }
105 };
AviZi280f8012017-06-09 02:39:56 +0300106
svishnev57c5c4a2018-04-22 14:14:31 +0300107 let expectedStore = cloneAndSet(
108 store.getState(),
109 'licenseModel.licenseKeyGroup.licenseKeyGroupsList',
110 []
111 );
112 expectedStore = cloneAndSet(
113 expectedStore,
114 'currentScreen.itemPermission',
115 expectedCurrentScreenProps.itemPermission
116 );
AviZi280f8012017-06-09 02:39:56 +0300117
svishnev57c5c4a2018-04-22 14:14:31 +0300118 mockRest.addHandler('destroy', ({ data, options, baseUrl }) => {
119 expect(baseUrl).toEqual(
120 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
121 version.id
122 }/license-key-groups/${toBeDeletedLicenseKeyGroupId}`
123 );
124 expect(data).toEqual(undefined);
125 expect(options).toEqual(undefined);
126 });
talig8e9c0652017-12-20 14:30:43 +0200127
svishnev57c5c4a2018-04-22 14:14:31 +0300128 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
129 expect(baseUrl).toEqual(
130 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
131 version.id
132 }`
133 );
134 expect(data).toEqual(undefined);
135 expect(options).toEqual(undefined);
136 return {
137 ...returnedVersionFields,
138 state: {
139 synchronizationState: SyncStates.UP_TO_DATE,
140 dirty: true
141 }
142 };
143 });
talig8e9c0652017-12-20 14:30:43 +0200144
svishnev57c5c4a2018-04-22 14:14:31 +0300145 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
146 expect(baseUrl).toEqual(
147 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
148 );
149 expect(data).toEqual(undefined);
150 expect(options).toEqual(undefined);
151 return {
152 ...returnedVersionFields
153 };
154 });
Michael Landoefa037d2017-02-19 12:57:33 +0200155
svishnev57c5c4a2018-04-22 14:14:31 +0300156 return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(
157 store.dispatch,
158 {
159 licenseKeyGroupId: toBeDeletedLicenseKeyGroupId,
160 licenseModelId: LICENSE_MODEL_ID,
161 version
162 }
163 ).then(() => {
164 expect(store.getState()).toEqual(expectedStore);
165 });
166 });
Michael Landoefa037d2017-02-19 12:57:33 +0200167
svishnev57c5c4a2018-04-22 14:14:31 +0300168 it('Add License Key Group', () => {
169 const store = storeCreator({
170 currentScreen: { ...itemPermissionAndProps }
171 });
172 deepFreeze(store.getState());
talig8e9c0652017-12-20 14:30:43 +0200173
svishnev57c5c4a2018-04-22 14:14:31 +0300174 const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build();
175 deepFreeze(LicenseKeyGroupPost);
Michael Landoefa037d2017-02-19 12:57:33 +0200176
svishnev57c5c4a2018-04-22 14:14:31 +0300177 const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build();
178 deepFreeze(LicenseKeyGroupStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200179
svishnev57c5c4a2018-04-22 14:14:31 +0300180 const expectedCurrentScreenProps = {
181 ...itemPermissionAndProps,
182 itemPermission: {
183 ...itemPermissionAndProps.itemPermission,
184 isDirty: true
185 }
186 };
Michael Landoefa037d2017-02-19 12:57:33 +0200187
svishnev57c5c4a2018-04-22 14:14:31 +0300188 let expectedStore = cloneAndSet(
189 store.getState(),
190 'licenseModel.licenseKeyGroup.licenseKeyGroupsList',
191 [LicenseKeyGroupStore]
192 );
193 expectedStore = cloneAndSet(
194 expectedStore,
195 'currentScreen.itemPermission',
196 expectedCurrentScreenProps.itemPermission
197 );
Michael Landoefa037d2017-02-19 12:57:33 +0200198
svishnev57c5c4a2018-04-22 14:14:31 +0300199 mockRest.addHandler('post', ({ options, data, baseUrl }) => {
200 expect(baseUrl).toEqual(
201 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
202 version.id
203 }/license-key-groups`
204 );
205 expect(data).toEqual(LicenseKeyGroupPost);
206 expect(options).toEqual(undefined);
207 return {
208 value: LicenseKeyGroupStore.id
209 };
210 });
Michael Landoefa037d2017-02-19 12:57:33 +0200211
svishnev57c5c4a2018-04-22 14:14:31 +0300212 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
213 expect(baseUrl).toEqual(
214 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
215 version.id
216 }`
217 );
218 expect(data).toEqual(undefined);
219 expect(options).toEqual(undefined);
220 return {
221 ...returnedVersionFields,
222 state: {
223 synchronizationState: SyncStates.UP_TO_DATE,
224 dirty: true
225 }
226 };
227 });
talig8e9c0652017-12-20 14:30:43 +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}`
232 );
233 expect(data).toEqual(undefined);
234 expect(options).toEqual(undefined);
235 return {
236 ...returnedVersionFields
237 };
238 });
Michael Landoefa037d2017-02-19 12:57:33 +0200239
svishnev57c5c4a2018-04-22 14:14:31 +0300240 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(
241 store.dispatch,
242 {
243 licenseKeyGroup: LicenseKeyGroupPost,
244 licenseModelId: LICENSE_MODEL_ID,
245 version
246 }
247 ).then(() => {
248 expect(store.getState()).toEqual(expectedStore);
249 });
250 });
Michael Landoefa037d2017-02-19 12:57:33 +0200251
svishnev57c5c4a2018-04-22 14:14:31 +0300252 it('Update License Key Group', () => {
253 const licenseKeyGroupsList = buildListFromFactory(
254 LicenseKeyGroupStoreFactory,
255 1
256 );
257 deepFreeze(licenseKeyGroupsList);
258 const store = storeCreator({
259 currentScreen: { ...itemPermissionAndProps },
260 licenseModel: {
261 licenseKeyGroup: {
262 licenseKeyGroupsList
263 }
264 }
265 });
talig8e9c0652017-12-20 14:30:43 +0200266
svishnev57c5c4a2018-04-22 14:14:31 +0300267 const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
268 const previousLicenseKeyGroupData = licenseKeyGroupsList[0];
Michael Landoefa037d2017-02-19 12:57:33 +0200269
svishnev57c5c4a2018-04-22 14:14:31 +0300270 const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({
271 name: 'lsk1_UPDATE',
272 description: 'string_UPDATE',
273 id: toBeUpdatedLicenseKeyGroupId
274 });
275 deepFreeze(licenseKeyGroupUpdatedData);
Michael Landoefa037d2017-02-19 12:57:33 +0200276
svishnev57c5c4a2018-04-22 14:14:31 +0300277 const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({
278 name: 'lsk1_UPDATE',
279 description: 'string_UPDATE'
280 });
Michael Landoefa037d2017-02-19 12:57:33 +0200281
svishnev57c5c4a2018-04-22 14:14:31 +0300282 deepFreeze(licenseKeyGroupPutRequest);
Michael Landoefa037d2017-02-19 12:57:33 +0200283
svishnev57c5c4a2018-04-22 14:14:31 +0300284 const expectedCurrentScreenProps = {
285 ...itemPermissionAndProps,
286 itemPermission: {
287 ...itemPermissionAndProps.itemPermission,
288 isDirty: true
289 }
290 };
AviZi280f8012017-06-09 02:39:56 +0300291
svishnev57c5c4a2018-04-22 14:14:31 +0300292 let expectedStore = cloneAndSet(
293 store.getState(),
294 'licenseModel.licenseKeyGroup.licenseKeyGroupsList',
295 [licenseKeyGroupUpdatedData]
296 );
297 expectedStore = cloneAndSet(
298 expectedStore,
299 'currentScreen.itemPermission',
300 expectedCurrentScreenProps.itemPermission
301 );
Michael Landoefa037d2017-02-19 12:57:33 +0200302
svishnev57c5c4a2018-04-22 14:14:31 +0300303 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
304 expect(baseUrl).toEqual(
305 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
306 version.id
307 }/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`
308 );
309 expect(data).toEqual(licenseKeyGroupPutRequest);
310 expect(options).toEqual(undefined);
311 });
talig8e9c0652017-12-20 14:30:43 +0200312
svishnev57c5c4a2018-04-22 14:14:31 +0300313 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
314 expect(baseUrl).toEqual(
315 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
316 version.id
317 }`
318 );
319 expect(data).toEqual(undefined);
320 expect(options).toEqual(undefined);
321 return {
322 ...returnedVersionFields,
323 state: {
324 synchronizationState: SyncStates.UP_TO_DATE,
325 dirty: true
326 }
327 };
328 });
Michael Landoefa037d2017-02-19 12:57:33 +0200329
svishnev57c5c4a2018-04-22 14:14:31 +0300330 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
331 expect(baseUrl).toEqual(
332 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
333 );
334 expect(data).toEqual(undefined);
335 expect(options).toEqual(undefined);
336 return {
337 ...returnedVersionFields
338 };
339 });
Michael Landoefa037d2017-02-19 12:57:33 +0200340
svishnev57c5c4a2018-04-22 14:14:31 +0300341 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(
342 store.dispatch,
343 {
344 previousLicenseKeyGroup: previousLicenseKeyGroupData,
345 licenseKeyGroup: licenseKeyGroupUpdatedData,
346 licenseModelId: LICENSE_MODEL_ID,
347 version
348 }
349 ).then(() => {
350 expect(store.getState()).toEqual(expectedStore);
351 });
352 });
talig8e9c0652017-12-20 14:30:43 +0200353
svishnev57c5c4a2018-04-22 14:14:31 +0300354 it('Load Limits List', () => {
355 const limitsList = LimitItemFactory.buildList(3);
356 deepFreeze(limitsList);
357 const store = storeCreator();
358 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +0200359
svishnev57c5c4a2018-04-22 14:14:31 +0300360 const expectedStore = cloneAndSet(
361 store.getState(),
362 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList',
363 limitsList
364 );
365 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
366 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
367 expect(baseUrl).toEqual(
368 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
369 version.id
370 }/license-key-groups/${licenseKeyGroup.id}/limits`
371 );
372 expect(data).toEqual(undefined);
373 expect(options).toEqual(undefined);
374 return { results: limitsList };
375 });
Avi Ziv61070c92017-07-26 17:37:57 +0300376
svishnev57c5c4a2018-04-22 14:14:31 +0300377 return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, {
378 licenseModelId: LICENSE_MODEL_ID,
379 version,
380 licenseKeyGroup
381 }).then(() => {
382 expect(store.getState()).toEqual(expectedStore);
383 });
384 });
Avi Ziv61070c92017-07-26 17:37:57 +0300385
svishnev57c5c4a2018-04-22 14:14:31 +0300386 it('Add Limit', () => {
387 const store = storeCreator({
388 currentScreen: { ...itemPermissionAndProps }
389 });
390 deepFreeze(store.getState());
Avi Ziv61070c92017-07-26 17:37:57 +0300391
svishnev57c5c4a2018-04-22 14:14:31 +0300392 const limitToAdd = LimitPostFactory.build();
393 let limitFromBE = { ...limitToAdd };
394 limitFromBE.metric = getStrValue(limitFromBE.metric);
395 limitFromBE.unit = getStrValue(limitFromBE.unit);
Avi Ziv61070c92017-07-26 17:37:57 +0300396
svishnev57c5c4a2018-04-22 14:14:31 +0300397 deepFreeze(limitToAdd);
398 deepFreeze(limitFromBE);
talig8e9c0652017-12-20 14:30:43 +0200399
svishnev57c5c4a2018-04-22 14:14:31 +0300400 const LimitIdFromResponse = 'ADDED_ID';
401 const limitAddedItem = { ...limitToAdd, id: LimitIdFromResponse };
402 deepFreeze(limitAddedItem);
403 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
Avi Ziv61070c92017-07-26 17:37:57 +0300404
svishnev57c5c4a2018-04-22 14:14:31 +0300405 const expectedCurrentScreenProps = {
406 ...itemPermissionAndProps,
407 itemPermission: {
408 ...itemPermissionAndProps.itemPermission,
409 isDirty: true
410 }
411 };
Avi Ziv61070c92017-07-26 17:37:57 +0300412
svishnev57c5c4a2018-04-22 14:14:31 +0300413 let expectedStore = cloneAndSet(
414 store.getState(),
415 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList',
416 [limitAddedItem]
417 );
418 expectedStore = cloneAndSet(
419 expectedStore,
420 'currentScreen.itemPermission',
421 expectedCurrentScreenProps.itemPermission
422 );
Avi Ziv61070c92017-07-26 17:37:57 +0300423
svishnev57c5c4a2018-04-22 14:14:31 +0300424 mockRest.addHandler('post', ({ data, options, baseUrl }) => {
425 expect(baseUrl).toEqual(
426 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
427 version.id
428 }/license-key-groups/${licenseKeyGroup.id}/limits`
429 );
430 expect(data).toEqual(limitFromBE);
431 expect(options).toEqual(undefined);
432 return {
433 returnCode: 'OK',
434 value: LimitIdFromResponse
435 };
436 });
talig8e9c0652017-12-20 14:30:43 +0200437
svishnev57c5c4a2018-04-22 14:14:31 +0300438 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
439 expect(baseUrl).toEqual(
440 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
441 version.id
442 }/license-key-groups/${licenseKeyGroup.id}/limits`
443 );
444 expect(data).toEqual(undefined);
445 expect(options).toEqual(undefined);
446 return { results: [limitAddedItem] };
447 });
Avi Ziv61070c92017-07-26 17:37:57 +0300448
svishnev57c5c4a2018-04-22 14:14:31 +0300449 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
450 expect(baseUrl).toEqual(
451 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
452 version.id
453 }`
454 );
455 expect(data).toEqual(undefined);
456 expect(options).toEqual(undefined);
457 return {
458 ...returnedVersionFields,
459 state: {
460 synchronizationState: SyncStates.UP_TO_DATE,
461 dirty: true
462 }
463 };
464 });
Avi Ziv61070c92017-07-26 17:37:57 +0300465
svishnev57c5c4a2018-04-22 14:14:31 +0300466 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
467 expect(baseUrl).toEqual(
468 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
469 );
470 expect(data).toEqual(undefined);
471 expect(options).toEqual(undefined);
472 return {
473 ...returnedVersionFields
474 };
475 });
az2497644017c2017-08-10 17:49:40 +0300476
svishnev57c5c4a2018-04-22 14:14:31 +0300477 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, {
478 licenseModelId: LICENSE_MODEL_ID,
479 version,
480 licenseKeyGroup,
481 limit: limitToAdd
482 }).then(() => {
483 expect(store.getState()).toEqual(expectedStore);
484 });
485 });
Avi Ziv61070c92017-07-26 17:37:57 +0300486
svishnev57c5c4a2018-04-22 14:14:31 +0300487 it('Delete Limit', () => {
488 const limitsList = LimitItemFactory.buildList(1);
489 deepFreeze(limitsList);
talig8e9c0652017-12-20 14:30:43 +0200490
svishnev57c5c4a2018-04-22 14:14:31 +0300491 const store = storeCreator({
492 currentScreen: { ...itemPermissionAndProps },
493 licenseModel: {
494 entitlementPool: {
495 entitlementPoolEditor: {
496 limitsList
497 }
498 }
499 }
500 });
501 deepFreeze(store.getState());
talig8e9c0652017-12-20 14:30:43 +0200502
svishnev57c5c4a2018-04-22 14:14:31 +0300503 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
Avi Ziv61070c92017-07-26 17:37:57 +0300504
svishnev57c5c4a2018-04-22 14:14:31 +0300505 const expectedCurrentScreenProps = {
506 ...itemPermissionAndProps,
507 itemPermission: {
508 ...itemPermissionAndProps.itemPermission,
509 isDirty: true
510 }
511 };
Avi Ziv61070c92017-07-26 17:37:57 +0300512
svishnev57c5c4a2018-04-22 14:14:31 +0300513 let expectedStore = cloneAndSet(
514 store.getState(),
515 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList',
516 []
517 );
518 expectedStore = cloneAndSet(
519 expectedStore,
520 'currentScreen.itemPermission',
521 expectedCurrentScreenProps.itemPermission
522 );
Avi Ziv61070c92017-07-26 17:37:57 +0300523
svishnev57c5c4a2018-04-22 14:14:31 +0300524 mockRest.addHandler('destroy', ({ data, options, baseUrl }) => {
525 expect(baseUrl).toEqual(
526 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
527 version.id
528 }/license-key-groups/${licenseKeyGroup.id}/limits/${
529 limitsList[0].id
530 }`
531 );
532 expect(data).toEqual(undefined);
533 expect(options).toEqual(undefined);
534 return {
535 results: {
536 returnCode: 'OK'
537 }
538 };
539 });
talig8e9c0652017-12-20 14:30:43 +0200540
svishnev57c5c4a2018-04-22 14:14:31 +0300541 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
542 expect(baseUrl).toEqual(
543 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
544 version.id
545 }/license-key-groups/${licenseKeyGroup.id}/limits`
546 );
547 expect(data).toEqual(undefined);
548 expect(options).toEqual(undefined);
549 return { results: [] };
550 });
Avi Ziv61070c92017-07-26 17:37:57 +0300551
svishnev57c5c4a2018-04-22 14:14:31 +0300552 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
553 expect(baseUrl).toEqual(
554 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
555 version.id
556 }`
557 );
558 expect(data).toEqual(undefined);
559 expect(options).toEqual(undefined);
560 return {
561 ...returnedVersionFields,
562 state: {
563 synchronizationState: SyncStates.UP_TO_DATE,
564 dirty: true
565 }
566 };
567 });
Avi Ziv61070c92017-07-26 17:37:57 +0300568
svishnev57c5c4a2018-04-22 14:14:31 +0300569 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
570 expect(baseUrl).toEqual(
571 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
572 );
573 expect(data).toEqual(undefined);
574 expect(options).toEqual(undefined);
575 return {
576 ...returnedVersionFields
577 };
578 });
Avi Ziv61070c92017-07-26 17:37:57 +0300579
svishnev57c5c4a2018-04-22 14:14:31 +0300580 return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, {
581 licenseModelId: LICENSE_MODEL_ID,
582 version,
583 licenseKeyGroup,
584 limit: limitsList[0]
585 }).then(() => {
586 expect(store.getState()).toEqual(expectedStore);
587 });
588 });
Avi Ziv61070c92017-07-26 17:37:57 +0300589
svishnev57c5c4a2018-04-22 14:14:31 +0300590 it('Update Limit', () => {
591 const limitsList = LimitItemFactory.buildList(1);
592 deepFreeze(limitsList);
593 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
594 const store = storeCreator({
595 currentScreen: { ...itemPermissionAndProps },
596 licenseModel: {
597 licenseKeyGroup: {
598 licenseKeyGroupsEditor: {
599 limitsList
600 }
601 }
602 }
603 });
az2497644017c2017-08-10 17:49:40 +0300604
svishnev57c5c4a2018-04-22 14:14:31 +0300605 deepFreeze(store.getState());
Avi Ziv61070c92017-07-26 17:37:57 +0300606
svishnev57c5c4a2018-04-22 14:14:31 +0300607 const previousData = limitsList[0];
608 deepFreeze(previousData);
609 const limitId = limitsList[0].id;
az2497644017c2017-08-10 17:49:40 +0300610
svishnev57c5c4a2018-04-22 14:14:31 +0300611 let updatedLimit = { ...previousData, name: 'updatedLimit' };
612 const updatedLimitForPut = { ...updatedLimit, id: undefined };
613 updatedLimit.metric = { choice: updatedLimit.metric, other: '' };
614 updatedLimit.unit = { choice: updatedLimit.unit, other: '' };
615 deepFreeze(updatedLimit);
talig8e9c0652017-12-20 14:30:43 +0200616
svishnev57c5c4a2018-04-22 14:14:31 +0300617 const expectedCurrentScreenProps = {
618 ...itemPermissionAndProps,
619 itemPermission: {
620 ...itemPermissionAndProps.itemPermission,
621 isDirty: true
622 }
623 };
Avi Ziv61070c92017-07-26 17:37:57 +0300624
svishnev57c5c4a2018-04-22 14:14:31 +0300625 let expectedStore = cloneAndSet(
626 store.getState(),
627 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList',
628 [updatedLimitForPut]
629 );
630 expectedStore = cloneAndSet(
631 expectedStore,
632 'currentScreen.itemPermission',
633 expectedCurrentScreenProps.itemPermission
634 );
Avi Ziv61070c92017-07-26 17:37:57 +0300635
svishnev57c5c4a2018-04-22 14:14:31 +0300636 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
637 expect(baseUrl).toEqual(
638 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
639 version.id
640 }/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}`
641 );
642 expect(data).toEqual(updatedLimitForPut);
643 expect(options).toEqual(undefined);
644 return { returnCode: 'OK' };
645 });
Avi Ziv61070c92017-07-26 17:37:57 +0300646
svishnev57c5c4a2018-04-22 14:14:31 +0300647 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
648 expect(baseUrl).toEqual(
649 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
650 version.id
651 }/license-key-groups/${licenseKeyGroup.id}/limits`
652 );
653 expect(data).toEqual(undefined);
654 expect(options).toEqual(undefined);
655 return { results: [updatedLimitForPut] };
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/items/${LICENSE_MODEL_ID}/versions/${
661 version.id
662 }`
663 );
664 expect(data).toEqual(undefined);
665 expect(options).toEqual(undefined);
666 return {
667 ...returnedVersionFields,
668 state: {
669 synchronizationState: SyncStates.UP_TO_DATE,
670 dirty: true
671 }
672 };
673 });
talig8e9c0652017-12-20 14:30:43 +0200674
svishnev57c5c4a2018-04-22 14:14:31 +0300675 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
676 expect(baseUrl).toEqual(
677 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
678 );
679 expect(data).toEqual(undefined);
680 expect(options).toEqual(undefined);
681 return {
682 ...returnedVersionFields
683 };
684 });
Avi Ziv61070c92017-07-26 17:37:57 +0300685
svishnev57c5c4a2018-04-22 14:14:31 +0300686 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, {
687 licenseModelId: LICENSE_MODEL_ID,
688 version,
689 licenseKeyGroup,
690 limit: updatedLimit
691 }).then(() => {
692 expect(store.getState()).toEqual(expectedStore);
693 });
694 });
Michael Landoefa037d2017-02-19 12:57:33 +0200695});