blob: 739e266d7fbf11c13b36ae7774bacf23626b5108 [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';
AviZi280f8012017-06-09 02:39:56 +030020import {LicenseKeyGroupStoreFactory, LicenseKeyGroupPostFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js';
Michael Landoefa037d2017-02-19 12:57:33 +020021
22import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
AviZi280f8012017-06-09 02:39:56 +030023import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
Avi Ziv61070c92017-07-26 17:37:57 +030024import {LimitItemFactory, LimitPostFactory} from 'test-utils/factories/licenseModel/LimitFactories.js';
az2497644017c2017-08-10 17:49:40 +030025import {getStrValue} from 'nfvo-utils/getValue.js';
Michael Landoefa037d2017-02-19 12:57:33 +020026
27describe('License Key Groups Module Tests', function () {
28
29 const LICENSE_MODEL_ID = '555';
AviZi280f8012017-06-09 02:39:56 +030030 const version = VersionControllerUtilsFactory.build().version;
31
Michael Landoefa037d2017-02-19 12:57:33 +020032 it('Load License Key Group', () => {
AviZi280f8012017-06-09 02:39:56 +030033
34 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory);
35
Michael Landoefa037d2017-02-19 12:57:33 +020036 deepFreeze(licenseKeyGroupsList);
37 const store = storeCreator();
38 deepFreeze(store.getState());
39
40 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList);
41
42 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030043 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
44 expect(data).toEqual(undefined);
45 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020046 return {results: licenseKeyGroupsList};
47 });
48
AviZi280f8012017-06-09 02:39:56 +030049 return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
50 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020051 });
52 });
53
54 it('Delete License Key Group', () => {
AviZi280f8012017-06-09 02:39:56 +030055
56 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
57
Michael Landoefa037d2017-02-19 12:57:33 +020058 deepFreeze(licenseKeyGroupsList);
59 const store = storeCreator({
60 licenseModel: {
61 licenseKeyGroup: {
62 licenseKeyGroupsList
63 }
64 }
65 });
66 deepFreeze(store.getState());
AviZi280f8012017-06-09 02:39:56 +030067 const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
Michael Landoefa037d2017-02-19 12:57:33 +020068 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []);
69
70 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030071 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeDeletedLicenseKeyGroupId}`);
72 expect(data).toEqual(undefined);
73 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020074 });
75
76 return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, {
77 licenseKeyGroupId: toBeDeletedLicenseKeyGroupId,
AviZi280f8012017-06-09 02:39:56 +030078 licenseModelId: LICENSE_MODEL_ID,
79 version
Michael Landoefa037d2017-02-19 12:57:33 +020080 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +030081 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020082 });
83 });
84
85 it('Add License Key Group', () => {
86
87 const store = storeCreator();
88 deepFreeze(store.getState());
89
AviZi280f8012017-06-09 02:39:56 +030090 const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build();
91 deepFreeze(LicenseKeyGroupPost);
Michael Landoefa037d2017-02-19 12:57:33 +020092
AviZi280f8012017-06-09 02:39:56 +030093 const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build();
94 deepFreeze(LicenseKeyGroupStore);
Michael Landoefa037d2017-02-19 12:57:33 +020095
AviZi280f8012017-06-09 02:39:56 +030096 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [LicenseKeyGroupStore]);
Michael Landoefa037d2017-02-19 12:57:33 +020097
AviZi280f8012017-06-09 02:39:56 +030098 mockRest.addHandler('post', ({options, data, baseUrl}) => {
99 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
100 expect(data).toEqual(LicenseKeyGroupPost);
101 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200102 return {
AviZi280f8012017-06-09 02:39:56 +0300103 value: LicenseKeyGroupStore.id
Michael Landoefa037d2017-02-19 12:57:33 +0200104 };
105 });
106
107 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
AviZi280f8012017-06-09 02:39:56 +0300108 licenseKeyGroup: LicenseKeyGroupPost,
109 licenseModelId: LICENSE_MODEL_ID,
110 version
Michael Landoefa037d2017-02-19 12:57:33 +0200111 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300112 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200113 });
114 });
115
116 it('Update License Key Group', () => {
AviZi280f8012017-06-09 02:39:56 +0300117 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
Michael Landoefa037d2017-02-19 12:57:33 +0200118 deepFreeze(licenseKeyGroupsList);
119 const store = storeCreator({
120 licenseModel: {
121 licenseKeyGroup: {
122 licenseKeyGroupsList
123 }
124 }
125 });
126
127 const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
128 const previousLicenseKeyGroupData = licenseKeyGroupsList[0];
129
AviZi280f8012017-06-09 02:39:56 +0300130 const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200131 name: 'lsk1_UPDATE',
132 description: 'string_UPDATE',
AviZi280f8012017-06-09 02:39:56 +0300133 id: toBeUpdatedLicenseKeyGroupId
134 });
135 deepFreeze(licenseKeyGroupUpdatedData);
Michael Landoefa037d2017-02-19 12:57:33 +0200136
AviZi280f8012017-06-09 02:39:56 +0300137 const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200138 name: 'lsk1_UPDATE',
AviZi280f8012017-06-09 02:39:56 +0300139 description: 'string_UPDATE'
140 });
141
Michael Landoefa037d2017-02-19 12:57:33 +0200142 deepFreeze(licenseKeyGroupPutRequest);
143
AviZi280f8012017-06-09 02:39:56 +0300144 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]);
Michael Landoefa037d2017-02-19 12:57:33 +0200145
AviZi280f8012017-06-09 02:39:56 +0300146 mockRest.addHandler('put', ({data, options, baseUrl}) => {
147 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`);
148 expect(data).toEqual(licenseKeyGroupPutRequest);
149 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200150 });
151
152 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
153 previousLicenseKeyGroup: previousLicenseKeyGroupData,
AviZi280f8012017-06-09 02:39:56 +0300154 licenseKeyGroup: licenseKeyGroupUpdatedData,
155 licenseModelId: LICENSE_MODEL_ID,
156 version
Michael Landoefa037d2017-02-19 12:57:33 +0200157 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300158 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200159 });
160 });
161
Avi Ziv61070c92017-07-26 17:37:57 +0300162 it('Load Limits List', () => {
163
az2497644017c2017-08-10 17:49:40 +0300164 const limitsList = LimitItemFactory.buildList(3);
Avi Ziv61070c92017-07-26 17:37:57 +0300165 deepFreeze(limitsList);
166 const store = storeCreator();
167 deepFreeze(store.getState());
168
169 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', limitsList);
170 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
171 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
172 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
173 expect(data).toEqual(undefined);
174 expect(options).toEqual(undefined);
175 return {results: limitsList};
176 });
177
178 return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, licenseKeyGroup}).then(() => {
179 expect(store.getState()).toEqual(expectedStore);
180 });
181 });
182
183 it('Add Limit', () => {
184
185 const store = storeCreator();
186 deepFreeze(store.getState());
187
188 const limitToAdd = LimitPostFactory.build();
az2497644017c2017-08-10 17:49:40 +0300189 let limitFromBE = {...limitToAdd};
190 limitFromBE.metric = getStrValue(limitFromBE.metric);
191 limitFromBE.unit = getStrValue(limitFromBE.unit);
Avi Ziv61070c92017-07-26 17:37:57 +0300192
193 deepFreeze(limitToAdd);
az2497644017c2017-08-10 17:49:40 +0300194 deepFreeze(limitFromBE);
Avi Ziv61070c92017-07-26 17:37:57 +0300195
196 const LimitIdFromResponse = 'ADDED_ID';
197 const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse};
198 deepFreeze(limitAddedItem);
199 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
200
201 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.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}/license-key-groups/${licenseKeyGroup.id}/limits`);
az2497644017c2017-08-10 17:49:40 +0300205 expect(data).toEqual(limitFromBE);
Avi Ziv61070c92017-07-26 17:37:57 +0300206 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}/license-key-groups/${licenseKeyGroup.id}/limits`);
215 expect(data).toEqual(undefined);
216 expect(options).toEqual(undefined);
217 return {results: [limitAddedItem]};
218 });
219
220 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch,
221 {
222 licenseModelId: LICENSE_MODEL_ID,
az2497644017c2017-08-10 17:49:40 +0300223 version,
Avi Ziv61070c92017-07-26 17:37:57 +0300224 licenseKeyGroup,
225 limit: limitToAdd
226 }
227 ).then(() => {
228 expect(store.getState()).toEqual(expectedStore);
229 });
230 });
231
232 it('Delete Limit', () => {
233
az2497644017c2017-08-10 17:49:40 +0300234 const limitsList = LimitItemFactory.buildList(1);
Avi Ziv61070c92017-07-26 17:37:57 +0300235 deepFreeze(limitsList);
az2497644017c2017-08-10 17:49:40 +0300236
Avi Ziv61070c92017-07-26 17:37:57 +0300237 const store = storeCreator({
238 licenseModel: {
239 entitlementPool: {
240 entitlementPoolEditor: {
241 limitsList
242 }
243 }
244 }
245 });
246 deepFreeze(store.getState());
247
248 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
249 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', []);
250
251 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
252 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitsList[0].id}`);
253 expect(data).toEqual(undefined);
254 expect(options).toEqual(undefined);
255 return {
256 results: {
257 returnCode: 'OK'
258 }
259 };
260 });
261
262 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
263 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
264 expect(data).toEqual(undefined);
265 expect(options).toEqual(undefined);
266 return {results: []};
267 });
268
269 return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, {
270 licenseModelId: LICENSE_MODEL_ID,
271 version,
272 licenseKeyGroup,
273 limit: limitsList[0]
274 }).then(() => {
275 expect(store.getState()).toEqual(expectedStore);
276 });
277 });
278
279 it('Update Limit', () => {
280
az2497644017c2017-08-10 17:49:40 +0300281 const limitsList = LimitItemFactory.buildList(1);
Avi Ziv61070c92017-07-26 17:37:57 +0300282 deepFreeze(limitsList);
283 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
284 const store = storeCreator({
285 licenseModel: {
286 licenseKeyGroup: {
287 licenseKeyGroupsEditor: {
288 limitsList
289 }
290 }
291 }
292 });
293
294 deepFreeze(store.getState());
295
az2497644017c2017-08-10 17:49:40 +0300296
Avi Ziv61070c92017-07-26 17:37:57 +0300297 const previousData = limitsList[0];
298 deepFreeze(previousData);
299 const limitId = limitsList[0].id;
Avi Ziv61070c92017-07-26 17:37:57 +0300300
az2497644017c2017-08-10 17:49:40 +0300301 let updatedLimit = {...previousData, name: 'updatedLimit'};
302 const updatedLimitForPut = {...updatedLimit, id: undefined};
303 updatedLimit.metric = {choice: updatedLimit.metric, other: ''};
304 updatedLimit.unit = {choice: updatedLimit.unit, other: ''};
305 deepFreeze(updatedLimit);
306
307 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [updatedLimitForPut]);
Avi Ziv61070c92017-07-26 17:37:57 +0300308
309
310 mockRest.addHandler('put', ({data, options, baseUrl}) => {
311 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}`);
312 expect(data).toEqual(updatedLimitForPut);
313 expect(options).toEqual(undefined);
314 return {returnCode: 'OK'};
315 });
316
317 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
318 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
319 expect(data).toEqual(undefined);
320 expect(options).toEqual(undefined);
az2497644017c2017-08-10 17:49:40 +0300321 return {results: [updatedLimitForPut]};
Avi Ziv61070c92017-07-26 17:37:57 +0300322 });
323
324 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch,
325 {
326 licenseModelId: LICENSE_MODEL_ID,
az2497644017c2017-08-10 17:49:40 +0300327 version,
Avi Ziv61070c92017-07-26 17:37:57 +0300328 licenseKeyGroup,
329 limit: updatedLimit
330 }
331 ).then(() => {
332 expect(store.getState()).toEqual(expectedStore);
333 });
334 });
335
Michael Landoefa037d2017-02-19 12:57:33 +0200336});