blob: 09a2c6f53a16de350e0cfd72b466c9b4a03abc78 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
AviZi280f8012017-06-09 02:39:56 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import deepFreeze from 'deep-freeze';
17import mockRest from 'test-utils/MockRest.js';
AviZi280f8012017-06-09 02:39:56 +030018import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
Michael Landoefa037d2017-02-19 12:57:33 +020019import {storeCreator} from 'sdc-app/AppStore.js';
AviZi280f8012017-06-09 02:39:56 +030020import {LicenseKeyGroupStoreFactory, LicenseKeyGroupPostFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js';
Michael Landoefa037d2017-02-19 12:57:33 +020021
22import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
talig8e9c0652017-12-20 14:30:43 +020023import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
24import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
Avi Ziv61070c92017-07-26 17:37:57 +030025import {LimitItemFactory, LimitPostFactory} from 'test-utils/factories/licenseModel/LimitFactories.js';
az2497644017c2017-08-10 17:49:40 +030026import {getStrValue} from 'nfvo-utils/getValue.js';
talig8e9c0652017-12-20 14:30:43 +020027import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js';
Michael Landoefa037d2017-02-19 12:57:33 +020028
29describe('License Key Groups Module Tests', function () {
30
31 const LICENSE_MODEL_ID = '555';
talig8e9c0652017-12-20 14:30:43 +020032 const version = VersionFactory.build();
33 const itemPermissionAndProps = CurrentScreenFactory.build({}, {version});
34 const returnedVersionFields = {baseId: version.baseId, description: version.description, id: version.id, name: version.name, status: version.status};
AviZi280f8012017-06-09 02:39:56 +030035
Michael Landoefa037d2017-02-19 12:57:33 +020036 it('Load License Key Group', () => {
AviZi280f8012017-06-09 02:39:56 +030037
38 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory);
39
Michael Landoefa037d2017-02-19 12:57:33 +020040 deepFreeze(licenseKeyGroupsList);
41 const store = storeCreator();
42 deepFreeze(store.getState());
43
44 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList);
45
46 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030047 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
48 expect(data).toEqual(undefined);
49 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020050 return {results: licenseKeyGroupsList};
51 });
52
AviZi280f8012017-06-09 02:39:56 +030053 return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
54 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020055 });
56 });
57
58 it('Delete License Key Group', () => {
AviZi280f8012017-06-09 02:39:56 +030059
60 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
61
Michael Landoefa037d2017-02-19 12:57:33 +020062 deepFreeze(licenseKeyGroupsList);
63 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +020064 currentScreen: {...itemPermissionAndProps},
Michael Landoefa037d2017-02-19 12:57:33 +020065 licenseModel: {
66 licenseKeyGroup: {
67 licenseKeyGroupsList
68 }
69 }
70 });
71 deepFreeze(store.getState());
AviZi280f8012017-06-09 02:39:56 +030072 const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
talig8e9c0652017-12-20 14:30:43 +020073
74 const expectedCurrentScreenProps = {
75 ...itemPermissionAndProps,
76 itemPermission: {
77 ...itemPermissionAndProps.itemPermission,
78 isDirty: true
79 }
80 };
81
82 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []);
83 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
Michael Landoefa037d2017-02-19 12:57:33 +020084
85 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030086 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeDeletedLicenseKeyGroupId}`);
87 expect(data).toEqual(undefined);
88 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020089 });
90
talig8e9c0652017-12-20 14:30:43 +020091 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
92 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
93 expect(data).toEqual(undefined);
94 expect(options).toEqual(undefined);
95 return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
96 });
97
Michael Landoefa037d2017-02-19 12:57:33 +020098 return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, {
99 licenseKeyGroupId: toBeDeletedLicenseKeyGroupId,
AviZi280f8012017-06-09 02:39:56 +0300100 licenseModelId: LICENSE_MODEL_ID,
101 version
Michael Landoefa037d2017-02-19 12:57:33 +0200102 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300103 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200104 });
105 });
106
107 it('Add License Key Group', () => {
108
talig8e9c0652017-12-20 14:30:43 +0200109 const store = storeCreator({
110 currentScreen: {...itemPermissionAndProps}
111 });
Michael Landoefa037d2017-02-19 12:57:33 +0200112 deepFreeze(store.getState());
113
AviZi280f8012017-06-09 02:39:56 +0300114 const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build();
115 deepFreeze(LicenseKeyGroupPost);
Michael Landoefa037d2017-02-19 12:57:33 +0200116
AviZi280f8012017-06-09 02:39:56 +0300117 const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build();
118 deepFreeze(LicenseKeyGroupStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200119
talig8e9c0652017-12-20 14:30:43 +0200120 const expectedCurrentScreenProps = {
121 ...itemPermissionAndProps,
122 itemPermission: {
123 ...itemPermissionAndProps.itemPermission,
124 isDirty: true
125 }
126 };
127
128 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [LicenseKeyGroupStore]);
129 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
Michael Landoefa037d2017-02-19 12:57:33 +0200130
AviZi280f8012017-06-09 02:39:56 +0300131 mockRest.addHandler('post', ({options, data, baseUrl}) => {
132 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
133 expect(data).toEqual(LicenseKeyGroupPost);
134 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200135 return {
AviZi280f8012017-06-09 02:39:56 +0300136 value: LicenseKeyGroupStore.id
Michael Landoefa037d2017-02-19 12:57:33 +0200137 };
138 });
139
talig8e9c0652017-12-20 14:30:43 +0200140 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
141 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
142 expect(data).toEqual(undefined);
143 expect(options).toEqual(undefined);
144 return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
145 });
146
Michael Landoefa037d2017-02-19 12:57:33 +0200147 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
AviZi280f8012017-06-09 02:39:56 +0300148 licenseKeyGroup: LicenseKeyGroupPost,
149 licenseModelId: LICENSE_MODEL_ID,
150 version
Michael Landoefa037d2017-02-19 12:57:33 +0200151 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300152 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200153 });
154 });
155
156 it('Update License Key Group', () => {
AviZi280f8012017-06-09 02:39:56 +0300157 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
Michael Landoefa037d2017-02-19 12:57:33 +0200158 deepFreeze(licenseKeyGroupsList);
159 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +0200160 currentScreen: {...itemPermissionAndProps},
Michael Landoefa037d2017-02-19 12:57:33 +0200161 licenseModel: {
162 licenseKeyGroup: {
163 licenseKeyGroupsList
164 }
165 }
166 });
167
168 const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
169 const previousLicenseKeyGroupData = licenseKeyGroupsList[0];
170
AviZi280f8012017-06-09 02:39:56 +0300171 const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200172 name: 'lsk1_UPDATE',
173 description: 'string_UPDATE',
AviZi280f8012017-06-09 02:39:56 +0300174 id: toBeUpdatedLicenseKeyGroupId
175 });
176 deepFreeze(licenseKeyGroupUpdatedData);
Michael Landoefa037d2017-02-19 12:57:33 +0200177
AviZi280f8012017-06-09 02:39:56 +0300178 const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200179 name: 'lsk1_UPDATE',
AviZi280f8012017-06-09 02:39:56 +0300180 description: 'string_UPDATE'
181 });
182
Michael Landoefa037d2017-02-19 12:57:33 +0200183 deepFreeze(licenseKeyGroupPutRequest);
184
talig8e9c0652017-12-20 14:30:43 +0200185 const expectedCurrentScreenProps = {
186 ...itemPermissionAndProps,
187 itemPermission: {
188 ...itemPermissionAndProps.itemPermission,
189 isDirty: true
190 }
191 };
192
193 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]);
194 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
Michael Landoefa037d2017-02-19 12:57:33 +0200195
AviZi280f8012017-06-09 02:39:56 +0300196 mockRest.addHandler('put', ({data, options, baseUrl}) => {
197 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`);
198 expect(data).toEqual(licenseKeyGroupPutRequest);
199 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200200 });
201
talig8e9c0652017-12-20 14:30:43 +0200202 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
203 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
204 expect(data).toEqual(undefined);
205 expect(options).toEqual(undefined);
206 return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
207 });
208
Michael Landoefa037d2017-02-19 12:57:33 +0200209 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
210 previousLicenseKeyGroup: previousLicenseKeyGroupData,
AviZi280f8012017-06-09 02:39:56 +0300211 licenseKeyGroup: licenseKeyGroupUpdatedData,
212 licenseModelId: LICENSE_MODEL_ID,
213 version
Michael Landoefa037d2017-02-19 12:57:33 +0200214 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300215 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200216 });
217 });
218
Avi Ziv61070c92017-07-26 17:37:57 +0300219 it('Load Limits List', () => {
220
az2497644017c2017-08-10 17:49:40 +0300221 const limitsList = LimitItemFactory.buildList(3);
Avi Ziv61070c92017-07-26 17:37:57 +0300222 deepFreeze(limitsList);
223 const store = storeCreator();
224 deepFreeze(store.getState());
225
226 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', limitsList);
227 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
228 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
229 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
230 expect(data).toEqual(undefined);
231 expect(options).toEqual(undefined);
232 return {results: limitsList};
233 });
234
235 return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, licenseKeyGroup}).then(() => {
236 expect(store.getState()).toEqual(expectedStore);
237 });
238 });
239
240 it('Add Limit', () => {
241
talig8e9c0652017-12-20 14:30:43 +0200242 const store = storeCreator({
243 currentScreen: {...itemPermissionAndProps}
244 });
Avi Ziv61070c92017-07-26 17:37:57 +0300245 deepFreeze(store.getState());
246
247 const limitToAdd = LimitPostFactory.build();
az2497644017c2017-08-10 17:49:40 +0300248 let limitFromBE = {...limitToAdd};
249 limitFromBE.metric = getStrValue(limitFromBE.metric);
250 limitFromBE.unit = getStrValue(limitFromBE.unit);
Avi Ziv61070c92017-07-26 17:37:57 +0300251
252 deepFreeze(limitToAdd);
az2497644017c2017-08-10 17:49:40 +0300253 deepFreeze(limitFromBE);
Avi Ziv61070c92017-07-26 17:37:57 +0300254
255 const LimitIdFromResponse = 'ADDED_ID';
256 const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse};
257 deepFreeze(limitAddedItem);
258 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
259
talig8e9c0652017-12-20 14:30:43 +0200260 const expectedCurrentScreenProps = {
261 ...itemPermissionAndProps,
262 itemPermission: {
263 ...itemPermissionAndProps.itemPermission,
264 isDirty: true
265 }
266 };
267
268 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [limitAddedItem]);
269 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
Avi Ziv61070c92017-07-26 17:37:57 +0300270
271 mockRest.addHandler('post', ({data, options, baseUrl}) => {
272 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
az2497644017c2017-08-10 17:49:40 +0300273 expect(data).toEqual(limitFromBE);
Avi Ziv61070c92017-07-26 17:37:57 +0300274 expect(options).toEqual(undefined);
275 return {
276 returnCode: 'OK',
277 value: LimitIdFromResponse
278 };
279 });
280
281 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
282 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
283 expect(data).toEqual(undefined);
284 expect(options).toEqual(undefined);
285 return {results: [limitAddedItem]};
286 });
287
talig8e9c0652017-12-20 14:30:43 +0200288 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
289 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
290 expect(data).toEqual(undefined);
291 expect(options).toEqual(undefined);
292 return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
293 });
294
Avi Ziv61070c92017-07-26 17:37:57 +0300295 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch,
296 {
297 licenseModelId: LICENSE_MODEL_ID,
az2497644017c2017-08-10 17:49:40 +0300298 version,
Avi Ziv61070c92017-07-26 17:37:57 +0300299 licenseKeyGroup,
300 limit: limitToAdd
301 }
302 ).then(() => {
303 expect(store.getState()).toEqual(expectedStore);
304 });
305 });
306
307 it('Delete Limit', () => {
308
az2497644017c2017-08-10 17:49:40 +0300309 const limitsList = LimitItemFactory.buildList(1);
Avi Ziv61070c92017-07-26 17:37:57 +0300310 deepFreeze(limitsList);
az2497644017c2017-08-10 17:49:40 +0300311
Avi Ziv61070c92017-07-26 17:37:57 +0300312 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +0200313 currentScreen: {...itemPermissionAndProps},
Avi Ziv61070c92017-07-26 17:37:57 +0300314 licenseModel: {
315 entitlementPool: {
316 entitlementPoolEditor: {
317 limitsList
318 }
319 }
320 }
321 });
322 deepFreeze(store.getState());
323
324 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
talig8e9c0652017-12-20 14:30:43 +0200325
326 const expectedCurrentScreenProps = {
327 ...itemPermissionAndProps,
328 itemPermission: {
329 ...itemPermissionAndProps.itemPermission,
330 isDirty: true
331 }
332 };
333
334 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', []);
335 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
Avi Ziv61070c92017-07-26 17:37:57 +0300336
337 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
338 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitsList[0].id}`);
339 expect(data).toEqual(undefined);
340 expect(options).toEqual(undefined);
341 return {
342 results: {
343 returnCode: 'OK'
344 }
345 };
346 });
347
348 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
349 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
350 expect(data).toEqual(undefined);
351 expect(options).toEqual(undefined);
352 return {results: []};
353 });
354
talig8e9c0652017-12-20 14:30:43 +0200355 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
356 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
357 expect(data).toEqual(undefined);
358 expect(options).toEqual(undefined);
359 return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
360 });
361
Avi Ziv61070c92017-07-26 17:37:57 +0300362 return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, {
363 licenseModelId: LICENSE_MODEL_ID,
364 version,
365 licenseKeyGroup,
366 limit: limitsList[0]
367 }).then(() => {
368 expect(store.getState()).toEqual(expectedStore);
369 });
370 });
371
372 it('Update Limit', () => {
373
az2497644017c2017-08-10 17:49:40 +0300374 const limitsList = LimitItemFactory.buildList(1);
Avi Ziv61070c92017-07-26 17:37:57 +0300375 deepFreeze(limitsList);
376 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
377 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +0200378 currentScreen: {...itemPermissionAndProps},
Avi Ziv61070c92017-07-26 17:37:57 +0300379 licenseModel: {
380 licenseKeyGroup: {
381 licenseKeyGroupsEditor: {
382 limitsList
383 }
384 }
385 }
386 });
387
388 deepFreeze(store.getState());
389
az2497644017c2017-08-10 17:49:40 +0300390
Avi Ziv61070c92017-07-26 17:37:57 +0300391 const previousData = limitsList[0];
392 deepFreeze(previousData);
393 const limitId = limitsList[0].id;
Avi Ziv61070c92017-07-26 17:37:57 +0300394
az2497644017c2017-08-10 17:49:40 +0300395 let updatedLimit = {...previousData, name: 'updatedLimit'};
396 const updatedLimitForPut = {...updatedLimit, id: undefined};
397 updatedLimit.metric = {choice: updatedLimit.metric, other: ''};
398 updatedLimit.unit = {choice: updatedLimit.unit, other: ''};
399 deepFreeze(updatedLimit);
400
talig8e9c0652017-12-20 14:30:43 +0200401 const expectedCurrentScreenProps = {
402 ...itemPermissionAndProps,
403 itemPermission: {
404 ...itemPermissionAndProps.itemPermission,
405 isDirty: true
406 }
407 };
408
409 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [updatedLimitForPut]);
410 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
Avi Ziv61070c92017-07-26 17:37:57 +0300411
412
413 mockRest.addHandler('put', ({data, options, baseUrl}) => {
414 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}`);
415 expect(data).toEqual(updatedLimitForPut);
416 expect(options).toEqual(undefined);
417 return {returnCode: 'OK'};
418 });
419
420 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
421 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
422 expect(data).toEqual(undefined);
423 expect(options).toEqual(undefined);
az2497644017c2017-08-10 17:49:40 +0300424 return {results: [updatedLimitForPut]};
Avi Ziv61070c92017-07-26 17:37:57 +0300425 });
426
talig8e9c0652017-12-20 14:30:43 +0200427 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
428 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
429 expect(data).toEqual(undefined);
430 expect(options).toEqual(undefined);
431 return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
432 });
433
Avi Ziv61070c92017-07-26 17:37:57 +0300434 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch,
435 {
436 licenseModelId: LICENSE_MODEL_ID,
az2497644017c2017-08-10 17:49:40 +0300437 version,
Avi Ziv61070c92017-07-26 17:37:57 +0300438 licenseKeyGroup,
439 limit: updatedLimit
440 }
441 ).then(() => {
442 expect(store.getState()).toEqual(expectedStore);
443 });
444 });
445
Michael Landoefa037d2017-02-19 12:57:33 +0200446});