blob: f5415239ad21c5a838dc64ac5d568a569b20902b [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';
Michael Landoefa037d2017-02-19 12:57:33 +020017import 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 EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
AviZi280f8012017-06-09 02:39:56 +030021import {EntitlementPoolStoreFactory, EntitlementPoolPostFactory} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js';
22import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
Avi Ziv61070c92017-07-26 17:37:57 +030023import {LimitItemFactory, LimitPostFactory} from 'test-utils/factories/licenseModel/LimitFactories.js';
az2497644017c2017-08-10 17:49:40 +030024import {getStrValue} from 'nfvo-utils/getValue.js';
Michael Landoefa037d2017-02-19 12:57:33 +020025
26describe('Entitlement Pools Module Tests', function () {
27
28 const LICENSE_MODEL_ID = '555';
AviZi280f8012017-06-09 02:39:56 +030029 const version = VersionControllerUtilsFactory.build().version;
Michael Landoefa037d2017-02-19 12:57:33 +020030
31 it('Load Entitlement Pools List', () => {
AviZi280f8012017-06-09 02:39:56 +030032
33 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory);
Michael Landoefa037d2017-02-19 12:57:33 +020034 deepFreeze(entitlementPoolsList);
35 const store = storeCreator();
36 deepFreeze(store.getState());
37
38 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', entitlementPoolsList);
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}/entitlement-pools`);
42 expect(data).toEqual(undefined);
43 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020044 return {results: entitlementPoolsList};
45 });
46
AviZi280f8012017-06-09 02:39:56 +030047 return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(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 Entitlement Pool', () => {
Michael Landoefa037d2017-02-19 12:57:33 +020053
AviZi280f8012017-06-09 02:39:56 +030054 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory,1);
Michael Landoefa037d2017-02-19 12:57:33 +020055 deepFreeze(entitlementPoolsList);
56 const store = storeCreator({
57 licenseModel: {
58 entitlementPool: {
59 entitlementPoolsList
60 }
61 }
62 });
63 deepFreeze(store.getState());
64
65 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', []);
66
67 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030068 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPoolsList[0].id}`);
69 expect(data).toEqual(undefined);
70 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020071 return {
72 results: {
73 returnCode: 'OK'
74 }
75 };
76 });
77
78 return EntitlementPoolsActionHelper.deleteEntitlementPool(store.dispatch, {
79 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +030080 version,
Michael Landoefa037d2017-02-19 12:57:33 +020081 entitlementPoolId: entitlementPoolsList[0].id
82 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +030083 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020084 });
85 });
86
87 it('Add Entitlement Pool', () => {
88
89 const store = storeCreator();
90 deepFreeze(store.getState());
91
AviZi280f8012017-06-09 02:39:56 +030092 const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build();
93
94 deepFreeze(EntitlementPoolPostRequest);
95
Michael Landoefa037d2017-02-19 12:57:33 +020096 const entitlementPoolIdFromResponse = 'ADDED_ID';
AviZi280f8012017-06-09 02:39:56 +030097 const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({id: entitlementPoolIdFromResponse});
98 deepFreeze(entitlementPoolAfterAdd);
Michael Landoefa037d2017-02-19 12:57:33 +020099
100 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolAfterAdd]);
101
AviZi280f8012017-06-09 02:39:56 +0300102 mockRest.addHandler('post', ({data, options, baseUrl}) => {
103 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
104 expect(data).toEqual(EntitlementPoolPostRequest);
105 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200106 return {
107 returnCode: 'OK',
108 value: entitlementPoolIdFromResponse
109 };
110 });
111
112 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch,
113 {
114 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300115 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200116 previousEntitlementPool: null,
AviZi280f8012017-06-09 02:39:56 +0300117 entitlementPool: EntitlementPoolPostRequest
Michael Landoefa037d2017-02-19 12:57:33 +0200118 }
119 ).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300120 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200121 });
122 });
123
124 it('Update Entitlement Pool', () => {
AviZi280f8012017-06-09 02:39:56 +0300125
126 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory, 1);
Michael Landoefa037d2017-02-19 12:57:33 +0200127 deepFreeze(entitlementPoolsList);
128
129 const store = storeCreator({
130 licenseModel: {
131 entitlementPool: {
132 entitlementPoolsList
133 }
134 }
135 });
AviZi280f8012017-06-09 02:39:56 +0300136
Michael Landoefa037d2017-02-19 12:57:33 +0200137 deepFreeze(store.getState());
138
139 const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id;
140 const previousEntitlementPoolData = entitlementPoolsList[0];
AviZi280f8012017-06-09 02:39:56 +0300141 const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED', id: toBeUpdatedEntitlementPoolId});
Michael Landoefa037d2017-02-19 12:57:33 +0200142 deepFreeze(entitlementPoolUpdateData);
143
AviZi280f8012017-06-09 02:39:56 +0300144 const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED'});
Michael Landoefa037d2017-02-19 12:57:33 +0200145 deepFreeze(entitlementPoolPutRequest);
146
147 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]);
148
149
AviZi280f8012017-06-09 02:39:56 +0300150 mockRest.addHandler('put', ({data, options, baseUrl}) => {
151 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${toBeUpdatedEntitlementPoolId}`);
152 expect(data).toEqual(entitlementPoolPutRequest);
153 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200154 return {returnCode: 'OK'};
155 });
156
157 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, {
158 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300159 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200160 previousEntitlementPool: previousEntitlementPoolData,
161 entitlementPool: entitlementPoolUpdateData
162 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300163 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200164 });
165 });
166
Avi Ziv61070c92017-07-26 17:37:57 +0300167 it('Load Limits List', () => {
168
az2497644017c2017-08-10 17:49:40 +0300169 const limitsList = LimitItemFactory.buildList(3);
Avi Ziv61070c92017-07-26 17:37:57 +0300170 deepFreeze(limitsList);
171 const store = storeCreator();
172 deepFreeze(store.getState());
173
174 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', limitsList);
175 const entitlementPool = EntitlementPoolStoreFactory.build();
176 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
177 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
178 expect(data).toEqual(undefined);
179 expect(options).toEqual(undefined);
180 return {results: limitsList};
181 });
182
183 return EntitlementPoolsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, entitlementPool}).then(() => {
184 expect(store.getState()).toEqual(expectedStore);
185 });
186 });
187
188 it('Add Limit', () => {
189
190 const store = storeCreator();
191 deepFreeze(store.getState());
192
193 const limitToAdd = LimitPostFactory.build();
az2497644017c2017-08-10 17:49:40 +0300194 let limitFromBE = {...limitToAdd};
195 limitFromBE.metric = getStrValue(limitFromBE.metric);
196 limitFromBE.unit = getStrValue(limitFromBE.unit);
Avi Ziv61070c92017-07-26 17:37:57 +0300197
198 deepFreeze(limitToAdd);
az2497644017c2017-08-10 17:49:40 +0300199 deepFreeze(limitFromBE);
Avi Ziv61070c92017-07-26 17:37:57 +0300200
201 const LimitIdFromResponse = 'ADDED_ID';
202 const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse};
203 deepFreeze(limitAddedItem);
204 const entitlementPool = EntitlementPoolStoreFactory.build();
205
206 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [limitAddedItem]);
207
208 mockRest.addHandler('post', ({data, options, baseUrl}) => {
209 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
az2497644017c2017-08-10 17:49:40 +0300210 expect(data).toEqual(limitFromBE);
Avi Ziv61070c92017-07-26 17:37:57 +0300211 expect(options).toEqual(undefined);
212 return {
213 returnCode: 'OK',
214 value: LimitIdFromResponse
215 };
216 });
217
218 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
219 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
220 expect(data).toEqual(undefined);
221 expect(options).toEqual(undefined);
222 return {results: [limitAddedItem]};
223 });
224
225 return EntitlementPoolsActionHelper.submitLimit(store.dispatch,
226 {
227 licenseModelId: LICENSE_MODEL_ID,
az2497644017c2017-08-10 17:49:40 +0300228 version,
Avi Ziv61070c92017-07-26 17:37:57 +0300229 entitlementPool,
230 limit: limitToAdd
231 }
232 ).then(() => {
233 expect(store.getState()).toEqual(expectedStore);
234 });
235 });
236
237
238 it('Delete Limit', () => {
239
az2497644017c2017-08-10 17:49:40 +0300240 const limitsList = LimitItemFactory.buildList(1);
Avi Ziv61070c92017-07-26 17:37:57 +0300241 deepFreeze(limitsList);
az2497644017c2017-08-10 17:49:40 +0300242
Avi Ziv61070c92017-07-26 17:37:57 +0300243 const store = storeCreator({
244 licenseModel: {
245 entitlementPool: {
246 entitlementPoolEditor: {
247 limitsList
248 }
249 }
250 }
251 });
252 deepFreeze(store.getState());
253
254 const entitlementPool = EntitlementPoolStoreFactory.build();
255 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', []);
256
257 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
258 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits/${limitsList[0].id}`);
259 expect(data).toEqual(undefined);
260 expect(options).toEqual(undefined);
261 return {
262 results: {
263 returnCode: 'OK'
264 }
265 };
266 });
267
268 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
269 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
270 expect(data).toEqual(undefined);
271 expect(options).toEqual(undefined);
272 return {results: []};
273 });
274
275 return EntitlementPoolsActionHelper.deleteLimit(store.dispatch, {
276 licenseModelId: LICENSE_MODEL_ID,
277 version,
278 entitlementPool,
279 limit: limitsList[0]
280 }).then(() => {
281 expect(store.getState()).toEqual(expectedStore);
282 });
283 });
284
285 it('Update Limit', () => {
286
az2497644017c2017-08-10 17:49:40 +0300287 const limitsList = LimitItemFactory.buildList(1);
Avi Ziv61070c92017-07-26 17:37:57 +0300288 deepFreeze(limitsList);
289 const entitlementPool = EntitlementPoolStoreFactory.build();
290 const store = storeCreator({
291 licenseModel: {
292 entitlementPool: {
293 entitlementPoolEditor: {
294 limitsList
295 }
296 }
297 }
298 });
299
300 deepFreeze(store.getState());
301
az2497644017c2017-08-10 17:49:40 +0300302
Avi Ziv61070c92017-07-26 17:37:57 +0300303 const previousData = limitsList[0];
az2497644017c2017-08-10 17:49:40 +0300304
Avi Ziv61070c92017-07-26 17:37:57 +0300305 deepFreeze(previousData);
306 const limitId = limitsList[0].id;
Avi Ziv61070c92017-07-26 17:37:57 +0300307
az2497644017c2017-08-10 17:49:40 +0300308 let updatedLimit = {...previousData, name: 'updatedLimit'};
309
310 const updatedLimitForPut = {...updatedLimit, id: undefined};
311 updatedLimit.metric = {choice: updatedLimit.metric, other: ''};
312 updatedLimit.unit = {choice: updatedLimit.unit, other: ''};
313 deepFreeze(updatedLimit);
314
315 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [updatedLimitForPut]);
Avi Ziv61070c92017-07-26 17:37:57 +0300316
317
318 mockRest.addHandler('put', ({data, options, baseUrl}) => {
319 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits/${limitId}`);
320 expect(data).toEqual(updatedLimitForPut);
321 expect(options).toEqual(undefined);
322 return {returnCode: 'OK'};
323 });
324
325 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
326 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
327 expect(data).toEqual(undefined);
328 expect(options).toEqual(undefined);
az2497644017c2017-08-10 17:49:40 +0300329 return {results: [updatedLimitForPut]};
Avi Ziv61070c92017-07-26 17:37:57 +0300330 });
331
332 return EntitlementPoolsActionHelper.submitLimit(store.dispatch,
333 {
334 licenseModelId: LICENSE_MODEL_ID,
az2497644017c2017-08-10 17:49:40 +0300335 version,
Avi Ziv61070c92017-07-26 17:37:57 +0300336 entitlementPool,
337 limit: updatedLimit
338 }
339 ).then(() => {
340 expect(store.getState()).toEqual(expectedStore);
341 });
342 });
343
Michael Landoefa037d2017-02-19 12:57:33 +0200344});