blob: ec091a411afd969c1c8df0e3d1ae40b391d8281c [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
svishnev8f133302018-08-06 23:08:39 +0300156 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
157 expect(baseUrl).toEqual(
158 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
159 version.id
160 }/license-key-groups`
161 );
162 expect(data).toEqual(undefined);
163 expect(options).toEqual(undefined);
164 return { results: [] };
165 });
166
svishnev57c5c4a2018-04-22 14:14:31 +0300167 return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(
168 store.dispatch,
169 {
170 licenseKeyGroupId: toBeDeletedLicenseKeyGroupId,
171 licenseModelId: LICENSE_MODEL_ID,
172 version
173 }
174 ).then(() => {
175 expect(store.getState()).toEqual(expectedStore);
176 });
177 });
Michael Landoefa037d2017-02-19 12:57:33 +0200178
svishnev57c5c4a2018-04-22 14:14:31 +0300179 it('Add License Key Group', () => {
180 const store = storeCreator({
181 currentScreen: { ...itemPermissionAndProps }
182 });
183 deepFreeze(store.getState());
talig8e9c0652017-12-20 14:30:43 +0200184
svishnev57c5c4a2018-04-22 14:14:31 +0300185 const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build();
186 deepFreeze(LicenseKeyGroupPost);
Michael Landoefa037d2017-02-19 12:57:33 +0200187
svishnev57c5c4a2018-04-22 14:14:31 +0300188 const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build();
189 deepFreeze(LicenseKeyGroupStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200190
svishnev57c5c4a2018-04-22 14:14:31 +0300191 const expectedCurrentScreenProps = {
192 ...itemPermissionAndProps,
193 itemPermission: {
194 ...itemPermissionAndProps.itemPermission,
195 isDirty: true
196 }
197 };
Michael Landoefa037d2017-02-19 12:57:33 +0200198
svishnev57c5c4a2018-04-22 14:14:31 +0300199 let expectedStore = cloneAndSet(
200 store.getState(),
201 'licenseModel.licenseKeyGroup.licenseKeyGroupsList',
202 [LicenseKeyGroupStore]
203 );
204 expectedStore = cloneAndSet(
205 expectedStore,
206 'currentScreen.itemPermission',
207 expectedCurrentScreenProps.itemPermission
208 );
Michael Landoefa037d2017-02-19 12:57:33 +0200209
svishnev57c5c4a2018-04-22 14:14:31 +0300210 mockRest.addHandler('post', ({ options, data, baseUrl }) => {
211 expect(baseUrl).toEqual(
212 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
213 version.id
214 }/license-key-groups`
215 );
216 expect(data).toEqual(LicenseKeyGroupPost);
217 expect(options).toEqual(undefined);
218 return {
219 value: LicenseKeyGroupStore.id
220 };
221 });
Michael Landoefa037d2017-02-19 12:57:33 +0200222
svishnev57c5c4a2018-04-22 14:14:31 +0300223 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
224 expect(baseUrl).toEqual(
225 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
226 version.id
227 }`
228 );
229 expect(data).toEqual(undefined);
230 expect(options).toEqual(undefined);
231 return {
232 ...returnedVersionFields,
233 state: {
234 synchronizationState: SyncStates.UP_TO_DATE,
235 dirty: true
236 }
237 };
238 });
talig8e9c0652017-12-20 14:30:43 +0200239
svishnev57c5c4a2018-04-22 14:14:31 +0300240 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
241 expect(baseUrl).toEqual(
242 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
243 );
244 expect(data).toEqual(undefined);
245 expect(options).toEqual(undefined);
246 return {
247 ...returnedVersionFields
248 };
249 });
Michael Landoefa037d2017-02-19 12:57:33 +0200250
svishnev8f133302018-08-06 23:08:39 +0300251 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
252 expect(baseUrl).toEqual(
253 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
254 version.id
255 }/license-key-groups`
256 );
257 expect(data).toEqual(undefined);
258 expect(options).toEqual(undefined);
259 return { results: [LicenseKeyGroupStore] };
260 });
261
svishnev57c5c4a2018-04-22 14:14:31 +0300262 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(
263 store.dispatch,
264 {
265 licenseKeyGroup: LicenseKeyGroupPost,
266 licenseModelId: LICENSE_MODEL_ID,
267 version
268 }
269 ).then(() => {
270 expect(store.getState()).toEqual(expectedStore);
271 });
272 });
Michael Landoefa037d2017-02-19 12:57:33 +0200273
svishnev57c5c4a2018-04-22 14:14:31 +0300274 it('Update License Key Group', () => {
275 const licenseKeyGroupsList = buildListFromFactory(
276 LicenseKeyGroupStoreFactory,
277 1
278 );
279 deepFreeze(licenseKeyGroupsList);
280 const store = storeCreator({
281 currentScreen: { ...itemPermissionAndProps },
282 licenseModel: {
283 licenseKeyGroup: {
284 licenseKeyGroupsList
285 }
286 }
287 });
talig8e9c0652017-12-20 14:30:43 +0200288
svishnev57c5c4a2018-04-22 14:14:31 +0300289 const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
290 const previousLicenseKeyGroupData = licenseKeyGroupsList[0];
Michael Landoefa037d2017-02-19 12:57:33 +0200291
svishnev57c5c4a2018-04-22 14:14:31 +0300292 const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({
293 name: 'lsk1_UPDATE',
294 description: 'string_UPDATE',
295 id: toBeUpdatedLicenseKeyGroupId
296 });
297 deepFreeze(licenseKeyGroupUpdatedData);
Michael Landoefa037d2017-02-19 12:57:33 +0200298
svishnev57c5c4a2018-04-22 14:14:31 +0300299 const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({
300 name: 'lsk1_UPDATE',
301 description: 'string_UPDATE'
302 });
Michael Landoefa037d2017-02-19 12:57:33 +0200303
svishnev57c5c4a2018-04-22 14:14:31 +0300304 deepFreeze(licenseKeyGroupPutRequest);
Michael Landoefa037d2017-02-19 12:57:33 +0200305
svishnev57c5c4a2018-04-22 14:14:31 +0300306 const expectedCurrentScreenProps = {
307 ...itemPermissionAndProps,
308 itemPermission: {
309 ...itemPermissionAndProps.itemPermission,
310 isDirty: true
311 }
312 };
AviZi280f8012017-06-09 02:39:56 +0300313
svishnev57c5c4a2018-04-22 14:14:31 +0300314 let expectedStore = cloneAndSet(
315 store.getState(),
316 'licenseModel.licenseKeyGroup.licenseKeyGroupsList',
317 [licenseKeyGroupUpdatedData]
318 );
319 expectedStore = cloneAndSet(
320 expectedStore,
321 'currentScreen.itemPermission',
322 expectedCurrentScreenProps.itemPermission
323 );
Michael Landoefa037d2017-02-19 12:57:33 +0200324
svishnev57c5c4a2018-04-22 14:14:31 +0300325 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
326 expect(baseUrl).toEqual(
327 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
328 version.id
329 }/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`
330 );
331 expect(data).toEqual(licenseKeyGroupPutRequest);
332 expect(options).toEqual(undefined);
333 });
talig8e9c0652017-12-20 14:30:43 +0200334
svishnev57c5c4a2018-04-22 14:14:31 +0300335 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
336 expect(baseUrl).toEqual(
337 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
338 version.id
339 }`
340 );
341 expect(data).toEqual(undefined);
342 expect(options).toEqual(undefined);
343 return {
344 ...returnedVersionFields,
345 state: {
346 synchronizationState: SyncStates.UP_TO_DATE,
347 dirty: true
348 }
349 };
350 });
Michael Landoefa037d2017-02-19 12:57:33 +0200351
svishnev57c5c4a2018-04-22 14:14:31 +0300352 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
353 expect(baseUrl).toEqual(
354 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
355 );
356 expect(data).toEqual(undefined);
357 expect(options).toEqual(undefined);
358 return {
359 ...returnedVersionFields
360 };
361 });
Michael Landoefa037d2017-02-19 12:57:33 +0200362
svishnev8f133302018-08-06 23:08:39 +0300363 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
364 expect(baseUrl).toEqual(
365 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
366 version.id
367 }/license-key-groups`
368 );
369 expect(data).toEqual(undefined);
370 expect(options).toEqual(undefined);
371 return { results: [licenseKeyGroupUpdatedData] };
372 });
373
svishnev57c5c4a2018-04-22 14:14:31 +0300374 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(
375 store.dispatch,
376 {
377 previousLicenseKeyGroup: previousLicenseKeyGroupData,
378 licenseKeyGroup: licenseKeyGroupUpdatedData,
379 licenseModelId: LICENSE_MODEL_ID,
380 version
381 }
382 ).then(() => {
383 expect(store.getState()).toEqual(expectedStore);
384 });
385 });
talig8e9c0652017-12-20 14:30:43 +0200386
svishnev57c5c4a2018-04-22 14:14:31 +0300387 it('Load Limits List', () => {
388 const limitsList = LimitItemFactory.buildList(3);
389 deepFreeze(limitsList);
390 const store = storeCreator();
391 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +0200392
svishnev57c5c4a2018-04-22 14:14:31 +0300393 const expectedStore = cloneAndSet(
394 store.getState(),
395 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList',
396 limitsList
397 );
398 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
399 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
400 expect(baseUrl).toEqual(
401 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
402 version.id
403 }/license-key-groups/${licenseKeyGroup.id}/limits`
404 );
405 expect(data).toEqual(undefined);
406 expect(options).toEqual(undefined);
407 return { results: limitsList };
408 });
Avi Ziv61070c92017-07-26 17:37:57 +0300409
svishnev57c5c4a2018-04-22 14:14:31 +0300410 return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, {
411 licenseModelId: LICENSE_MODEL_ID,
412 version,
413 licenseKeyGroup
414 }).then(() => {
415 expect(store.getState()).toEqual(expectedStore);
416 });
417 });
Avi Ziv61070c92017-07-26 17:37:57 +0300418
svishnev57c5c4a2018-04-22 14:14:31 +0300419 it('Add Limit', () => {
420 const store = storeCreator({
421 currentScreen: { ...itemPermissionAndProps }
422 });
423 deepFreeze(store.getState());
Avi Ziv61070c92017-07-26 17:37:57 +0300424
svishnev57c5c4a2018-04-22 14:14:31 +0300425 const limitToAdd = LimitPostFactory.build();
426 let limitFromBE = { ...limitToAdd };
427 limitFromBE.metric = getStrValue(limitFromBE.metric);
428 limitFromBE.unit = getStrValue(limitFromBE.unit);
Avi Ziv61070c92017-07-26 17:37:57 +0300429
svishnev57c5c4a2018-04-22 14:14:31 +0300430 deepFreeze(limitToAdd);
431 deepFreeze(limitFromBE);
talig8e9c0652017-12-20 14:30:43 +0200432
svishnev57c5c4a2018-04-22 14:14:31 +0300433 const LimitIdFromResponse = 'ADDED_ID';
434 const limitAddedItem = { ...limitToAdd, id: LimitIdFromResponse };
435 deepFreeze(limitAddedItem);
436 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
Avi Ziv61070c92017-07-26 17:37:57 +0300437
svishnev57c5c4a2018-04-22 14:14:31 +0300438 const expectedCurrentScreenProps = {
439 ...itemPermissionAndProps,
440 itemPermission: {
441 ...itemPermissionAndProps.itemPermission,
442 isDirty: true
443 }
444 };
Avi Ziv61070c92017-07-26 17:37:57 +0300445
svishnev57c5c4a2018-04-22 14:14:31 +0300446 let expectedStore = cloneAndSet(
447 store.getState(),
448 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList',
449 [limitAddedItem]
450 );
451 expectedStore = cloneAndSet(
452 expectedStore,
453 'currentScreen.itemPermission',
454 expectedCurrentScreenProps.itemPermission
455 );
Avi Ziv61070c92017-07-26 17:37:57 +0300456
svishnev57c5c4a2018-04-22 14:14:31 +0300457 mockRest.addHandler('post', ({ data, options, baseUrl }) => {
458 expect(baseUrl).toEqual(
459 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
460 version.id
461 }/license-key-groups/${licenseKeyGroup.id}/limits`
462 );
463 expect(data).toEqual(limitFromBE);
464 expect(options).toEqual(undefined);
465 return {
466 returnCode: 'OK',
467 value: LimitIdFromResponse
468 };
469 });
talig8e9c0652017-12-20 14:30:43 +0200470
svishnev57c5c4a2018-04-22 14:14:31 +0300471 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
472 expect(baseUrl).toEqual(
473 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
474 version.id
475 }/license-key-groups/${licenseKeyGroup.id}/limits`
476 );
477 expect(data).toEqual(undefined);
478 expect(options).toEqual(undefined);
479 return { results: [limitAddedItem] };
480 });
Avi Ziv61070c92017-07-26 17:37:57 +0300481
svishnev57c5c4a2018-04-22 14:14:31 +0300482 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
483 expect(baseUrl).toEqual(
484 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
485 version.id
486 }`
487 );
488 expect(data).toEqual(undefined);
489 expect(options).toEqual(undefined);
490 return {
491 ...returnedVersionFields,
492 state: {
493 synchronizationState: SyncStates.UP_TO_DATE,
494 dirty: true
495 }
496 };
497 });
Avi Ziv61070c92017-07-26 17:37:57 +0300498
svishnev57c5c4a2018-04-22 14:14:31 +0300499 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
500 expect(baseUrl).toEqual(
501 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
502 );
503 expect(data).toEqual(undefined);
504 expect(options).toEqual(undefined);
505 return {
506 ...returnedVersionFields
507 };
508 });
az2497644017c2017-08-10 17:49:40 +0300509
svishnev57c5c4a2018-04-22 14:14:31 +0300510 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, {
511 licenseModelId: LICENSE_MODEL_ID,
512 version,
513 licenseKeyGroup,
514 limit: limitToAdd
515 }).then(() => {
516 expect(store.getState()).toEqual(expectedStore);
517 });
518 });
Avi Ziv61070c92017-07-26 17:37:57 +0300519
svishnev57c5c4a2018-04-22 14:14:31 +0300520 it('Delete Limit', () => {
521 const limitsList = LimitItemFactory.buildList(1);
522 deepFreeze(limitsList);
talig8e9c0652017-12-20 14:30:43 +0200523
svishnev57c5c4a2018-04-22 14:14:31 +0300524 const store = storeCreator({
525 currentScreen: { ...itemPermissionAndProps },
526 licenseModel: {
527 entitlementPool: {
528 entitlementPoolEditor: {
529 limitsList
530 }
531 }
532 }
533 });
534 deepFreeze(store.getState());
talig8e9c0652017-12-20 14:30:43 +0200535
svishnev57c5c4a2018-04-22 14:14:31 +0300536 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
Avi Ziv61070c92017-07-26 17:37:57 +0300537
svishnev57c5c4a2018-04-22 14:14:31 +0300538 const expectedCurrentScreenProps = {
539 ...itemPermissionAndProps,
540 itemPermission: {
541 ...itemPermissionAndProps.itemPermission,
542 isDirty: true
543 }
544 };
Avi Ziv61070c92017-07-26 17:37:57 +0300545
svishnev57c5c4a2018-04-22 14:14:31 +0300546 let expectedStore = cloneAndSet(
547 store.getState(),
548 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList',
549 []
550 );
551 expectedStore = cloneAndSet(
552 expectedStore,
553 'currentScreen.itemPermission',
554 expectedCurrentScreenProps.itemPermission
555 );
Avi Ziv61070c92017-07-26 17:37:57 +0300556
svishnev57c5c4a2018-04-22 14:14:31 +0300557 mockRest.addHandler('destroy', ({ data, options, baseUrl }) => {
558 expect(baseUrl).toEqual(
559 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
560 version.id
561 }/license-key-groups/${licenseKeyGroup.id}/limits/${
562 limitsList[0].id
563 }`
564 );
565 expect(data).toEqual(undefined);
566 expect(options).toEqual(undefined);
567 return {
568 results: {
569 returnCode: 'OK'
570 }
571 };
572 });
talig8e9c0652017-12-20 14:30:43 +0200573
svishnev57c5c4a2018-04-22 14:14:31 +0300574 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
575 expect(baseUrl).toEqual(
576 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
577 version.id
578 }/license-key-groups/${licenseKeyGroup.id}/limits`
579 );
580 expect(data).toEqual(undefined);
581 expect(options).toEqual(undefined);
582 return { results: [] };
583 });
Avi Ziv61070c92017-07-26 17:37:57 +0300584
svishnev57c5c4a2018-04-22 14:14:31 +0300585 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
586 expect(baseUrl).toEqual(
587 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
588 version.id
589 }`
590 );
591 expect(data).toEqual(undefined);
592 expect(options).toEqual(undefined);
593 return {
594 ...returnedVersionFields,
595 state: {
596 synchronizationState: SyncStates.UP_TO_DATE,
597 dirty: true
598 }
599 };
600 });
Avi Ziv61070c92017-07-26 17:37:57 +0300601
svishnev57c5c4a2018-04-22 14:14:31 +0300602 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
603 expect(baseUrl).toEqual(
604 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
605 );
606 expect(data).toEqual(undefined);
607 expect(options).toEqual(undefined);
608 return {
609 ...returnedVersionFields
610 };
611 });
Avi Ziv61070c92017-07-26 17:37:57 +0300612
svishnev57c5c4a2018-04-22 14:14:31 +0300613 return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, {
614 licenseModelId: LICENSE_MODEL_ID,
615 version,
616 licenseKeyGroup,
617 limit: limitsList[0]
618 }).then(() => {
619 expect(store.getState()).toEqual(expectedStore);
620 });
621 });
Avi Ziv61070c92017-07-26 17:37:57 +0300622
svishnev57c5c4a2018-04-22 14:14:31 +0300623 it('Update Limit', () => {
624 const limitsList = LimitItemFactory.buildList(1);
625 deepFreeze(limitsList);
626 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
627 const store = storeCreator({
628 currentScreen: { ...itemPermissionAndProps },
629 licenseModel: {
630 licenseKeyGroup: {
631 licenseKeyGroupsEditor: {
632 limitsList
633 }
634 }
635 }
636 });
az2497644017c2017-08-10 17:49:40 +0300637
svishnev57c5c4a2018-04-22 14:14:31 +0300638 deepFreeze(store.getState());
Avi Ziv61070c92017-07-26 17:37:57 +0300639
svishnev57c5c4a2018-04-22 14:14:31 +0300640 const previousData = limitsList[0];
641 deepFreeze(previousData);
642 const limitId = limitsList[0].id;
az2497644017c2017-08-10 17:49:40 +0300643
svishnev57c5c4a2018-04-22 14:14:31 +0300644 let updatedLimit = { ...previousData, name: 'updatedLimit' };
645 const updatedLimitForPut = { ...updatedLimit, id: undefined };
646 updatedLimit.metric = { choice: updatedLimit.metric, other: '' };
647 updatedLimit.unit = { choice: updatedLimit.unit, other: '' };
648 deepFreeze(updatedLimit);
talig8e9c0652017-12-20 14:30:43 +0200649
svishnev57c5c4a2018-04-22 14:14:31 +0300650 const expectedCurrentScreenProps = {
651 ...itemPermissionAndProps,
652 itemPermission: {
653 ...itemPermissionAndProps.itemPermission,
654 isDirty: true
655 }
656 };
Avi Ziv61070c92017-07-26 17:37:57 +0300657
svishnev57c5c4a2018-04-22 14:14:31 +0300658 let expectedStore = cloneAndSet(
659 store.getState(),
660 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList',
661 [updatedLimitForPut]
662 );
663 expectedStore = cloneAndSet(
664 expectedStore,
665 'currentScreen.itemPermission',
666 expectedCurrentScreenProps.itemPermission
667 );
Avi Ziv61070c92017-07-26 17:37:57 +0300668
svishnev57c5c4a2018-04-22 14:14:31 +0300669 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
670 expect(baseUrl).toEqual(
671 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
672 version.id
673 }/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}`
674 );
675 expect(data).toEqual(updatedLimitForPut);
676 expect(options).toEqual(undefined);
677 return { returnCode: 'OK' };
678 });
Avi Ziv61070c92017-07-26 17:37:57 +0300679
svishnev57c5c4a2018-04-22 14:14:31 +0300680 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
681 expect(baseUrl).toEqual(
682 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
683 version.id
684 }/license-key-groups/${licenseKeyGroup.id}/limits`
685 );
686 expect(data).toEqual(undefined);
687 expect(options).toEqual(undefined);
688 return { results: [updatedLimitForPut] };
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/items/${LICENSE_MODEL_ID}/versions/${
694 version.id
695 }`
696 );
697 expect(data).toEqual(undefined);
698 expect(options).toEqual(undefined);
699 return {
700 ...returnedVersionFields,
701 state: {
702 synchronizationState: SyncStates.UP_TO_DATE,
703 dirty: true
704 }
705 };
706 });
talig8e9c0652017-12-20 14:30:43 +0200707
svishnev57c5c4a2018-04-22 14:14:31 +0300708 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
709 expect(baseUrl).toEqual(
710 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
711 );
712 expect(data).toEqual(undefined);
713 expect(options).toEqual(undefined);
714 return {
715 ...returnedVersionFields
716 };
717 });
Avi Ziv61070c92017-07-26 17:37:57 +0300718
svishnev57c5c4a2018-04-22 14:14:31 +0300719 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, {
720 licenseModelId: LICENSE_MODEL_ID,
721 version,
722 licenseKeyGroup,
723 limit: updatedLimit
724 }).then(() => {
725 expect(store.getState()).toEqual(expectedStore);
726 });
727 });
Michael Landoefa037d2017-02-19 12:57:33 +0200728});