[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / test / licenseModel / featureGroups / test.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
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';
23
24
25 describe('Feature Groups Module Tests', function () {
26
27         const LICENSE_MODEL_ID = '555';
28         const version = VersionControllerUtilsFactory.build().version;
29
30         it('Load Feature Groups List', () => {
31
32                 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory);
33                 deepFreeze(featureGroupsList);
34
35                 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}) => {
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};
45                 });
46
47                 return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
48                         expect(store.getState()).toEqual(expectedStore);
49                 });
50         });
51
52         it('Delete Feature Group', () => {
53                 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1);
54                 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
66                 const idToDelete = featureGroupsList[0].id;
67
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);
72                         return {
73                                 results: {
74                                         returnCode: 'OK'
75                                 }
76                         };
77                 });
78
79                 return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, {
80                         licenseModelId: LICENSE_MODEL_ID,
81                         version,
82                         featureGroupId: idToDelete
83                 }).then(() => {
84                         expect(store.getState()).toEqual(expectedStore);
85                 });
86         });
87
88         it('Add Feature Group', () => {
89
90                 const store = storeCreator();
91                 deepFreeze(store.getState());
92
93                 const FeatureGroupPostRequest = FeatureGroupPostFactory.build({
94                         addedLicenseKeyGroupsIds: [1],
95                         addedEntitlementPoolsIds: [1]
96                 });
97                 const featureGroupToAdd = FeatureGroupDispatchFactory.build({
98                         licenseKeyGroupsIds: [1],
99                         entitlementPoolsIds: [1]
100                 });
101
102                 const featureGroupIdFromResponse = 'ADDED_ID';
103                 const featureGroupAfterAdd = FeatureGroupStoreFactory.build({
104                         ...featureGroupToAdd,
105                         id: featureGroupIdFromResponse
106                 });
107
108                 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupAfterAdd]);
109
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);
114                         return {
115                                 returnCode: 'OK',
116                                 value: featureGroupIdFromResponse
117                         };
118                 });
119
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: []};
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
135                 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
136                         licenseModelId: LICENSE_MODEL_ID,
137                         version,
138                         featureGroup: featureGroupToAdd
139                 }).then(() => {
140                         expect(store.getState()).toEqual(expectedStore);
141                 });
142         });
143
144         it('Update Feature Group', () => {
145                 const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1, {
146                         licenseKeyGroupsIds: [1],
147                         entitlementPoolsIds: [1]
148                 });
149                 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];
162
163                 const featureGroupUpdateData = FeatureGroupStoreFactory.build({
164                         ...previousFeatureGroupData,
165                         licenseKeyGroupsIds: [7],
166                         entitlementPoolsIds: [7]
167                 });
168                 deepFreeze(featureGroupUpdateData);
169
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]
178                 });
179                 deepFreeze(FeatureGroupPutFactoryRequest);
180
181                 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupUpdateData]);
182
183
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'};
189                 });
190
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: []};
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
205                 return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
206                         licenseModelId: LICENSE_MODEL_ID,
207                         version,
208                         previousFeatureGroup: previousFeatureGroupData,
209                         featureGroup: featureGroupUpdateData
210                 }).then(() => {
211                         expect(store.getState()).toEqual(expectedStore);
212                 });
213
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
248         });
249
250 });