blob: df84d184ce4733fdc5a4046820019c6f6f46fe81 [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, buildFromExistingObject} from 'test-utils/Util.js';
Michael Landoefa037d2017-02-19 12:57:33 +020019import {storeCreator} from 'sdc-app/AppStore.js';
20
21import SoftwareProductCreationActionHelper from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationActionHelper.js';
22import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
23import SoftwareProductCategoriesHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductCategoriesHelper.js';
AviZi280f8012017-06-09 02:39:56 +030024import {forms} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js';
25import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
26
27import {VSPEditorFactory, VSPEditorPostFactory, VSPEditorFactoryWithLicensingData, VSPEditorPostFactoryWithLicensingData} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';
28import {CategoryFactory} from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js';
29import {heatSetupManifest} from 'test-utils/factories/softwareProduct/SoftwareProductAttachmentsFactories.js';
30
31import { FeatureGroupStoreFactory as FeatureGroup} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
32import {LicenseAgreementStoreFactory as LicenseAgreement} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js';
33import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
34
Michael Landoefa037d2017-02-19 12:57:33 +020035
36describe('Software Product Module Tests', function () {
37 it('Get Software Products List', () => {
38 const store = storeCreator();
39 deepFreeze(store.getState());
AviZi280f8012017-06-09 02:39:56 +030040 const softwareProductList = VSPEditorFactory.buildList(2);
Michael Landoefa037d2017-02-19 12:57:33 +020041 deepFreeze(softwareProductList);
Michael Landoefa037d2017-02-19 12:57:33 +020042 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +020043 const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', softwareProductList);
44
45 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030046 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/');
47 expect(data).toEqual(undefined);
48 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020049 return {results: softwareProductList};
50 });
51
AviZi280f8012017-06-09 02:39:56 +030052 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
53 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/?versionFilter=Final');
54 expect(data).toEqual(undefined);
55 expect(options).toEqual(undefined);
56 return {results: []};
57 });
58
Michael Landoefa037d2017-02-19 12:57:33 +020059 return SoftwareProductActionHelper.fetchSoftwareProductList(store.dispatch).then(() => {
AviZi280f8012017-06-09 02:39:56 +030060 return SoftwareProductActionHelper.fetchFinalizedSoftwareProductList(store.dispatch);
61 }).then(() => {
62 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020063 });
64 });
65
66 it('Add Software Product', () => {
67 const store = storeCreator();
68 deepFreeze(store.getState());
69
AviZi280f8012017-06-09 02:39:56 +030070 const softwareProductPostRequest = VSPEditorPostFactory.build();
71 deepFreeze(softwareProductPostRequest);
72 const idFromResponse = '1';
73 const expectedVSP = VSPEditorPostFactory.build({id: idFromResponse, vendorId: softwareProductPostRequest.vendorId});
74 deepFreeze(expectedVSP);
Michael Landoefa037d2017-02-19 12:57:33 +020075
AviZi280f8012017-06-09 02:39:56 +030076 mockRest.addHandler('post', ({options, data, baseUrl}) => {
77 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/');
78 expect(data).toEqual(softwareProductPostRequest);
79 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020080 return {
AviZi280f8012017-06-09 02:39:56 +030081 vspId: idFromResponse
Michael Landoefa037d2017-02-19 12:57:33 +020082 };
83 });
84
85 return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, {
AviZi280f8012017-06-09 02:39:56 +030086 softwareProduct: softwareProductPostRequest
87 }).then((response) => {
88 expect(response.vspId).toEqual(idFromResponse);
Michael Landoefa037d2017-02-19 12:57:33 +020089 });
90 });
AviZi280f8012017-06-09 02:39:56 +030091
92 it('Fetch Software Product with manifest', () => {
93 const store = storeCreator();
94 deepFreeze(store.getState());
95
96 const softwareProductPostRequest = VSPEditorPostFactory.build();
97 deepFreeze(softwareProductPostRequest);
98
99 const expectedGenericInfo = {
100 'name': {
101 isValid: true,
102 errorText: '',
103 validations: [{type: 'validateName', data: true}, {type: 'maxLength', data: 25}, {
104 type: 'required',
105 data: true
106 }]
107 },
108 'description': {
109 isValid: true,
110 errorText: '',
111 validations: [{type: 'required', data: true}]
Michael Landoefa037d2017-02-19 12:57:33 +0200112 }
113 };
AviZi280f8012017-06-09 02:39:56 +0300114 const expectedFormName = forms.VENDOR_SOFTWARE_PRODUCT_DETAILS;
115
116 const idFromResponse = '1';
117 const version = { id: '0.1', label: '0.1'};
118 const expectedVSP = VSPEditorPostFactory.build({id: idFromResponse, vendorId: softwareProductPostRequest.vendorId});
119 deepFreeze(expectedVSP);
120 let expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductEditor.data', expectedVSP);
121 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.genericFieldInfo', expectedGenericInfo);
122 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.formName', expectedFormName);
123 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductQuestionnaire', {qdata: {}, dataMap: {}, qgenericFieldInfo: {}});
124
125 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductAttachments.heatValidation', {
126 'attachmentsTree': {},
127 'errorList': [],
128 'selectedNode': 'All'
129 });
130 let manifest = heatSetupManifest.build();
131 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductAttachments.heatSetup', manifest);
132
133 mockRest.addHandler('post', ({options, data, baseUrl}) => {
134 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/');
135 expect(data).toEqual(softwareProductPostRequest);
136 expect(options).toEqual(undefined);
137 return {
138 vspId: idFromResponse,
139 version
140 };
141 });
142
143 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
144 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}`);
145 expect(data).toEqual(undefined);
146 expect(options).toEqual(undefined);
147 return expectedVSP;
148 });
149
150 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
151 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}/questionnaire`);
152 expect(data).toEqual(undefined);
153 expect(options).toEqual(undefined);
154 return {data: JSON.stringify({}), schema: JSON.stringify({})};
155 });
156
157 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
158 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}/orchestration-template-candidate/manifest`);
159 expect(data).toEqual(undefined);
160 expect(options).toEqual(undefined);
161 return manifest;
162 });
163
164 return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, {
165 softwareProduct: softwareProductPostRequest
166 }).then(() => {
167 return SoftwareProductActionHelper.fetchSoftwareProduct(store.dispatch, {softwareProductId: idFromResponse, version});
168 }).then(() => {
169 return SoftwareProductActionHelper.loadSoftwareProductHeatCandidate(store.dispatch, {softwareProductId: idFromResponse, version});
170 }).then(() => {
171 expect(store.getState()).toEqual(expectedStore);
172 let newName = 'newName';
173 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.formReady', null);
174 ValidationHelper.dataChanged(store.dispatch, {deltaData: {'name': newName}, formName: forms.VENDOR_SOFTWARE_PRODUCT_DETAILS});
175 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.data.name', newName);
176 expect(store.getState()).toEqual(expectedStore);
177 });
178 });
179
180 it('Load and edit Software Product licensing data', () => {
181 const store = storeCreator();
182
183 const softwareProductPostRequest = VSPEditorPostFactory.build();
184 deepFreeze(softwareProductPostRequest);
185
186 const licenseModelId = softwareProductPostRequest.vendorId;
187 const LMVersion = VersionControllerUtilsFactory.build().version;
188 const secondLicenseModelId = 'secondLicenseModelId';
189
190 let FG1 = FeatureGroup.build();
191 let LA1 = LicenseAgreement.build({
192 featureGroupsIds: [FG1.id]
193 });
194
195 let FG2 = FeatureGroup.build();
196 let LA2 = LicenseAgreement.build({
197 featureGroupsIds: [FG2.id]
198 });
199
200 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
201 expect(baseUrl).toEqual('/sdc1/feProxy/rest/v1/categories/resources/');
202 expect(data).toEqual(undefined);
203 expect(options).toEqual(undefined);
204 return [];
205 });
206
207 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
208 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-license-models/?versionFilter=Final');
209 expect(data).toEqual(undefined);
210 expect(options).toEqual(undefined);
211 return {results: []};
212 });
213
214 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
215 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModelId}/versions/${LMVersion.id}/license-agreements`);
216 expect(data).toEqual(undefined);
217 expect(options).toEqual(undefined);
218 return {results: [LA1]};
219 });
220
221 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
222 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModelId}/versions/${LMVersion.id}/feature-groups`);
223 expect(data).toEqual(undefined);
224 expect(options).toEqual(undefined);
225 return {results: [FG1]};
226 });
227
228 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
229 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${secondLicenseModelId}/versions/${LMVersion.id}/license-agreements`);
230 expect(data).toEqual(undefined);
231 expect(options).toEqual(undefined);
232 return {results: [LA2]};
233 });
234
235 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
236 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${secondLicenseModelId}/versions/${LMVersion.id}/feature-groups`);
237 expect(data).toEqual(undefined);
238 expect(options).toEqual(undefined);
239 return {results: [FG2]};
240 });
241
242 return SoftwareProductActionHelper.loadSoftwareProductDetailsData(store.dispatch, {licenseModelId, licensingVersion: LMVersion}).then(() => {
243 let state = store.getState();
244 expect(state.licenseModel.licenseAgreement.licenseAgreementList).toEqual([LA1]);
245 expect(state.licenseModel.featureGroup.featureGroupsList).toEqual([FG1]);
246 return SoftwareProductActionHelper.softwareProductEditorVendorChanged(store.dispatch,
247 {deltaData: {vendorId: secondLicenseModelId, licensingVersion: LMVersion},
248 formName: forms.VENDOR_SOFTWARE_PRODUCT_DETAILS});
249 }).then(() => {
250 let state = store.getState();
251 expect(state.licenseModel.licenseAgreement.licenseAgreementList).toEqual([LA2]);
252 expect(state.licenseModel.featureGroup.featureGroupsList).toEqual([FG2]);
253 });
254 });
255
256 it('Save Software product', () => {
257
258 const softwareProduct = VSPEditorFactoryWithLicensingData.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200259 deepFreeze(softwareProduct);
260
261 const store = storeCreator({
262 softwareProduct: {
263 softwareProductEditor: {data: softwareProduct},
264 softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
265 }
266 });
267 deepFreeze(store.getState());
268
AviZi280f8012017-06-09 02:39:56 +0300269 const dataForUpdate = {
Michael Landoefa037d2017-02-19 12:57:33 +0200270 name: 'VSP5_UPDATED',
271 description: 'A software model for Fortigate._UPDATED'
272 };
AviZi280f8012017-06-09 02:39:56 +0300273
274 const toBeUpdatedSoftwareProductId = softwareProduct.id;
275 let softwareProductUpdateData = VSPEditorPostFactoryWithLicensingData.build(dataForUpdate);
276 delete softwareProductUpdateData.version;
277
278 const softwareProductPutRequest = buildFromExistingObject(VSPEditorFactoryWithLicensingData, softwareProductUpdateData, {id: toBeUpdatedSoftwareProductId, version: softwareProduct.version});
279
Michael Landoefa037d2017-02-19 12:57:33 +0200280 deepFreeze(softwareProductUpdateData);
281
AviZi280f8012017-06-09 02:39:56 +0300282 const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', [softwareProductPutRequest]);
Michael Landoefa037d2017-02-19 12:57:33 +0200283 const questionnaireData = {
284 general: {
285 affinityData: {
286 affinityGrouping: true,
287 antiAffinityGrouping: false
288 }
289 }
290 };
291 deepFreeze(questionnaireData);
292
AviZi280f8012017-06-09 02:39:56 +0300293 mockRest.addHandler('put', ({data, options, baseUrl}) => {
294 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${softwareProduct.version.id}`);
295 expect(data).toEqual(softwareProductUpdateData);
296 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200297 return {returnCode: 'OK'};
298 });
AviZi280f8012017-06-09 02:39:56 +0300299 mockRest.addHandler('put', ({data, options, baseUrl}) => {
300 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${softwareProduct.version.id}/questionnaire`);
301 expect(data).toEqual(questionnaireData);
302 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200303 return {returnCode: 'OK'};
304 });
305
306 return SoftwareProductActionHelper.updateSoftwareProduct(store.dispatch, {
AviZi280f8012017-06-09 02:39:56 +0300307 softwareProduct: softwareProductPutRequest,
Michael Landoefa037d2017-02-19 12:57:33 +0200308 qdata: questionnaireData
309 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300310 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200311 });
312 });
AviZi280f8012017-06-09 02:39:56 +0300313
Michael Landoefa037d2017-02-19 12:57:33 +0200314 it('Save Software product data only', () => {
AviZi280f8012017-06-09 02:39:56 +0300315
316 const softwareProduct = VSPEditorFactoryWithLicensingData.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200317 deepFreeze(softwareProduct);
318
319 const store = storeCreator({
320 softwareProduct: {
321 softwareProductEditor: {data: softwareProduct},
322 softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
323 }
324 });
325 deepFreeze(store.getState());
326 const expectedStore = store.getState();
327
AviZi280f8012017-06-09 02:39:56 +0300328 const dataForUpdate = {
Michael Landoefa037d2017-02-19 12:57:33 +0200329 name: 'VSP5_UPDATED',
330 description: 'A software model for Fortigate._UPDATED'
331 };
AviZi280f8012017-06-09 02:39:56 +0300332
333 const toBeUpdatedSoftwareProductId = softwareProduct.id;
334 let softwareProductUpdateData = VSPEditorPostFactoryWithLicensingData.build(dataForUpdate);
335 delete softwareProductUpdateData.version;
336
337 const softwareProductPutRequest = buildFromExistingObject(VSPEditorFactoryWithLicensingData, softwareProductUpdateData, {id: toBeUpdatedSoftwareProductId, version: softwareProduct.version});
338
Michael Landoefa037d2017-02-19 12:57:33 +0200339 deepFreeze(softwareProductUpdateData);
340
AviZi280f8012017-06-09 02:39:56 +0300341 mockRest.addHandler('put', ({data, options, baseUrl}) => {
342 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${softwareProduct.version.id}`);
343 expect(data).toEqual(softwareProductUpdateData);
344 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200345 return {returnCode: 'OK'};
346 });
347
348 return SoftwareProductActionHelper.updateSoftwareProductData(store.dispatch, {
AviZi280f8012017-06-09 02:39:56 +0300349 softwareProduct: softwareProductPutRequest
Michael Landoefa037d2017-02-19 12:57:33 +0200350 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300351 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200352 });
353 });
354
355 it('Save Software product questionnaire only', () => {
AviZi280f8012017-06-09 02:39:56 +0300356 const softwareProduct = VSPEditorFactoryWithLicensingData.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200357 deepFreeze(softwareProduct);
358
359 const store = storeCreator({
360 softwareProduct: {
361 softwareProductEditor: {data: softwareProduct},
362 softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
363 }
364 });
365 deepFreeze(store.getState());
366 const expectedStore = store.getState();
367
368 const toBeUpdatedSoftwareProductId = softwareProduct.id;
369 const questionnaireData = {
370 general: {
371 affinityData: {
372 affinityGrouping: true,
373 antiAffinityGrouping: false
374 }
375 }
376 };
377 deepFreeze(questionnaireData);
378
AviZi280f8012017-06-09 02:39:56 +0300379 mockRest.addHandler('put', ({data, options, baseUrl}) => {
380 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${softwareProduct.version.id}/questionnaire`);
381 expect(data).toEqual(questionnaireData);
382 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200383 return {returnCode: 'OK'};
384 });
385
386 return SoftwareProductActionHelper.updateSoftwareProductQuestionnaire(store.dispatch, {
387 softwareProductId: softwareProduct.id,
AviZi280f8012017-06-09 02:39:56 +0300388 version: softwareProduct.version,
Michael Landoefa037d2017-02-19 12:57:33 +0200389 qdata: questionnaireData
390 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300391 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200392 });
393 });
394
395 it('Handle category without subcategories', () => {
AviZi280f8012017-06-09 02:39:56 +0300396
397 const categories = CategoryFactory.buildList(3);
398 categories[0].subcategories = CategoryFactory.buildList(3);
399 categories[2].subcategories = CategoryFactory.buildList(3);
400
401 const category = SoftwareProductCategoriesHelper.getCurrentCategoryOfSubCategory(categories[2].subcategories[2].uniqueId, categories);
402 expect(category).toEqual(categories[2].uniqueId);
Michael Landoefa037d2017-02-19 12:57:33 +0200403 });
404
405});