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 VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
24 import {LimitItemFactory, LimitPostFactory} from 'test-utils/factories/licenseModel/LimitFactories.js';
26 describe('License Key Groups Module Tests', function () {
28 const LICENSE_MODEL_ID = '555';
29 const version = VersionControllerUtilsFactory.build().version;
31 it('Load License Key Group', () => {
33 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory);
35 deepFreeze(licenseKeyGroupsList);
36 const store = storeCreator();
37 deepFreeze(store.getState());
39 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList);
41 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
42 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
43 expect(data).toEqual(undefined);
44 expect(options).toEqual(undefined);
45 return {results: licenseKeyGroupsList};
48 return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
49 expect(store.getState()).toEqual(expectedStore);
53 it('Delete License Key Group', () => {
55 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
57 deepFreeze(licenseKeyGroupsList);
58 const store = storeCreator({
65 deepFreeze(store.getState());
66 const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
67 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []);
69 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
70 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeDeletedLicenseKeyGroupId}`);
71 expect(data).toEqual(undefined);
72 expect(options).toEqual(undefined);
75 return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, {
76 licenseKeyGroupId: toBeDeletedLicenseKeyGroupId,
77 licenseModelId: LICENSE_MODEL_ID,
80 expect(store.getState()).toEqual(expectedStore);
84 it('Add License Key Group', () => {
86 const store = storeCreator();
87 deepFreeze(store.getState());
89 const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build();
90 deepFreeze(LicenseKeyGroupPost);
92 const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build();
93 deepFreeze(LicenseKeyGroupStore);
95 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [LicenseKeyGroupStore]);
97 mockRest.addHandler('post', ({options, data, baseUrl}) => {
98 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
99 expect(data).toEqual(LicenseKeyGroupPost);
100 expect(options).toEqual(undefined);
102 value: LicenseKeyGroupStore.id
106 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
107 licenseKeyGroup: LicenseKeyGroupPost,
108 licenseModelId: LICENSE_MODEL_ID,
111 expect(store.getState()).toEqual(expectedStore);
115 it('Update License Key Group', () => {
116 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
117 deepFreeze(licenseKeyGroupsList);
118 const store = storeCreator({
126 const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
127 const previousLicenseKeyGroupData = licenseKeyGroupsList[0];
129 const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({
131 description: 'string_UPDATE',
132 id: toBeUpdatedLicenseKeyGroupId
134 deepFreeze(licenseKeyGroupUpdatedData);
136 const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({
138 description: 'string_UPDATE'
141 deepFreeze(licenseKeyGroupPutRequest);
143 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]);
145 mockRest.addHandler('put', ({data, options, baseUrl}) => {
146 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`);
147 expect(data).toEqual(licenseKeyGroupPutRequest);
148 expect(options).toEqual(undefined);
151 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
152 previousLicenseKeyGroup: previousLicenseKeyGroupData,
153 licenseKeyGroup: licenseKeyGroupUpdatedData,
154 licenseModelId: LICENSE_MODEL_ID,
157 expect(store.getState()).toEqual(expectedStore);
161 it('Load Limits List', () => {
163 const limitsList = LimitItemFactory.buildList(3);
164 deepFreeze(limitsList);
165 const store = storeCreator();
166 deepFreeze(store.getState());
168 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', limitsList);
169 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
170 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
171 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
172 expect(data).toEqual(undefined);
173 expect(options).toEqual(undefined);
174 return {results: limitsList};
177 return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, licenseKeyGroup}).then(() => {
178 expect(store.getState()).toEqual(expectedStore);
182 it('Add Limit', () => {
184 const store = storeCreator();
185 deepFreeze(store.getState());
187 const limitToAdd = LimitPostFactory.build();
189 deepFreeze(limitToAdd);
191 const LimitIdFromResponse = 'ADDED_ID';
192 const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse};
193 deepFreeze(limitAddedItem);
194 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
196 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [limitAddedItem]);
198 mockRest.addHandler('post', ({data, options, baseUrl}) => {
199 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
200 expect(data).toEqual(limitToAdd);
201 expect(options).toEqual(undefined);
204 value: LimitIdFromResponse
208 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
209 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
210 expect(data).toEqual(undefined);
211 expect(options).toEqual(undefined);
212 return {results: [limitAddedItem]};
215 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch,
217 licenseModelId: LICENSE_MODEL_ID,
223 expect(store.getState()).toEqual(expectedStore);
227 it('Delete Limit', () => {
229 const limitsList = LimitItemFactory.buildList(1);
230 deepFreeze(limitsList);
232 const store = storeCreator({
235 entitlementPoolEditor: {
241 deepFreeze(store.getState());
243 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
244 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', []);
246 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
247 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}`);
248 expect(data).toEqual(undefined);
249 expect(options).toEqual(undefined);
257 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
258 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
259 expect(data).toEqual(undefined);
260 expect(options).toEqual(undefined);
261 return {results: []};
264 return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, {
265 licenseModelId: LICENSE_MODEL_ID,
270 expect(store.getState()).toEqual(expectedStore);
274 it('Update Limit', () => {
276 const limitsList = LimitItemFactory.buildList(1);
277 deepFreeze(limitsList);
278 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
279 const store = storeCreator({
282 licenseKeyGroupsEditor: {
289 deepFreeze(store.getState());
292 const previousData = limitsList[0];
293 deepFreeze(previousData);
294 const limitId = limitsList[0].id;
296 const updatedLimit = {...previousData, name: 'updatedLimit'};
297 deepFreeze(updatedLimit);
298 const updatedLimitForPut = {...updatedLimit, id: undefined};
300 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [updatedLimit]);
303 mockRest.addHandler('put', ({data, options, baseUrl}) => {
304 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}`);
305 expect(data).toEqual(updatedLimitForPut);
306 expect(options).toEqual(undefined);
307 return {returnCode: 'OK'};
310 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
311 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
312 expect(data).toEqual(undefined);
313 expect(options).toEqual(undefined);
314 return {results: [updatedLimit]};
317 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch,
319 licenseModelId: LICENSE_MODEL_ID,
325 expect(store.getState()).toEqual(expectedStore);