blob: eb947b83d00e718619af644f5b1ed68d41f60c75 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
AviZi280f8012017-06-09 02:39:56 +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,
AviZi280f8012017-06-09 02:39:56 +030012 * 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.
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';
AviZi280f8012017-06-09 02:39:56 +030018import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
Michael Landoefa037d2017-02-19 12:57:33 +020019import {storeCreator} from 'sdc-app/AppStore.js';
20import FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
AviZi280f8012017-06-09 02:39:56 +030021import { FeatureGroupStoreFactory, FeatureGroupPostFactory, FeatureGroupDispatchFactory, FeatureGroupPutFactory } from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
talig8e9c0652017-12-20 14:30:43 +020022import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
23import CurrentScreenFactory from 'test-utils/factories/common/CurrentScreenFactory.js';
24import {SyncStates} from 'sdc-app/common/merge/MergeEditorConstants.js';
Michael Landoefa037d2017-02-19 12:57:33 +020025
26
27describe('Feature Groups Module Tests', function () {
28
29 const LICENSE_MODEL_ID = '555';
talig8e9c0652017-12-20 14:30:43 +020030 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};
Michael Landoefa037d2017-02-19 12:57:33 +020033
34 it('Load Feature Groups List', () => {
AviZi280f8012017-06-09 02:39:56 +030035
36 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory);
Michael Landoefa037d2017-02-19 12:57:33 +020037 deepFreeze(featureGroupsList);
AviZi280f8012017-06-09 02:39:56 +030038
Michael Landoefa037d2017-02-19 12:57:33 +020039 const store = storeCreator();
40 deepFreeze(store.getState());
41
42 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', featureGroupsList);
43
44 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030045 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);
Michael Landoefa037d2017-02-19 12:57:33 +020048 return {results: featureGroupsList};
49 });
50
AviZi280f8012017-06-09 02:39:56 +030051 return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
52 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020053 });
54 });
55
56 it('Delete Feature Group', () => {
AviZi280f8012017-06-09 02:39:56 +030057 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1);
Michael Landoefa037d2017-02-19 12:57:33 +020058 deepFreeze(featureGroupsList);
59 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +020060 currentScreen: {...itemPermissionAndProps},
Michael Landoefa037d2017-02-19 12:57:33 +020061 licenseModel: {
62 featureGroup: {
63 featureGroupsList
64 }
65 }
66 });
67 deepFreeze(store.getState());
68
talig8e9c0652017-12-20 14:30:43 +020069 const expectedCurrentScreenProps = {
70 ...itemPermissionAndProps,
71 itemPermission: {
72 ...itemPermissionAndProps.itemPermission,
73 isDirty: true
74 }
75 };
76
77 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', []);
78 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
Michael Landoefa037d2017-02-19 12:57:33 +020079
AviZi280f8012017-06-09 02:39:56 +030080 const idToDelete = featureGroupsList[0].id;
81
Michael Landoefa037d2017-02-19 12:57:33 +020082 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030083 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);
Michael Landoefa037d2017-02-19 12:57:33 +020086 return {
87 results: {
88 returnCode: 'OK'
89 }
90 };
91 });
92
talig8e9c0652017-12-20 14:30:43 +020093 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}};
98 });
99
Michael Landoefa037d2017-02-19 12:57:33 +0200100 return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, {
101 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300102 version,
103 featureGroupId: idToDelete
Michael Landoefa037d2017-02-19 12:57:33 +0200104 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300105 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200106 });
107 });
108
109 it('Add Feature Group', () => {
110
talig8e9c0652017-12-20 14:30:43 +0200111 const store = storeCreator({
112 currentScreen: {...itemPermissionAndProps},
113 licenseModel: {
114 featureGroup: {
115 featureGroupsList: []
116 }
117 }
118 });
Michael Landoefa037d2017-02-19 12:57:33 +0200119 deepFreeze(store.getState());
120
AviZi280f8012017-06-09 02:39:56 +0300121 const FeatureGroupPostRequest = FeatureGroupPostFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200122 addedLicenseKeyGroupsIds: [1],
123 addedEntitlementPoolsIds: [1]
AviZi280f8012017-06-09 02:39:56 +0300124 });
125 const featureGroupToAdd = FeatureGroupDispatchFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200126 licenseKeyGroupsIds: [1],
127 entitlementPoolsIds: [1]
AviZi280f8012017-06-09 02:39:56 +0300128 });
129
Michael Landoefa037d2017-02-19 12:57:33 +0200130 const featureGroupIdFromResponse = 'ADDED_ID';
AviZi280f8012017-06-09 02:39:56 +0300131 const featureGroupAfterAdd = FeatureGroupStoreFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200132 ...featureGroupToAdd,
133 id: featureGroupIdFromResponse
AviZi280f8012017-06-09 02:39:56 +0300134 });
Michael Landoefa037d2017-02-19 12:57:33 +0200135
talig8e9c0652017-12-20 14:30:43 +0200136 const expectedCurrentScreenProps = {
137 ...itemPermissionAndProps,
138 itemPermission: {
139 ...itemPermissionAndProps.itemPermission,
140 isDirty: true
141 }
142 };
143
144 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupAfterAdd]);
145 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
Michael Landoefa037d2017-02-19 12:57:33 +0200146
AviZi280f8012017-06-09 02:39:56 +0300147 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);
Michael Landoefa037d2017-02-19 12:57:33 +0200151 return {
152 returnCode: 'OK',
153 value: featureGroupIdFromResponse
154 };
155 });
156
AviZi280f8012017-06-09 02:39:56 +0300157 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: []};
162 });
163
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: []};
169 });
170
talig8e9c0652017-12-20 14:30:43 +0200171 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}};
176 });
177
AviZi280f8012017-06-09 02:39:56 +0300178
Michael Landoefa037d2017-02-19 12:57:33 +0200179 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
180 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300181 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200182 featureGroup: featureGroupToAdd
183 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300184 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200185 });
186 });
187
188 it('Update Feature Group', () => {
AviZi280f8012017-06-09 02:39:56 +0300189 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1, {
Michael Landoefa037d2017-02-19 12:57:33 +0200190 licenseKeyGroupsIds: [1],
AviZi280f8012017-06-09 02:39:56 +0300191 entitlementPoolsIds: [1]
192 });
Michael Landoefa037d2017-02-19 12:57:33 +0200193 deepFreeze(featureGroupsList);
194
195 const store = storeCreator({
talig8e9c0652017-12-20 14:30:43 +0200196 currentScreen: {...itemPermissionAndProps},
Michael Landoefa037d2017-02-19 12:57:33 +0200197 licenseModel: {
198 featureGroup: {
199 featureGroupsList
200 }
201 }
202 });
203 deepFreeze(store.getState());
204
205 const toBeUpdatedFeatureGroupId = featureGroupsList[0].id;
206 const previousFeatureGroupData = featureGroupsList[0];
AviZi280f8012017-06-09 02:39:56 +0300207
208 const featureGroupUpdateData = FeatureGroupStoreFactory.build({
209 ...previousFeatureGroupData,
Michael Landoefa037d2017-02-19 12:57:33 +0200210 licenseKeyGroupsIds: [7],
211 entitlementPoolsIds: [7]
AviZi280f8012017-06-09 02:39:56 +0300212 });
Michael Landoefa037d2017-02-19 12:57:33 +0200213 deepFreeze(featureGroupUpdateData);
214
AviZi280f8012017-06-09 02:39:56 +0300215 const FeatureGroupPutFactoryRequest = FeatureGroupPutFactory.build({
216 name: featureGroupUpdateData.name,
217 description: featureGroupUpdateData.description,
218 partNumber: featureGroupUpdateData.partNumber,
Michael Landoefa037d2017-02-19 12:57:33 +0200219 addedLicenseKeyGroupsIds: [7],
220 addedEntitlementPoolsIds: [7],
221 removedLicenseKeyGroupsIds: [1],
222 removedEntitlementPoolsIds: [1]
AviZi280f8012017-06-09 02:39:56 +0300223 });
224 deepFreeze(FeatureGroupPutFactoryRequest);
Michael Landoefa037d2017-02-19 12:57:33 +0200225
talig8e9c0652017-12-20 14:30:43 +0200226 const expectedCurrentScreenProps = {
227 ...itemPermissionAndProps,
228 itemPermission: {
229 ...itemPermissionAndProps.itemPermission,
230 isDirty: true
231 }
232 };
233
234 let expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupUpdateData]);
235 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreenProps.itemPermission);
Michael Landoefa037d2017-02-19 12:57:33 +0200236
237
AviZi280f8012017-06-09 02:39:56 +0300238 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);
Michael Landoefa037d2017-02-19 12:57:33 +0200242 return {returnCode: 'OK'};
243 });
244
AviZi280f8012017-06-09 02:39:56 +0300245 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: []};
250 });
251
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: []};
257 });
258
talig8e9c0652017-12-20 14:30:43 +0200259 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}};
264 });
265
Michael Landoefa037d2017-02-19 12:57:33 +0200266 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
267 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300268 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200269 previousFeatureGroup: previousFeatureGroupData,
270 featureGroup: featureGroupUpdateData
271 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300272 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200273 });
AviZi280f8012017-06-09 02:39:56 +0300274
275 });
276
277 it('Open Editor', () => {
278
279 const store = storeCreator();
280 deepFreeze(store.getState());
281
282 const editorData = FeatureGroupStoreFactory.build();
283 deepFreeze(editorData);
AviZi280f8012017-06-09 02:39:56 +0300284 const LICENSE_MODEL_ID = '123';
285
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: []};
291 });
292
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: []};
298 });
299
300
talig8e9c0652017-12-20 14:30:43 +0200301 return FeatureGroupsActionHelper.openFeatureGroupsEditor(store.dispatch, {featureGroup: editorData, licenseModelId: '123', version}).then(() => {
302 expect(store.getState().licenseModel.featureGroup.featureGroupEditor.data).toEqual(editorData);
303 });
Michael Landoefa037d2017-02-19 12:57:33 +0200304 });
305
306});