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 FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
21 import { FeatureGroupStoreFactory, FeatureGroupPostFactory, FeatureGroupDispatchFactory, FeatureGroupPutFactory } from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
22 import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
25 describe('Feature Groups Module Tests', function () {
27 const LICENSE_MODEL_ID = '555';
28 const version = VersionControllerUtilsFactory.build().version;
30 it('Load Feature Groups List', () => {
32 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory);
33 deepFreeze(featureGroupsList);
35 const store = storeCreator();
36 deepFreeze(store.getState());
38 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', featureGroupsList);
40 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
41 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`);
42 expect(data).toEqual(undefined);
43 expect(options).toEqual(undefined);
44 return {results: featureGroupsList};
47 return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
48 expect(store.getState()).toEqual(expectedStore);
52 it('Delete Feature Group', () => {
53 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1);
54 deepFreeze(featureGroupsList);
55 const store = storeCreator({
62 deepFreeze(store.getState());
64 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', []);
66 const idToDelete = featureGroupsList[0].id;
68 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
69 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups/${idToDelete}`);
70 expect(data).toEqual(undefined);
71 expect(options).toEqual(undefined);
79 return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, {
80 licenseModelId: LICENSE_MODEL_ID,
82 featureGroupId: idToDelete
84 expect(store.getState()).toEqual(expectedStore);
88 it('Add Feature Group', () => {
90 const store = storeCreator();
91 deepFreeze(store.getState());
93 const FeatureGroupPostRequest = FeatureGroupPostFactory.build({
94 addedLicenseKeyGroupsIds: [1],
95 addedEntitlementPoolsIds: [1]
97 const featureGroupToAdd = FeatureGroupDispatchFactory.build({
98 licenseKeyGroupsIds: [1],
99 entitlementPoolsIds: [1]
102 const featureGroupIdFromResponse = 'ADDED_ID';
103 const featureGroupAfterAdd = FeatureGroupStoreFactory.build({
104 ...featureGroupToAdd,
105 id: featureGroupIdFromResponse
108 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupAfterAdd]);
110 mockRest.addHandler('post', ({data, options, baseUrl}) => {
111 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`);
112 expect(data).toEqual(FeatureGroupPostRequest);
113 expect(options).toEqual(undefined);
116 value: featureGroupIdFromResponse
120 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
121 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
122 expect(data).toEqual(undefined);
123 expect(options).toEqual(undefined);
124 return {results: []};
127 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
128 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
129 expect(data).toEqual(undefined);
130 expect(options).toEqual(undefined);
131 return {results: []};
135 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
136 licenseModelId: LICENSE_MODEL_ID,
138 featureGroup: featureGroupToAdd
140 expect(store.getState()).toEqual(expectedStore);
144 it('Update Feature Group', () => {
145 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1, {
146 licenseKeyGroupsIds: [1],
147 entitlementPoolsIds: [1]
149 deepFreeze(featureGroupsList);
151 const store = storeCreator({
158 deepFreeze(store.getState());
160 const toBeUpdatedFeatureGroupId = featureGroupsList[0].id;
161 const previousFeatureGroupData = featureGroupsList[0];
163 const featureGroupUpdateData = FeatureGroupStoreFactory.build({
164 ...previousFeatureGroupData,
165 licenseKeyGroupsIds: [7],
166 entitlementPoolsIds: [7]
168 deepFreeze(featureGroupUpdateData);
170 const FeatureGroupPutFactoryRequest = FeatureGroupPutFactory.build({
171 name: featureGroupUpdateData.name,
172 description: featureGroupUpdateData.description,
173 partNumber: featureGroupUpdateData.partNumber,
174 addedLicenseKeyGroupsIds: [7],
175 addedEntitlementPoolsIds: [7],
176 removedLicenseKeyGroupsIds: [1],
177 removedEntitlementPoolsIds: [1]
179 deepFreeze(FeatureGroupPutFactoryRequest);
181 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupUpdateData]);
184 mockRest.addHandler('put', ({data, options, baseUrl}) => {
185 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups/${toBeUpdatedFeatureGroupId}`);
186 expect(data).toEqual(FeatureGroupPutFactoryRequest);
187 expect(options).toEqual(undefined);
188 return {returnCode: 'OK'};
191 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
192 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
193 expect(data).toEqual(undefined);
194 expect(options).toEqual(undefined);
195 return {results: []};
198 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
199 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
200 expect(data).toEqual(undefined);
201 expect(options).toEqual(undefined);
202 return {results: []};
205 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
206 licenseModelId: LICENSE_MODEL_ID,
208 previousFeatureGroup: previousFeatureGroupData,
209 featureGroup: featureGroupUpdateData
211 expect(store.getState()).toEqual(expectedStore);
216 it('Open Editor', () => {
218 const store = storeCreator();
219 deepFreeze(store.getState());
221 const editorData = FeatureGroupStoreFactory.build();
222 deepFreeze(editorData);
223 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupEditor.data', editorData);
224 const LICENSE_MODEL_ID = '123';
226 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
227 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
228 expect(data).toEqual(undefined);
229 expect(options).toEqual(undefined);
230 return {results: []};
233 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
234 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
235 expect(data).toEqual(undefined);
236 expect(options).toEqual(undefined);
237 return {results: []};
241 FeatureGroupsActionHelper.openFeatureGroupsEditor(store.dispatch, {featureGroup: editorData, licenseModelId: '123', version});
243 expect(store.getState()).toEqual(expectedStore);