blob: 7d0d7242b5317b49049a431c821b9f01d6d39fee [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';
22import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
Michael Landoefa037d2017-02-19 12:57:33 +020023
24
25describe('Feature Groups Module Tests', function () {
26
27 const LICENSE_MODEL_ID = '555';
AviZi280f8012017-06-09 02:39:56 +030028 const version = VersionControllerUtilsFactory.build().version;
Michael Landoefa037d2017-02-19 12:57:33 +020029
30 it('Load Feature Groups List', () => {
AviZi280f8012017-06-09 02:39:56 +030031
32 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory);
Michael Landoefa037d2017-02-19 12:57:33 +020033 deepFreeze(featureGroupsList);
AviZi280f8012017-06-09 02:39:56 +030034
Michael Landoefa037d2017-02-19 12:57:33 +020035 const store = storeCreator();
36 deepFreeze(store.getState());
37
38 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', featureGroupsList);
39
40 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030041 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);
Michael Landoefa037d2017-02-19 12:57:33 +020044 return {results: featureGroupsList};
45 });
46
AviZi280f8012017-06-09 02:39:56 +030047 return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
48 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020049 });
50 });
51
52 it('Delete Feature Group', () => {
AviZi280f8012017-06-09 02:39:56 +030053 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1);
Michael Landoefa037d2017-02-19 12:57:33 +020054 deepFreeze(featureGroupsList);
55 const store = storeCreator({
56 licenseModel: {
57 featureGroup: {
58 featureGroupsList
59 }
60 }
61 });
62 deepFreeze(store.getState());
63
64 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', []);
65
AviZi280f8012017-06-09 02:39:56 +030066 const idToDelete = featureGroupsList[0].id;
67
Michael Landoefa037d2017-02-19 12:57:33 +020068 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030069 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);
Michael Landoefa037d2017-02-19 12:57:33 +020072 return {
73 results: {
74 returnCode: 'OK'
75 }
76 };
77 });
78
79 return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, {
80 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +030081 version,
82 featureGroupId: idToDelete
Michael Landoefa037d2017-02-19 12:57:33 +020083 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +030084 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020085 });
86 });
87
88 it('Add Feature Group', () => {
89
90 const store = storeCreator();
91 deepFreeze(store.getState());
92
AviZi280f8012017-06-09 02:39:56 +030093 const FeatureGroupPostRequest = FeatureGroupPostFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +020094 addedLicenseKeyGroupsIds: [1],
95 addedEntitlementPoolsIds: [1]
AviZi280f8012017-06-09 02:39:56 +030096 });
97 const featureGroupToAdd = FeatureGroupDispatchFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +020098 licenseKeyGroupsIds: [1],
99 entitlementPoolsIds: [1]
AviZi280f8012017-06-09 02:39:56 +0300100 });
101
Michael Landoefa037d2017-02-19 12:57:33 +0200102 const featureGroupIdFromResponse = 'ADDED_ID';
AviZi280f8012017-06-09 02:39:56 +0300103 const featureGroupAfterAdd = FeatureGroupStoreFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200104 ...featureGroupToAdd,
105 id: featureGroupIdFromResponse
AviZi280f8012017-06-09 02:39:56 +0300106 });
Michael Landoefa037d2017-02-19 12:57:33 +0200107
108 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupAfterAdd]);
109
AviZi280f8012017-06-09 02:39:56 +0300110 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);
Michael Landoefa037d2017-02-19 12:57:33 +0200114 return {
115 returnCode: 'OK',
116 value: featureGroupIdFromResponse
117 };
118 });
119
AviZi280f8012017-06-09 02:39:56 +0300120 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: []};
125 });
126
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: []};
132 });
133
134
Michael Landoefa037d2017-02-19 12:57:33 +0200135 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
136 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300137 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200138 featureGroup: featureGroupToAdd
139 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300140 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200141 });
142 });
143
144 it('Update Feature Group', () => {
AviZi280f8012017-06-09 02:39:56 +0300145 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1, {
Michael Landoefa037d2017-02-19 12:57:33 +0200146 licenseKeyGroupsIds: [1],
AviZi280f8012017-06-09 02:39:56 +0300147 entitlementPoolsIds: [1]
148 });
Michael Landoefa037d2017-02-19 12:57:33 +0200149 deepFreeze(featureGroupsList);
150
151 const store = storeCreator({
152 licenseModel: {
153 featureGroup: {
154 featureGroupsList
155 }
156 }
157 });
158 deepFreeze(store.getState());
159
160 const toBeUpdatedFeatureGroupId = featureGroupsList[0].id;
161 const previousFeatureGroupData = featureGroupsList[0];
AviZi280f8012017-06-09 02:39:56 +0300162
163 const featureGroupUpdateData = FeatureGroupStoreFactory.build({
164 ...previousFeatureGroupData,
Michael Landoefa037d2017-02-19 12:57:33 +0200165 licenseKeyGroupsIds: [7],
166 entitlementPoolsIds: [7]
AviZi280f8012017-06-09 02:39:56 +0300167 });
Michael Landoefa037d2017-02-19 12:57:33 +0200168 deepFreeze(featureGroupUpdateData);
169
AviZi280f8012017-06-09 02:39:56 +0300170 const FeatureGroupPutFactoryRequest = FeatureGroupPutFactory.build({
171 name: featureGroupUpdateData.name,
172 description: featureGroupUpdateData.description,
173 partNumber: featureGroupUpdateData.partNumber,
Michael Landoefa037d2017-02-19 12:57:33 +0200174 addedLicenseKeyGroupsIds: [7],
175 addedEntitlementPoolsIds: [7],
176 removedLicenseKeyGroupsIds: [1],
177 removedEntitlementPoolsIds: [1]
AviZi280f8012017-06-09 02:39:56 +0300178 });
179 deepFreeze(FeatureGroupPutFactoryRequest);
Michael Landoefa037d2017-02-19 12:57:33 +0200180
181 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupUpdateData]);
182
183
AviZi280f8012017-06-09 02:39:56 +0300184 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);
Michael Landoefa037d2017-02-19 12:57:33 +0200188 return {returnCode: 'OK'};
189 });
190
AviZi280f8012017-06-09 02:39:56 +0300191 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: []};
196 });
197
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: []};
203 });
204
Michael Landoefa037d2017-02-19 12:57:33 +0200205 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
206 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300207 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200208 previousFeatureGroup: previousFeatureGroupData,
209 featureGroup: featureGroupUpdateData
210 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300211 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200212 });
AviZi280f8012017-06-09 02:39:56 +0300213
214 });
215
216 it('Open Editor', () => {
217
218 const store = storeCreator();
219 deepFreeze(store.getState());
220
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';
225
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: []};
231 });
232
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: []};
238 });
239
240
241 FeatureGroupsActionHelper.openFeatureGroupsEditor(store.dispatch, {featureGroup: editorData, licenseModelId: '123', version});
242 setTimeout(() =>{
243 expect(store.getState()).toEqual(expectedStore);
244 }, 100);
245
246
247
Michael Landoefa037d2017-02-19 12:57:33 +0200248 });
249
250});