blob: 911fb011f43f8766465937ab45ddd5a248920c8d [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';
Michael Landoefa037d2017-02-19 12:57:33 +020024
25describe('Entitlement Pools 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 Entitlement Pools List', () => {
AviZi280f8012017-06-09 02:39:56 +030031
32 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory);
Michael Landoefa037d2017-02-19 12:57:33 +020033 deepFreeze(entitlementPoolsList);
34 const store = storeCreator();
35 deepFreeze(store.getState());
36
37 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', entitlementPoolsList);
38
39 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030040 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
41 expect(data).toEqual(undefined);
42 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020043 return {results: entitlementPoolsList};
44 });
45
AviZi280f8012017-06-09 02:39:56 +030046 return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
47 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020048 });
49 });
50
51 it('Delete Entitlement Pool', () => {
Michael Landoefa037d2017-02-19 12:57:33 +020052
AviZi280f8012017-06-09 02:39:56 +030053 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory,1);
Michael Landoefa037d2017-02-19 12:57:33 +020054 deepFreeze(entitlementPoolsList);
55 const store = storeCreator({
56 licenseModel: {
57 entitlementPool: {
58 entitlementPoolsList
59 }
60 }
61 });
62 deepFreeze(store.getState());
63
64 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', []);
65
66 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030067 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPoolsList[0].id}`);
68 expect(data).toEqual(undefined);
69 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020070 return {
71 results: {
72 returnCode: 'OK'
73 }
74 };
75 });
76
77 return EntitlementPoolsActionHelper.deleteEntitlementPool(store.dispatch, {
78 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +030079 version,
Michael Landoefa037d2017-02-19 12:57:33 +020080 entitlementPoolId: entitlementPoolsList[0].id
81 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +030082 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020083 });
84 });
85
86 it('Add Entitlement Pool', () => {
87
88 const store = storeCreator();
89 deepFreeze(store.getState());
90
AviZi280f8012017-06-09 02:39:56 +030091 const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build();
92
93 deepFreeze(EntitlementPoolPostRequest);
94
Michael Landoefa037d2017-02-19 12:57:33 +020095 const entitlementPoolIdFromResponse = 'ADDED_ID';
AviZi280f8012017-06-09 02:39:56 +030096 const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({id: entitlementPoolIdFromResponse});
97 deepFreeze(entitlementPoolAfterAdd);
Michael Landoefa037d2017-02-19 12:57:33 +020098
99 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolAfterAdd]);
100
AviZi280f8012017-06-09 02:39:56 +0300101 mockRest.addHandler('post', ({data, options, baseUrl}) => {
102 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
103 expect(data).toEqual(EntitlementPoolPostRequest);
104 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200105 return {
106 returnCode: 'OK',
107 value: entitlementPoolIdFromResponse
108 };
109 });
110
111 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch,
112 {
113 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300114 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200115 previousEntitlementPool: null,
AviZi280f8012017-06-09 02:39:56 +0300116 entitlementPool: EntitlementPoolPostRequest
Michael Landoefa037d2017-02-19 12:57:33 +0200117 }
118 ).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300119 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200120 });
121 });
122
123 it('Update Entitlement Pool', () => {
AviZi280f8012017-06-09 02:39:56 +0300124
125 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory, 1);
Michael Landoefa037d2017-02-19 12:57:33 +0200126 deepFreeze(entitlementPoolsList);
127
128 const store = storeCreator({
129 licenseModel: {
130 entitlementPool: {
131 entitlementPoolsList
132 }
133 }
134 });
AviZi280f8012017-06-09 02:39:56 +0300135
Michael Landoefa037d2017-02-19 12:57:33 +0200136 deepFreeze(store.getState());
137
138 const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id;
139 const previousEntitlementPoolData = entitlementPoolsList[0];
AviZi280f8012017-06-09 02:39:56 +0300140 const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED', id: toBeUpdatedEntitlementPoolId});
Michael Landoefa037d2017-02-19 12:57:33 +0200141 deepFreeze(entitlementPoolUpdateData);
142
AviZi280f8012017-06-09 02:39:56 +0300143 const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED'});
Michael Landoefa037d2017-02-19 12:57:33 +0200144 deepFreeze(entitlementPoolPutRequest);
145
146 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]);
147
148
AviZi280f8012017-06-09 02:39:56 +0300149 mockRest.addHandler('put', ({data, options, baseUrl}) => {
150 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${toBeUpdatedEntitlementPoolId}`);
151 expect(data).toEqual(entitlementPoolPutRequest);
152 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200153 return {returnCode: 'OK'};
154 });
155
156 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, {
157 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300158 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200159 previousEntitlementPool: previousEntitlementPoolData,
160 entitlementPool: entitlementPoolUpdateData
161 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300162 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200163 });
164 });
165
Avi Ziv61070c92017-07-26 17:37:57 +0300166 it('Load Limits List', () => {
167
168 const limitsList = LimitItemFactory.buildList(3);
169 deepFreeze(limitsList);
170 const store = storeCreator();
171 deepFreeze(store.getState());
172
173 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', limitsList);
174 const entitlementPool = EntitlementPoolStoreFactory.build();
175 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
176 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
177 expect(data).toEqual(undefined);
178 expect(options).toEqual(undefined);
179 return {results: limitsList};
180 });
181
182 return EntitlementPoolsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, entitlementPool}).then(() => {
183 expect(store.getState()).toEqual(expectedStore);
184 });
185 });
186
187 it('Add Limit', () => {
188
189 const store = storeCreator();
190 deepFreeze(store.getState());
191
192 const limitToAdd = LimitPostFactory.build();
193
194 deepFreeze(limitToAdd);
195
196 const LimitIdFromResponse = 'ADDED_ID';
197 const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse};
198 deepFreeze(limitAddedItem);
199 const entitlementPool = EntitlementPoolStoreFactory.build();
200
201 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [limitAddedItem]);
202
203 mockRest.addHandler('post', ({data, options, baseUrl}) => {
204 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
205 expect(data).toEqual(limitToAdd);
206 expect(options).toEqual(undefined);
207 return {
208 returnCode: 'OK',
209 value: LimitIdFromResponse
210 };
211 });
212
213 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
214 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
215 expect(data).toEqual(undefined);
216 expect(options).toEqual(undefined);
217 return {results: [limitAddedItem]};
218 });
219
220 return EntitlementPoolsActionHelper.submitLimit(store.dispatch,
221 {
222 licenseModelId: LICENSE_MODEL_ID,
223 version,
224 entitlementPool,
225 limit: limitToAdd
226 }
227 ).then(() => {
228 expect(store.getState()).toEqual(expectedStore);
229 });
230 });
231
232
233 it('Delete Limit', () => {
234
235 const limitsList = LimitItemFactory.buildList(1);
236 deepFreeze(limitsList);
237
238 const store = storeCreator({
239 licenseModel: {
240 entitlementPool: {
241 entitlementPoolEditor: {
242 limitsList
243 }
244 }
245 }
246 });
247 deepFreeze(store.getState());
248
249 const entitlementPool = EntitlementPoolStoreFactory.build();
250 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', []);
251
252 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
253 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits/${limitsList[0].id}`);
254 expect(data).toEqual(undefined);
255 expect(options).toEqual(undefined);
256 return {
257 results: {
258 returnCode: 'OK'
259 }
260 };
261 });
262
263 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
264 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
265 expect(data).toEqual(undefined);
266 expect(options).toEqual(undefined);
267 return {results: []};
268 });
269
270 return EntitlementPoolsActionHelper.deleteLimit(store.dispatch, {
271 licenseModelId: LICENSE_MODEL_ID,
272 version,
273 entitlementPool,
274 limit: limitsList[0]
275 }).then(() => {
276 expect(store.getState()).toEqual(expectedStore);
277 });
278 });
279
280 it('Update Limit', () => {
281
282 const limitsList = LimitItemFactory.buildList(1);
283 deepFreeze(limitsList);
284 const entitlementPool = EntitlementPoolStoreFactory.build();
285 const store = storeCreator({
286 licenseModel: {
287 entitlementPool: {
288 entitlementPoolEditor: {
289 limitsList
290 }
291 }
292 }
293 });
294
295 deepFreeze(store.getState());
296
297
298 const previousData = limitsList[0];
299 deepFreeze(previousData);
300 const limitId = limitsList[0].id;
301
302 const updatedLimit = {...previousData, name: 'updatedLimit'};
303 deepFreeze(updatedLimit);
304 const updatedLimitForPut = {...updatedLimit, id: undefined};
305
306 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolEditor.limitsList', [updatedLimit]);
307
308
309 mockRest.addHandler('put', ({data, options, baseUrl}) => {
310 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits/${limitId}`);
311 expect(data).toEqual(updatedLimitForPut);
312 expect(options).toEqual(undefined);
313 return {returnCode: 'OK'};
314 });
315
316 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
317 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPool.id}/limits`);
318 expect(data).toEqual(undefined);
319 expect(options).toEqual(undefined);
320 return {results: [updatedLimit]};
321 });
322
323 return EntitlementPoolsActionHelper.submitLimit(store.dispatch,
324 {
325 licenseModelId: LICENSE_MODEL_ID,
326 version,
327 entitlementPool,
328 limit: updatedLimit
329 }
330 ).then(() => {
331 expect(store.getState()).toEqual(expectedStore);
332 });
333 });
334
Michael Landoefa037d2017-02-19 12:57:33 +0200335});