2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * 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
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * 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.
16 import deepFreeze from 'deep-freeze';
17 import mockRest from 'test-utils/MockRest.js';
18 import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
19 import {storeCreator} from 'sdc-app/AppStore.js';
20 import {LicenseKeyGroupStoreFactory, LicenseKeyGroupPostFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js';
22 import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
23 import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
24 import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
25 import {LimitItemFactory, LimitPostFactory} from 'test-utils/factories/licenseModel/LimitFactories.js';
26 import {getStrValue} from 'nfvo-utils/getValue.js';
27 import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js';
29 describe('License Key Groups Module Tests', function () {
31 const LICENSE_MODEL_ID = '555';
32 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};
36 it('Load License Key Group', () => {
38 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory);
40 deepFreeze(licenseKeyGroupsList);
41 const store = storeCreator();
42 deepFreeze(store.getState());
44 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList);
46 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
47 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);
50 return {results: licenseKeyGroupsList};
53 return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
54 expect(store.getState()).toEqual(expectedStore);
58 it('Delete License Key Group', () => {
60 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
62 deepFreeze(licenseKeyGroupsList);
63 const store = storeCreator({
64 currentScreen: {...itemPermissionAndProps},
71 deepFreeze(store.getState());
72 const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
74 const expectedCurrentScreenProps = {
75 ...itemPermissionAndProps,
77 ...itemPermissionAndProps.itemPermission,
82 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []);
83 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
85 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
86 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);
91 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}};
98 return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, {
99 licenseKeyGroupId: toBeDeletedLicenseKeyGroupId,
100 licenseModelId: LICENSE_MODEL_ID,
103 expect(store.getState()).toEqual(expectedStore);
107 it('Add License Key Group', () => {
109 const store = storeCreator({
110 currentScreen: {...itemPermissionAndProps}
112 deepFreeze(store.getState());
114 const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build();
115 deepFreeze(LicenseKeyGroupPost);
117 const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build();
118 deepFreeze(LicenseKeyGroupStore);
120 const expectedCurrentScreenProps = {
121 ...itemPermissionAndProps,
123 ...itemPermissionAndProps.itemPermission,
128 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [LicenseKeyGroupStore]);
129 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
131 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);
136 value: LicenseKeyGroupStore.id
140 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}};
147 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
148 licenseKeyGroup: LicenseKeyGroupPost,
149 licenseModelId: LICENSE_MODEL_ID,
152 expect(store.getState()).toEqual(expectedStore);
156 it('Update License Key Group', () => {
157 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
158 deepFreeze(licenseKeyGroupsList);
159 const store = storeCreator({
160 currentScreen: {...itemPermissionAndProps},
168 const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
169 const previousLicenseKeyGroupData = licenseKeyGroupsList[0];
171 const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({
173 description: 'string_UPDATE',
174 id: toBeUpdatedLicenseKeyGroupId
176 deepFreeze(licenseKeyGroupUpdatedData);
178 const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({
180 description: 'string_UPDATE'
183 deepFreeze(licenseKeyGroupPutRequest);
185 const expectedCurrentScreenProps = {
186 ...itemPermissionAndProps,
188 ...itemPermissionAndProps.itemPermission,
193 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]);
194 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
196 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);
202 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}};
209 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
210 previousLicenseKeyGroup: previousLicenseKeyGroupData,
211 licenseKeyGroup: licenseKeyGroupUpdatedData,
212 licenseModelId: LICENSE_MODEL_ID,
215 expect(store.getState()).toEqual(expectedStore);
219 it('Load Limits List', () => {
221 const limitsList = LimitItemFactory.buildList(3);
222 deepFreeze(limitsList);
223 const store = storeCreator();
224 deepFreeze(store.getState());
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};
235 return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, licenseKeyGroup}).then(() => {
236 expect(store.getState()).toEqual(expectedStore);
240 it('Add Limit', () => {
242 const store = storeCreator({
243 currentScreen: {...itemPermissionAndProps}
245 deepFreeze(store.getState());
247 const limitToAdd = LimitPostFactory.build();
248 let limitFromBE = {...limitToAdd};
249 limitFromBE.metric = getStrValue(limitFromBE.metric);
250 limitFromBE.unit = getStrValue(limitFromBE.unit);
252 deepFreeze(limitToAdd);
253 deepFreeze(limitFromBE);
255 const LimitIdFromResponse = 'ADDED_ID';
256 const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse};
257 deepFreeze(limitAddedItem);
258 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
260 const expectedCurrentScreenProps = {
261 ...itemPermissionAndProps,
263 ...itemPermissionAndProps.itemPermission,
268 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [limitAddedItem]);
269 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
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`);
273 expect(data).toEqual(limitFromBE);
274 expect(options).toEqual(undefined);
277 value: LimitIdFromResponse
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]};
288 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}};
295 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch,
297 licenseModelId: LICENSE_MODEL_ID,
303 expect(store.getState()).toEqual(expectedStore);
307 it('Delete Limit', () => {
309 const limitsList = LimitItemFactory.buildList(1);
310 deepFreeze(limitsList);
312 const store = storeCreator({
313 currentScreen: {...itemPermissionAndProps},
316 entitlementPoolEditor: {
322 deepFreeze(store.getState());
324 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
326 const expectedCurrentScreenProps = {
327 ...itemPermissionAndProps,
329 ...itemPermissionAndProps.itemPermission,
334 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', []);
335 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
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);
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: []};
355 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}};
362 return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, {
363 licenseModelId: LICENSE_MODEL_ID,
368 expect(store.getState()).toEqual(expectedStore);
372 it('Update Limit', () => {
374 const limitsList = LimitItemFactory.buildList(1);
375 deepFreeze(limitsList);
376 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
377 const store = storeCreator({
378 currentScreen: {...itemPermissionAndProps},
381 licenseKeyGroupsEditor: {
388 deepFreeze(store.getState());
391 const previousData = limitsList[0];
392 deepFreeze(previousData);
393 const limitId = limitsList[0].id;
395 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);
401 const expectedCurrentScreenProps = {
402 ...itemPermissionAndProps,
404 ...itemPermissionAndProps.itemPermission,
409 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [updatedLimitForPut]);
410 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
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'};
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);
424 return {results: [updatedLimitForPut]};
427 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}};
434 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch,
436 licenseModelId: LICENSE_MODEL_ID,
442 expect(store.getState()).toEqual(expectedStore);