blob: 77fcc006945adcaf2fcbcf3ff35535c3eb8a8b90 [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';
Michael Landoefa037d2017-02-19 12:57:33 +020025
26describe('License Key Groups Module Tests', function () {
27
28 const LICENSE_MODEL_ID = '555';
AviZi280f8012017-06-09 02:39:56 +030029 const version = VersionControllerUtilsFactory.build().version;
30
Michael Landoefa037d2017-02-19 12:57:33 +020031 it('Load License Key Group', () => {
AviZi280f8012017-06-09 02:39:56 +030032
33 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory);
34
Michael Landoefa037d2017-02-19 12:57:33 +020035 deepFreeze(licenseKeyGroupsList);
36 const store = storeCreator();
37 deepFreeze(store.getState());
38
39 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList);
40
41 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030042 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
43 expect(data).toEqual(undefined);
44 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020045 return {results: licenseKeyGroupsList};
46 });
47
AviZi280f8012017-06-09 02:39:56 +030048 return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
49 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020050 });
51 });
52
53 it('Delete License Key Group', () => {
AviZi280f8012017-06-09 02:39:56 +030054
55 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
56
Michael Landoefa037d2017-02-19 12:57:33 +020057 deepFreeze(licenseKeyGroupsList);
58 const store = storeCreator({
59 licenseModel: {
60 licenseKeyGroup: {
61 licenseKeyGroupsList
62 }
63 }
64 });
65 deepFreeze(store.getState());
AviZi280f8012017-06-09 02:39:56 +030066 const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
Michael Landoefa037d2017-02-19 12:57:33 +020067 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []);
68
69 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030070 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeDeletedLicenseKeyGroupId}`);
71 expect(data).toEqual(undefined);
72 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020073 });
74
75 return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, {
76 licenseKeyGroupId: toBeDeletedLicenseKeyGroupId,
AviZi280f8012017-06-09 02:39:56 +030077 licenseModelId: LICENSE_MODEL_ID,
78 version
Michael Landoefa037d2017-02-19 12:57:33 +020079 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +030080 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020081 });
82 });
83
84 it('Add License Key Group', () => {
85
86 const store = storeCreator();
87 deepFreeze(store.getState());
88
AviZi280f8012017-06-09 02:39:56 +030089 const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build();
90 deepFreeze(LicenseKeyGroupPost);
Michael Landoefa037d2017-02-19 12:57:33 +020091
AviZi280f8012017-06-09 02:39:56 +030092 const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build();
93 deepFreeze(LicenseKeyGroupStore);
Michael Landoefa037d2017-02-19 12:57:33 +020094
AviZi280f8012017-06-09 02:39:56 +030095 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [LicenseKeyGroupStore]);
Michael Landoefa037d2017-02-19 12:57:33 +020096
AviZi280f8012017-06-09 02:39:56 +030097 mockRest.addHandler('post', ({options, data, baseUrl}) => {
98 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
99 expect(data).toEqual(LicenseKeyGroupPost);
100 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200101 return {
AviZi280f8012017-06-09 02:39:56 +0300102 value: LicenseKeyGroupStore.id
Michael Landoefa037d2017-02-19 12:57:33 +0200103 };
104 });
105
106 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
AviZi280f8012017-06-09 02:39:56 +0300107 licenseKeyGroup: LicenseKeyGroupPost,
108 licenseModelId: LICENSE_MODEL_ID,
109 version
Michael Landoefa037d2017-02-19 12:57:33 +0200110 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300111 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200112 });
113 });
114
115 it('Update License Key Group', () => {
AviZi280f8012017-06-09 02:39:56 +0300116 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
Michael Landoefa037d2017-02-19 12:57:33 +0200117 deepFreeze(licenseKeyGroupsList);
118 const store = storeCreator({
119 licenseModel: {
120 licenseKeyGroup: {
121 licenseKeyGroupsList
122 }
123 }
124 });
125
126 const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
127 const previousLicenseKeyGroupData = licenseKeyGroupsList[0];
128
AviZi280f8012017-06-09 02:39:56 +0300129 const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200130 name: 'lsk1_UPDATE',
131 description: 'string_UPDATE',
AviZi280f8012017-06-09 02:39:56 +0300132 id: toBeUpdatedLicenseKeyGroupId
133 });
134 deepFreeze(licenseKeyGroupUpdatedData);
Michael Landoefa037d2017-02-19 12:57:33 +0200135
AviZi280f8012017-06-09 02:39:56 +0300136 const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200137 name: 'lsk1_UPDATE',
AviZi280f8012017-06-09 02:39:56 +0300138 description: 'string_UPDATE'
139 });
140
Michael Landoefa037d2017-02-19 12:57:33 +0200141 deepFreeze(licenseKeyGroupPutRequest);
142
AviZi280f8012017-06-09 02:39:56 +0300143 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]);
Michael Landoefa037d2017-02-19 12:57:33 +0200144
AviZi280f8012017-06-09 02:39:56 +0300145 mockRest.addHandler('put', ({data, options, baseUrl}) => {
146 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`);
147 expect(data).toEqual(licenseKeyGroupPutRequest);
148 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200149 });
150
151 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
152 previousLicenseKeyGroup: previousLicenseKeyGroupData,
AviZi280f8012017-06-09 02:39:56 +0300153 licenseKeyGroup: licenseKeyGroupUpdatedData,
154 licenseModelId: LICENSE_MODEL_ID,
155 version
Michael Landoefa037d2017-02-19 12:57:33 +0200156 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300157 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200158 });
159 });
160
Avi Ziv61070c92017-07-26 17:37:57 +0300161 it('Load Limits List', () => {
162
163 const limitsList = LimitItemFactory.buildList(3);
164 deepFreeze(limitsList);
165 const store = storeCreator();
166 deepFreeze(store.getState());
167
168 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', limitsList);
169 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
170 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
171 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
172 expect(data).toEqual(undefined);
173 expect(options).toEqual(undefined);
174 return {results: limitsList};
175 });
176
177 return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, licenseKeyGroup}).then(() => {
178 expect(store.getState()).toEqual(expectedStore);
179 });
180 });
181
182 it('Add Limit', () => {
183
184 const store = storeCreator();
185 deepFreeze(store.getState());
186
187 const limitToAdd = LimitPostFactory.build();
188
189 deepFreeze(limitToAdd);
190
191 const LimitIdFromResponse = 'ADDED_ID';
192 const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse};
193 deepFreeze(limitAddedItem);
194 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
195
196 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [limitAddedItem]);
197
198 mockRest.addHandler('post', ({data, options, baseUrl}) => {
199 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
200 expect(data).toEqual(limitToAdd);
201 expect(options).toEqual(undefined);
202 return {
203 returnCode: 'OK',
204 value: LimitIdFromResponse
205 };
206 });
207
208 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
209 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
210 expect(data).toEqual(undefined);
211 expect(options).toEqual(undefined);
212 return {results: [limitAddedItem]};
213 });
214
215 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch,
216 {
217 licenseModelId: LICENSE_MODEL_ID,
218 version,
219 licenseKeyGroup,
220 limit: limitToAdd
221 }
222 ).then(() => {
223 expect(store.getState()).toEqual(expectedStore);
224 });
225 });
226
227 it('Delete Limit', () => {
228
229 const limitsList = LimitItemFactory.buildList(1);
230 deepFreeze(limitsList);
231
232 const store = storeCreator({
233 licenseModel: {
234 entitlementPool: {
235 entitlementPoolEditor: {
236 limitsList
237 }
238 }
239 }
240 });
241 deepFreeze(store.getState());
242
243 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
244 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', []);
245
246 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
247 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}`);
248 expect(data).toEqual(undefined);
249 expect(options).toEqual(undefined);
250 return {
251 results: {
252 returnCode: 'OK'
253 }
254 };
255 });
256
257 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
258 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`);
259 expect(data).toEqual(undefined);
260 expect(options).toEqual(undefined);
261 return {results: []};
262 });
263
264 return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, {
265 licenseModelId: LICENSE_MODEL_ID,
266 version,
267 licenseKeyGroup,
268 limit: limitsList[0]
269 }).then(() => {
270 expect(store.getState()).toEqual(expectedStore);
271 });
272 });
273
274 it('Update Limit', () => {
275
276 const limitsList = LimitItemFactory.buildList(1);
277 deepFreeze(limitsList);
278 const licenseKeyGroup = LicenseKeyGroupStoreFactory.build();
279 const store = storeCreator({
280 licenseModel: {
281 licenseKeyGroup: {
282 licenseKeyGroupsEditor: {
283 limitsList
284 }
285 }
286 }
287 });
288
289 deepFreeze(store.getState());
290
291
292 const previousData = limitsList[0];
293 deepFreeze(previousData);
294 const limitId = limitsList[0].id;
295
296 const updatedLimit = {...previousData, name: 'updatedLimit'};
297 deepFreeze(updatedLimit);
298 const updatedLimitForPut = {...updatedLimit, id: undefined};
299
300 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [updatedLimit]);
301
302
303 mockRest.addHandler('put', ({data, options, baseUrl}) => {
304 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}`);
305 expect(data).toEqual(updatedLimitForPut);
306 expect(options).toEqual(undefined);
307 return {returnCode: 'OK'};
308 });
309
310 mockRest.addHandler('fetch', ({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`);
312 expect(data).toEqual(undefined);
313 expect(options).toEqual(undefined);
314 return {results: [updatedLimit]};
315 });
316
317 return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch,
318 {
319 licenseModelId: LICENSE_MODEL_ID,
320 version,
321 licenseKeyGroup,
322 limit: updatedLimit
323 }
324 ).then(() => {
325 expect(store.getState()).toEqual(expectedStore);
326 });
327 });
328
Michael Landoefa037d2017-02-19 12:57:33 +0200329});