blob: 63c876cce30a526e96d34f8c84eddaf215c6af56 [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';
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';
Michael Landoefa037d2017-02-19 12:57:33 +020020import FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
svishnev57c5c4a2018-04-22 14:14:31 +030021import {
22 FeatureGroupStoreFactory,
23 FeatureGroupPostFactory,
24 FeatureGroupDispatchFactory,
25 FeatureGroupPutFactory
26} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
talig8e9c0652017-12-20 14:30:43 +020027import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
28import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
svishnev57c5c4a2018-04-22 14:14:31 +030029import { SyncStates } from 'sdc-app/common/merge/MergeEditorConstants.js';
Michael Landoefa037d2017-02-19 12:57:33 +020030
svishnev57c5c4a2018-04-22 14:14:31 +030031describe('Feature Groups Module Tests', function() {
32 const LICENSE_MODEL_ID = '555';
33 const version = VersionFactory.build();
34 const itemPermissionAndProps = CurrentScreenFactory.build({}, { version });
35 const returnedVersionFields = {
36 baseId: version.baseId,
37 description: version.description,
38 id: version.id,
39 name: version.name,
40 status: version.status
41 };
Michael Landoefa037d2017-02-19 12:57:33 +020042
svishnev57c5c4a2018-04-22 14:14:31 +030043 it('Load Feature Groups List', () => {
44 const featureGroupsList = buildListFromFactory(
45 FeatureGroupStoreFactory
46 );
47 deepFreeze(featureGroupsList);
Michael Landoefa037d2017-02-19 12:57:33 +020048
svishnev57c5c4a2018-04-22 14:14:31 +030049 const store = storeCreator();
50 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +020051
svishnev57c5c4a2018-04-22 14:14:31 +030052 const expectedStore = cloneAndSet(
53 store.getState(),
54 'licenseModel.featureGroup.featureGroupsList',
55 featureGroupsList
56 );
AviZi280f8012017-06-09 02:39:56 +030057
svishnev57c5c4a2018-04-22 14:14:31 +030058 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
59 expect(baseUrl).toEqual(
60 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
61 version.id
62 }/feature-groups`
63 );
64 expect(data).toEqual(undefined);
65 expect(options).toEqual(undefined);
66 return { results: featureGroupsList };
67 });
AviZi280f8012017-06-09 02:39:56 +030068
svishnev57c5c4a2018-04-22 14:14:31 +030069 return FeatureGroupsActionHelper.fetchFeatureGroupsList(
70 store.dispatch,
71 { licenseModelId: LICENSE_MODEL_ID, version }
72 ).then(() => {
73 expect(store.getState()).toEqual(expectedStore);
74 });
75 });
Michael Landoefa037d2017-02-19 12:57:33 +020076
svishnev57c5c4a2018-04-22 14:14:31 +030077 it('Delete Feature Group', () => {
78 const featureGroupsList = buildListFromFactory(
79 FeatureGroupStoreFactory,
80 1
81 );
82 deepFreeze(featureGroupsList);
83 const store = storeCreator({
84 currentScreen: { ...itemPermissionAndProps },
85 licenseModel: {
86 featureGroup: {
87 featureGroupsList
88 }
89 }
90 });
91 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +020092
svishnev57c5c4a2018-04-22 14:14:31 +030093 const expectedCurrentScreenProps = {
94 ...itemPermissionAndProps,
95 itemPermission: {
96 ...itemPermissionAndProps.itemPermission,
97 isDirty: true
98 }
99 };
Michael Landoefa037d2017-02-19 12:57:33 +0200100
svishnev57c5c4a2018-04-22 14:14:31 +0300101 let expectedStore = cloneAndSet(
102 store.getState(),
103 'licenseModel.featureGroup.featureGroupsList',
104 []
105 );
106 expectedStore = cloneAndSet(
107 expectedStore,
108 'currentScreen.itemPermission',
109 expectedCurrentScreenProps.itemPermission
110 );
Michael Landoefa037d2017-02-19 12:57:33 +0200111
svishnev57c5c4a2018-04-22 14:14:31 +0300112 const idToDelete = featureGroupsList[0].id;
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 }/feature-groups/${idToDelete}`
119 );
120 expect(data).toEqual(undefined);
121 expect(options).toEqual(undefined);
122 return {
123 results: {
124 returnCode: 'OK'
125 }
126 };
127 });
talig8e9c0652017-12-20 14:30:43 +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 });
Michael Landoefa037d2017-02-19 12:57:33 +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 });
AviZi280f8012017-06-09 02:39:56 +0300156
svishnev57c5c4a2018-04-22 14:14:31 +0300157 return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, {
158 licenseModelId: LICENSE_MODEL_ID,
159 version,
160 featureGroupId: idToDelete
161 }).then(() => {
162 expect(store.getState()).toEqual(expectedStore);
163 });
164 });
Michael Landoefa037d2017-02-19 12:57:33 +0200165
svishnev57c5c4a2018-04-22 14:14:31 +0300166 it('Add Feature Group', () => {
167 const store = storeCreator({
168 currentScreen: { ...itemPermissionAndProps },
169 licenseModel: {
170 featureGroup: {
171 featureGroupsList: []
172 }
173 }
174 });
175 deepFreeze(store.getState());
talig8e9c0652017-12-20 14:30:43 +0200176
svishnev57c5c4a2018-04-22 14:14:31 +0300177 const FeatureGroupPostRequest = FeatureGroupPostFactory.build({
178 addedLicenseKeyGroupsIds: [1],
179 addedEntitlementPoolsIds: [1]
180 });
181 const featureGroupToAdd = FeatureGroupDispatchFactory.build({
182 licenseKeyGroupsIds: [1],
183 entitlementPoolsIds: [1]
184 });
Michael Landoefa037d2017-02-19 12:57:33 +0200185
svishnev57c5c4a2018-04-22 14:14:31 +0300186 const featureGroupIdFromResponse = 'ADDED_ID';
187 const featureGroupAfterAdd = FeatureGroupStoreFactory.build({
188 ...featureGroupToAdd,
189 id: featureGroupIdFromResponse
190 });
Michael Landoefa037d2017-02-19 12:57:33 +0200191
svishnev57c5c4a2018-04-22 14:14:31 +0300192 const expectedCurrentScreenProps = {
193 ...itemPermissionAndProps,
194 itemPermission: {
195 ...itemPermissionAndProps.itemPermission,
196 isDirty: true
197 }
198 };
Michael Landoefa037d2017-02-19 12:57:33 +0200199
svishnev57c5c4a2018-04-22 14:14:31 +0300200 let expectedStore = cloneAndSet(
201 store.getState(),
202 'licenseModel.featureGroup.featureGroupsList',
203 [featureGroupAfterAdd]
204 );
205 expectedStore = cloneAndSet(
206 expectedStore,
207 'currentScreen.itemPermission',
208 expectedCurrentScreenProps.itemPermission
209 );
AviZi280f8012017-06-09 02:39:56 +0300210
svishnev57c5c4a2018-04-22 14:14:31 +0300211 mockRest.addHandler('post', ({ data, options, baseUrl }) => {
212 expect(baseUrl).toEqual(
213 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
214 version.id
215 }/feature-groups`
216 );
217 expect(data).toEqual(FeatureGroupPostRequest);
218 expect(options).toEqual(undefined);
219 return {
220 returnCode: 'OK',
221 value: featureGroupIdFromResponse
222 };
223 });
Michael Landoefa037d2017-02-19 12:57:33 +0200224
svishnev57c5c4a2018-04-22 14:14:31 +0300225 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
226 expect(baseUrl).toEqual(
227 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
228 version.id
229 }/entitlement-pools`
230 );
231 expect(data).toEqual(undefined);
232 expect(options).toEqual(undefined);
233 return { results: [] };
234 });
talig8e9c0652017-12-20 14:30:43 +0200235
svishnev57c5c4a2018-04-22 14:14:31 +0300236 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
237 expect(baseUrl).toEqual(
238 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
239 version.id
240 }/license-key-groups`
241 );
242 expect(data).toEqual(undefined);
243 expect(options).toEqual(undefined);
244 return { results: [] };
245 });
Michael Landoefa037d2017-02-19 12:57:33 +0200246
svishnev57c5c4a2018-04-22 14:14:31 +0300247 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
248 expect(baseUrl).toEqual(
249 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
250 version.id
251 }`
252 );
253 expect(data).toEqual(undefined);
254 expect(options).toEqual(undefined);
255 return {
256 ...returnedVersionFields,
257 state: {
258 synchronizationState: SyncStates.UP_TO_DATE,
259 dirty: true
260 }
261 };
262 });
Michael Landoefa037d2017-02-19 12:57:33 +0200263
svishnev57c5c4a2018-04-22 14:14:31 +0300264 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
265 expect(baseUrl).toEqual(
266 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
267 );
268 expect(data).toEqual(undefined);
269 expect(options).toEqual(undefined);
270 return {
271 ...returnedVersionFields
272 };
273 });
AviZi280f8012017-06-09 02:39:56 +0300274
svishnev57c5c4a2018-04-22 14:14:31 +0300275 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
276 licenseModelId: LICENSE_MODEL_ID,
277 version,
278 featureGroup: featureGroupToAdd
279 }).then(() => {
280 expect(store.getState()).toEqual(expectedStore);
281 });
282 });
AviZi280f8012017-06-09 02:39:56 +0300283
svishnev57c5c4a2018-04-22 14:14:31 +0300284 it('Update Feature Group', () => {
285 const featureGroupsList = buildListFromFactory(
286 FeatureGroupStoreFactory,
287 1,
288 {
289 licenseKeyGroupsIds: [1],
290 entitlementPoolsIds: [1]
291 }
292 );
293 deepFreeze(featureGroupsList);
talig8e9c0652017-12-20 14:30:43 +0200294
svishnev57c5c4a2018-04-22 14:14:31 +0300295 const store = storeCreator({
296 currentScreen: { ...itemPermissionAndProps },
297 licenseModel: {
298 featureGroup: {
299 featureGroupsList
300 }
301 }
302 });
303 deepFreeze(store.getState());
AviZi280f8012017-06-09 02:39:56 +0300304
svishnev57c5c4a2018-04-22 14:14:31 +0300305 const toBeUpdatedFeatureGroupId = featureGroupsList[0].id;
306 const previousFeatureGroupData = featureGroupsList[0];
Michael Landoefa037d2017-02-19 12:57:33 +0200307
svishnev57c5c4a2018-04-22 14:14:31 +0300308 const featureGroupUpdateData = FeatureGroupStoreFactory.build({
309 ...previousFeatureGroupData,
310 licenseKeyGroupsIds: [7],
311 entitlementPoolsIds: [7]
312 });
313 deepFreeze(featureGroupUpdateData);
Michael Landoefa037d2017-02-19 12:57:33 +0200314
svishnev57c5c4a2018-04-22 14:14:31 +0300315 const FeatureGroupPutFactoryRequest = FeatureGroupPutFactory.build({
316 name: featureGroupUpdateData.name,
317 description: featureGroupUpdateData.description,
318 partNumber: featureGroupUpdateData.partNumber,
319 addedLicenseKeyGroupsIds: [7],
320 addedEntitlementPoolsIds: [7],
321 removedLicenseKeyGroupsIds: [1],
322 removedEntitlementPoolsIds: [1]
323 });
324 deepFreeze(FeatureGroupPutFactoryRequest);
Michael Landoefa037d2017-02-19 12:57:33 +0200325
svishnev57c5c4a2018-04-22 14:14:31 +0300326 const expectedCurrentScreenProps = {
327 ...itemPermissionAndProps,
328 itemPermission: {
329 ...itemPermissionAndProps.itemPermission,
330 isDirty: true
331 }
332 };
AviZi280f8012017-06-09 02:39:56 +0300333
svishnev57c5c4a2018-04-22 14:14:31 +0300334 let expectedStore = cloneAndSet(
335 store.getState(),
336 'licenseModel.featureGroup.featureGroupsList',
337 [featureGroupUpdateData]
338 );
339 expectedStore = cloneAndSet(
340 expectedStore,
341 'currentScreen.itemPermission',
342 expectedCurrentScreenProps.itemPermission
343 );
Michael Landoefa037d2017-02-19 12:57:33 +0200344
svishnev57c5c4a2018-04-22 14:14:31 +0300345 mockRest.addHandler('put', ({ data, options, baseUrl }) => {
346 expect(baseUrl).toEqual(
347 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
348 version.id
349 }/feature-groups/${toBeUpdatedFeatureGroupId}`
350 );
351 expect(data).toEqual(FeatureGroupPutFactoryRequest);
352 expect(options).toEqual(undefined);
353 return { returnCode: 'OK' };
354 });
Michael Landoefa037d2017-02-19 12:57:33 +0200355
svishnev57c5c4a2018-04-22 14:14:31 +0300356 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
357 expect(baseUrl).toEqual(
358 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
359 version.id
360 }/entitlement-pools`
361 );
362 expect(data).toEqual(undefined);
363 expect(options).toEqual(undefined);
364 return { results: [] };
365 });
talig8e9c0652017-12-20 14:30:43 +0200366
svishnev57c5c4a2018-04-22 14:14:31 +0300367 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
368 expect(baseUrl).toEqual(
369 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
370 version.id
371 }/license-key-groups`
372 );
373 expect(data).toEqual(undefined);
374 expect(options).toEqual(undefined);
375 return { results: [] };
376 });
Michael Landoefa037d2017-02-19 12:57:33 +0200377
svishnev57c5c4a2018-04-22 14:14:31 +0300378 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
379 expect(baseUrl).toEqual(
380 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${
381 version.id
382 }`
383 );
384 expect(data).toEqual(undefined);
385 expect(options).toEqual(undefined);
386 return {
387 ...returnedVersionFields,
388 state: {
389 synchronizationState: SyncStates.UP_TO_DATE,
390 dirty: true
391 }
392 };
393 });
Michael Landoefa037d2017-02-19 12:57:33 +0200394
svishnev57c5c4a2018-04-22 14:14:31 +0300395 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
396 expect(baseUrl).toEqual(
397 `/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}`
398 );
399 expect(data).toEqual(undefined);
400 expect(options).toEqual(undefined);
401 return {
402 ...returnedVersionFields
403 };
404 });
Michael Landoefa037d2017-02-19 12:57:33 +0200405
svishnev57c5c4a2018-04-22 14:14:31 +0300406 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
407 licenseModelId: LICENSE_MODEL_ID,
408 version,
409 previousFeatureGroup: previousFeatureGroupData,
410 featureGroup: featureGroupUpdateData
411 }).then(() => {
412 expect(store.getState()).toEqual(expectedStore);
413 });
414 });
AviZi280f8012017-06-09 02:39:56 +0300415
svishnev57c5c4a2018-04-22 14:14:31 +0300416 it('Open Editor', () => {
417 const store = storeCreator();
418 deepFreeze(store.getState());
AviZi280f8012017-06-09 02:39:56 +0300419
svishnev57c5c4a2018-04-22 14:14:31 +0300420 const editorData = FeatureGroupStoreFactory.build();
421 deepFreeze(editorData);
422 const LICENSE_MODEL_ID = '123';
talig8e9c0652017-12-20 14:30:43 +0200423
svishnev57c5c4a2018-04-22 14:14:31 +0300424 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
425 expect(baseUrl).toEqual(
426 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
427 version.id
428 }/entitlement-pools`
429 );
430 expect(data).toEqual(undefined);
431 expect(options).toEqual(undefined);
432 return { results: [] };
433 });
AviZi280f8012017-06-09 02:39:56 +0300434
svishnev57c5c4a2018-04-22 14:14:31 +0300435 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
436 expect(baseUrl).toEqual(
437 `/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${
438 version.id
439 }/license-key-groups`
440 );
441 expect(data).toEqual(undefined);
442 expect(options).toEqual(undefined);
443 return { results: [] };
444 });
AviZi280f8012017-06-09 02:39:56 +0300445
svishnev57c5c4a2018-04-22 14:14:31 +0300446 return FeatureGroupsActionHelper.openFeatureGroupsEditor(
447 store.dispatch,
448 { featureGroup: editorData, licenseModelId: '123', version }
449 ).then(() => {
450 expect(
451 store.getState().licenseModel.featureGroup.featureGroupEditor
452 .data
453 ).toEqual(editorData);
454 });
455 });
Michael Landoefa037d2017-02-19 12:57:33 +0200456});