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 VersionFactory from 'test-utils/factories/common/VersionFactory.js';
23 import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
24 import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js';
27 describe('Feature Groups Module Tests', function () {
29 const LICENSE_MODEL_ID = '555';
30 const version = VersionFactory.build();
31 const itemPermissionAndProps = CurrentScreenFactory.build({}, {version});
32 const returnedVersionFields = {baseId: version.baseId, description: version.description, id: version.id, name: version.name, status: version.status};
34 it('Load Feature Groups List', () => {
36 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory);
37 deepFreeze(featureGroupsList);
39 const store = storeCreator();
40 deepFreeze(store.getState());
42 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', featureGroupsList);
44 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
45 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`);
46 expect(data).toEqual(undefined);
47 expect(options).toEqual(undefined);
48 return {results: featureGroupsList};
51 return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
52 expect(store.getState()).toEqual(expectedStore);
56 it('Delete Feature Group', () => {
57 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1);
58 deepFreeze(featureGroupsList);
59 const store = storeCreator({
60 currentScreen: {...itemPermissionAndProps},
67 deepFreeze(store.getState());
69 const expectedCurrentScreenProps = {
70 ...itemPermissionAndProps,
72 ...itemPermissionAndProps.itemPermission,
77 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', []);
78 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
80 const idToDelete = featureGroupsList[0].id;
82 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
83 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups/${idToDelete}`);
84 expect(data).toEqual(undefined);
85 expect(options).toEqual(undefined);
93 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
94 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
95 expect(data).toEqual(undefined);
96 expect(options).toEqual(undefined);
97 return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
100 return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, {
101 licenseModelId: LICENSE_MODEL_ID,
103 featureGroupId: idToDelete
105 expect(store.getState()).toEqual(expectedStore);
109 it('Add Feature Group', () => {
111 const store = storeCreator({
112 currentScreen: {...itemPermissionAndProps},
115 featureGroupsList: []
119 deepFreeze(store.getState());
121 const FeatureGroupPostRequest = FeatureGroupPostFactory.build({
122 addedLicenseKeyGroupsIds: [1],
123 addedEntitlementPoolsIds: [1]
125 const featureGroupToAdd = FeatureGroupDispatchFactory.build({
126 licenseKeyGroupsIds: [1],
127 entitlementPoolsIds: [1]
130 const featureGroupIdFromResponse = 'ADDED_ID';
131 const featureGroupAfterAdd = FeatureGroupStoreFactory.build({
132 ...featureGroupToAdd,
133 id: featureGroupIdFromResponse
136 const expectedCurrentScreenProps = {
137 ...itemPermissionAndProps,
139 ...itemPermissionAndProps.itemPermission,
144 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupAfterAdd]);
145 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
147 mockRest.addHandler('post', ({data, options, baseUrl}) => {
148 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`);
149 expect(data).toEqual(FeatureGroupPostRequest);
150 expect(options).toEqual(undefined);
153 value: featureGroupIdFromResponse
157 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
158 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
159 expect(data).toEqual(undefined);
160 expect(options).toEqual(undefined);
161 return {results: []};
164 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
165 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
166 expect(data).toEqual(undefined);
167 expect(options).toEqual(undefined);
168 return {results: []};
171 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
172 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
173 expect(data).toEqual(undefined);
174 expect(options).toEqual(undefined);
175 return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
179 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
180 licenseModelId: LICENSE_MODEL_ID,
182 featureGroup: featureGroupToAdd
184 expect(store.getState()).toEqual(expectedStore);
188 it('Update Feature Group', () => {
189 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1, {
190 licenseKeyGroupsIds: [1],
191 entitlementPoolsIds: [1]
193 deepFreeze(featureGroupsList);
195 const store = storeCreator({
196 currentScreen: {...itemPermissionAndProps},
203 deepFreeze(store.getState());
205 const toBeUpdatedFeatureGroupId = featureGroupsList[0].id;
206 const previousFeatureGroupData = featureGroupsList[0];
208 const featureGroupUpdateData = FeatureGroupStoreFactory.build({
209 ...previousFeatureGroupData,
210 licenseKeyGroupsIds: [7],
211 entitlementPoolsIds: [7]
213 deepFreeze(featureGroupUpdateData);
215 const FeatureGroupPutFactoryRequest = FeatureGroupPutFactory.build({
216 name: featureGroupUpdateData.name,
217 description: featureGroupUpdateData.description,
218 partNumber: featureGroupUpdateData.partNumber,
219 addedLicenseKeyGroupsIds: [7],
220 addedEntitlementPoolsIds: [7],
221 removedLicenseKeyGroupsIds: [1],
222 removedEntitlementPoolsIds: [1]
224 deepFreeze(FeatureGroupPutFactoryRequest);
226 const expectedCurrentScreenProps = {
227 ...itemPermissionAndProps,
229 ...itemPermissionAndProps.itemPermission,
234 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupUpdateData]);
235 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
238 mockRest.addHandler('put', ({data, options, baseUrl}) => {
239 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups/${toBeUpdatedFeatureGroupId}`);
240 expect(data).toEqual(FeatureGroupPutFactoryRequest);
241 expect(options).toEqual(undefined);
242 return {returnCode: 'OK'};
245 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
246 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
247 expect(data).toEqual(undefined);
248 expect(options).toEqual(undefined);
249 return {results: []};
252 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
253 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
254 expect(data).toEqual(undefined);
255 expect(options).toEqual(undefined);
256 return {results: []};
259 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
260 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${LICENSE_MODEL_ID}/versions/${version.id}`);
261 expect(data).toEqual(undefined);
262 expect(options).toEqual(undefined);
263 return {...returnedVersionFields, state: {synchronizationState: SyncStates.UP_TO_DATE, dirty: true}};
266 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
267 licenseModelId: LICENSE_MODEL_ID,
269 previousFeatureGroup: previousFeatureGroupData,
270 featureGroup: featureGroupUpdateData
272 expect(store.getState()).toEqual(expectedStore);
277 it('Open Editor', () => {
279 const store = storeCreator();
280 deepFreeze(store.getState());
282 const editorData = FeatureGroupStoreFactory.build();
283 deepFreeze(editorData);
284 const LICENSE_MODEL_ID = '123';
286 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
287 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
288 expect(data).toEqual(undefined);
289 expect(options).toEqual(undefined);
290 return {results: []};
293 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
294 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
295 expect(data).toEqual(undefined);
296 expect(options).toEqual(undefined);
297 return {results: []};
301 return FeatureGroupsActionHelper.openFeatureGroupsEditor(store.dispatch, {featureGroup: editorData, licenseModelId: '123', version}).then(() => {
302 expect(store.getState().licenseModel.featureGroup.featureGroupEditor.data).toEqual(editorData);