blob: 0e0c9ecafd029dbdf81073039d7ea1d006d1c284 [file] [log] [blame]
svishnev091edfd2018-03-19 12:15:19 +02001/*
2 * Copyright © 2016-2018 European Support Limited
andre.schmid36fa9cd2021-07-22 11:54:07 +01003 * Modifications Copyright (C) 2021 Nordix Foundation.
AviZi280f8012017-06-09 02:39:56 +03004 *
Michael Landoefa037d2017-02-19 12:57:33 +02005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
AviZi280f8012017-06-09 02:39:56 +03008 *
svishnev091edfd2018-03-19 12:15:19 +02009 * http://www.apache.org/licenses/LICENSE-2.0
AviZi280f8012017-06-09 02:39:56 +030010 *
Michael Landoefa037d2017-02-19 12:57:33 +020011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
svishnev091edfd2018-03-19 12:15:19 +020013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Michael Landoefa037d2017-02-19 12:57:33 +020016 */
Michael Landoefa037d2017-02-19 12:57:33 +020017import deepFreeze from 'deep-freeze';
18import mockRest from 'test-utils/MockRest.js';
AviZi280f8012017-06-09 02:39:56 +030019import {cloneAndSet, buildFromExistingObject} from 'test-utils/Util.js';
Michael Landoefa037d2017-02-19 12:57:33 +020020import {storeCreator} from 'sdc-app/AppStore.js';
21
22import SoftwareProductCreationActionHelper from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationActionHelper.js';
23import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
24import SoftwareProductCategoriesHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductCategoriesHelper.js';
AviZi280f8012017-06-09 02:39:56 +030025import {forms} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js';
26import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
27
28import {VSPEditorFactory, VSPEditorPostFactory, VSPEditorFactoryWithLicensingData, VSPEditorPostFactoryWithLicensingData} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';
29import {CategoryFactory} from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js';
30import {heatSetupManifest} from 'test-utils/factories/softwareProduct/SoftwareProductAttachmentsFactories.js';
31
32import { FeatureGroupStoreFactory as FeatureGroup} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
33import {LicenseAgreementStoreFactory as LicenseAgreement} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js';
AviZi280f8012017-06-09 02:39:56 +030034
talig8e9c0652017-12-20 14:30:43 +020035import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
36import {InitializedCurrentScreenFactory} from 'test-utils/factories/common/CurrentScreenFactory.js';
Michael Landoefa037d2017-02-19 12:57:33 +020037
talig8e9c0652017-12-20 14:30:43 +020038describe('Software Product Details Module Tests', function () {
svishnev091edfd2018-03-19 12:15:19 +020039 it('Get Software Products List', async () => {
Michael Landoefa037d2017-02-19 12:57:33 +020040 const store = storeCreator();
41 deepFreeze(store.getState());
AviZi280f8012017-06-09 02:39:56 +030042 const softwareProductList = VSPEditorFactory.buildList(2);
Michael Landoefa037d2017-02-19 12:57:33 +020043 deepFreeze(softwareProductList);
Michael Landoefa037d2017-02-19 12:57:33 +020044 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +020045 const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', softwareProductList);
46
47 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +020048 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/?versionFilter=Draft');
AviZi280f8012017-06-09 02:39:56 +030049 expect(data).toEqual(undefined);
50 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020051 return {results: softwareProductList};
52 });
53
AviZi280f8012017-06-09 02:39:56 +030054 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +020055 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/?versionFilter=Certified');
AviZi280f8012017-06-09 02:39:56 +030056 expect(data).toEqual(undefined);
57 expect(options).toEqual(undefined);
58 return {results: []};
59 });
60
svishnev091edfd2018-03-19 12:15:19 +020061 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
62 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/?Status=ARCHIVED');
63 expect(data).toEqual(undefined);
64 expect(options).toEqual(undefined);
65 return {results: []};
Michael Landoefa037d2017-02-19 12:57:33 +020066 });
svishnev091edfd2018-03-19 12:15:19 +020067
68 await SoftwareProductActionHelper.fetchSoftwareProductList(store.dispatch);
69 await SoftwareProductActionHelper.fetchFinalizedSoftwareProductList(store.dispatch);
70 await SoftwareProductActionHelper.fetchArchivedSoftwareProductList(store.dispatch);
aribeirocba52c92021-07-12 15:10:19 +010071
72 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020073 });
74
75 it('Add Software Product', () => {
76 const store = storeCreator();
77 deepFreeze(store.getState());
78
AviZi280f8012017-06-09 02:39:56 +030079 const softwareProductPostRequest = VSPEditorPostFactory.build();
80 deepFreeze(softwareProductPostRequest);
81 const idFromResponse = '1';
82 const expectedVSP = VSPEditorPostFactory.build({id: idFromResponse, vendorId: softwareProductPostRequest.vendorId});
83 deepFreeze(expectedVSP);
Michael Landoefa037d2017-02-19 12:57:33 +020084
AviZi280f8012017-06-09 02:39:56 +030085 mockRest.addHandler('post', ({options, data, baseUrl}) => {
86 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/');
87 expect(data).toEqual(softwareProductPostRequest);
88 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020089 return {
AviZi280f8012017-06-09 02:39:56 +030090 vspId: idFromResponse
Michael Landoefa037d2017-02-19 12:57:33 +020091 };
92 });
93
94 return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, {
AviZi280f8012017-06-09 02:39:56 +030095 softwareProduct: softwareProductPostRequest
96 }).then((response) => {
97 expect(response.vspId).toEqual(idFromResponse);
Michael Landoefa037d2017-02-19 12:57:33 +020098 });
99 });
AviZi280f8012017-06-09 02:39:56 +0300100
101 it('Fetch Software Product with manifest', () => {
102 const store = storeCreator();
103 deepFreeze(store.getState());
104
105 const softwareProductPostRequest = VSPEditorPostFactory.build();
106 deepFreeze(softwareProductPostRequest);
107
108 const expectedGenericInfo = {
109 'name': {
110 isValid: true,
111 errorText: '',
112 validations: [{type: 'validateName', data: true}, {type: 'maxLength', data: 25}, {
113 type: 'required',
114 data: true
115 }]
116 },
117 'description': {
118 isValid: true,
119 errorText: '',
aribeirocba52c92021-07-12 15:10:19 +0100120 validations: [{type: 'validateName', data: true}, {type: 'required', data: true}]
Michael Landoefa037d2017-02-19 12:57:33 +0200121 }
122 };
AviZi280f8012017-06-09 02:39:56 +0300123 const expectedFormName = forms.VENDOR_SOFTWARE_PRODUCT_DETAILS;
124
125 const idFromResponse = '1';
126 const version = { id: '0.1', label: '0.1'};
127 const expectedVSP = VSPEditorPostFactory.build({id: idFromResponse, vendorId: softwareProductPostRequest.vendorId});
128 deepFreeze(expectedVSP);
129 let expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductEditor.data', expectedVSP);
130 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.genericFieldInfo', expectedGenericInfo);
131 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.formName', expectedFormName);
132 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductQuestionnaire', {qdata: {}, dataMap: {}, qgenericFieldInfo: {}});
133
134 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductAttachments.heatValidation', {
135 'attachmentsTree': {},
136 'errorList': [],
137 'selectedNode': 'All'
138 });
139 let manifest = heatSetupManifest.build();
140 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductAttachments.heatSetup', manifest);
141
talig8e9c0652017-12-20 14:30:43 +0200142 const expectedCurrentScreen = InitializedCurrentScreenFactory.build();
143 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreen.itemPermission);
144 expectedStore = cloneAndSet(expectedStore, 'currentScreen.props', expectedCurrentScreen.props);
145
AviZi280f8012017-06-09 02:39:56 +0300146 mockRest.addHandler('post', ({options, data, baseUrl}) => {
147 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/');
148 expect(data).toEqual(softwareProductPostRequest);
149 expect(options).toEqual(undefined);
150 return {
151 vspId: idFromResponse,
152 version
153 };
154 });
155
156 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
157 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}`);
158 expect(data).toEqual(undefined);
159 expect(options).toEqual(undefined);
160 return expectedVSP;
161 });
162
163 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
164 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}/questionnaire`);
165 expect(data).toEqual(undefined);
166 expect(options).toEqual(undefined);
167 return {data: JSON.stringify({}), schema: JSON.stringify({})};
168 });
169
170 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
171 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}/orchestration-template-candidate/manifest`);
172 expect(data).toEqual(undefined);
173 expect(options).toEqual(undefined);
174 return manifest;
175 });
176
177 return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, {
178 softwareProduct: softwareProductPostRequest
179 }).then(() => {
180 return SoftwareProductActionHelper.fetchSoftwareProduct(store.dispatch, {softwareProductId: idFromResponse, version});
181 }).then(() => {
182 return SoftwareProductActionHelper.loadSoftwareProductHeatCandidate(store.dispatch, {softwareProductId: idFromResponse, version});
183 }).then(() => {
184 expect(store.getState()).toEqual(expectedStore);
185 let newName = 'newName';
186 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.formReady', null);
187 ValidationHelper.dataChanged(store.dispatch, {deltaData: {'name': newName}, formName: forms.VENDOR_SOFTWARE_PRODUCT_DETAILS});
188 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.data.name', newName);
189 expect(store.getState()).toEqual(expectedStore);
190 });
191 });
192
193 it('Load and edit Software Product licensing data', () => {
194 const store = storeCreator();
195
196 const softwareProductPostRequest = VSPEditorPostFactory.build();
197 deepFreeze(softwareProductPostRequest);
198
199 const licenseModelId = softwareProductPostRequest.vendorId;
talig8e9c0652017-12-20 14:30:43 +0200200 const LMVersion = VersionFactory.build();
AviZi280f8012017-06-09 02:39:56 +0300201 const secondLicenseModelId = 'secondLicenseModelId';
202
203 let FG1 = FeatureGroup.build();
204 let LA1 = LicenseAgreement.build({
205 featureGroupsIds: [FG1.id]
206 });
207
208 let FG2 = FeatureGroup.build();
209 let LA2 = LicenseAgreement.build({
210 featureGroupsIds: [FG2.id]
211 });
212
213 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
214 expect(baseUrl).toEqual('/sdc1/feProxy/rest/v1/categories/resources/');
215 expect(data).toEqual(undefined);
216 expect(options).toEqual(undefined);
217 return [];
218 });
219
220 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
andre.schmid36fa9cd2021-07-22 11:54:07 +0100221 expect(baseUrl).toEqual('/sdc1/feProxy/rest/v1/catalog/model/');
222 expect(data).toEqual(undefined);
223 expect(options).toEqual(undefined);
224 return [];
225 });
226
227 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200228 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-license-models/?versionFilter=Certified');
AviZi280f8012017-06-09 02:39:56 +0300229 expect(data).toEqual(undefined);
230 expect(options).toEqual(undefined);
231 return {results: []};
232 });
233
234 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200235 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${licenseModelId}/versions/${LMVersion.id}`);
236 expect(data).toEqual(undefined);
237 expect(options).toEqual(undefined);
238 return {results: {}};
239 });
240
241 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +0300242 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModelId}/versions/${LMVersion.id}/license-agreements`);
243 expect(data).toEqual(undefined);
244 expect(options).toEqual(undefined);
245 return {results: [LA1]};
246 });
247
248 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
249 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModelId}/versions/${LMVersion.id}/feature-groups`);
250 expect(data).toEqual(undefined);
251 expect(options).toEqual(undefined);
252 return {results: [FG1]};
253 });
254
255 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200256 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${secondLicenseModelId}/versions/${LMVersion.id}`);
257 expect(data).toEqual(undefined);
258 expect(options).toEqual(undefined);
259 return {results: {}};
260 });
261
262 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +0300263 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${secondLicenseModelId}/versions/${LMVersion.id}/license-agreements`);
264 expect(data).toEqual(undefined);
265 expect(options).toEqual(undefined);
266 return {results: [LA2]};
267 });
268
269 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
270 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${secondLicenseModelId}/versions/${LMVersion.id}/feature-groups`);
271 expect(data).toEqual(undefined);
272 expect(options).toEqual(undefined);
273 return {results: [FG2]};
274 });
275
talig8e9c0652017-12-20 14:30:43 +0200276 return SoftwareProductActionHelper.loadSoftwareProductDetailsData(store.dispatch, {licenseModelId, licensingVersion: LMVersion.id}).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300277 let state = store.getState();
278 expect(state.licenseModel.licenseAgreement.licenseAgreementList).toEqual([LA1]);
279 expect(state.licenseModel.featureGroup.featureGroupsList).toEqual([FG1]);
280 return SoftwareProductActionHelper.softwareProductEditorVendorChanged(store.dispatch,
talig8e9c0652017-12-20 14:30:43 +0200281 {deltaData: {vendorId: secondLicenseModelId, licensingVersion: LMVersion.id},
282 formName: forms.VENDOR_SOFTWARE_PRODUCT_DETAILS}
283 ).then(() => {
284 let state = store.getState();
285 expect(state.licenseModel.licenseAgreement.licenseAgreementList).toEqual([LA2]);
286 expect(state.licenseModel.featureGroup.featureGroupsList).toEqual([FG2]);
287 });
AviZi280f8012017-06-09 02:39:56 +0300288 });
289 });
290
291 it('Save Software product', () => {
292
293 const softwareProduct = VSPEditorFactoryWithLicensingData.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200294 deepFreeze(softwareProduct);
295
talig8e9c0652017-12-20 14:30:43 +0200296 const version = VersionFactory.build();
297
Michael Landoefa037d2017-02-19 12:57:33 +0200298 const store = storeCreator({
299 softwareProduct: {
300 softwareProductEditor: {data: softwareProduct},
301 softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
302 }
303 });
304 deepFreeze(store.getState());
305
AviZi280f8012017-06-09 02:39:56 +0300306 const dataForUpdate = {
Michael Landoefa037d2017-02-19 12:57:33 +0200307 name: 'VSP5_UPDATED',
308 description: 'A software model for Fortigate._UPDATED'
309 };
AviZi280f8012017-06-09 02:39:56 +0300310
311 const toBeUpdatedSoftwareProductId = softwareProduct.id;
312 let softwareProductUpdateData = VSPEditorPostFactoryWithLicensingData.build(dataForUpdate);
313 delete softwareProductUpdateData.version;
314
315 const softwareProductPutRequest = buildFromExistingObject(VSPEditorFactoryWithLicensingData, softwareProductUpdateData, {id: toBeUpdatedSoftwareProductId, version: softwareProduct.version});
316
Michael Landoefa037d2017-02-19 12:57:33 +0200317 deepFreeze(softwareProductUpdateData);
318
AviZi280f8012017-06-09 02:39:56 +0300319 const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', [softwareProductPutRequest]);
Michael Landoefa037d2017-02-19 12:57:33 +0200320 const questionnaireData = {
321 general: {
322 affinityData: {
323 affinityGrouping: true,
324 antiAffinityGrouping: false
325 }
326 }
327 };
328 deepFreeze(questionnaireData);
329
AviZi280f8012017-06-09 02:39:56 +0300330 mockRest.addHandler('put', ({data, options, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200331 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${version.id}`);
AviZi280f8012017-06-09 02:39:56 +0300332 expect(data).toEqual(softwareProductUpdateData);
333 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200334 return {returnCode: 'OK'};
335 });
AviZi280f8012017-06-09 02:39:56 +0300336 mockRest.addHandler('put', ({data, options, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200337 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${version.id}/questionnaire`);
AviZi280f8012017-06-09 02:39:56 +0300338 expect(data).toEqual(questionnaireData);
339 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200340 return {returnCode: 'OK'};
341 });
342
343 return SoftwareProductActionHelper.updateSoftwareProduct(store.dispatch, {
AviZi280f8012017-06-09 02:39:56 +0300344 softwareProduct: softwareProductPutRequest,
talig8e9c0652017-12-20 14:30:43 +0200345 qdata: questionnaireData,
346 version
Michael Landoefa037d2017-02-19 12:57:33 +0200347 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300348 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200349 });
350 });
AviZi280f8012017-06-09 02:39:56 +0300351
Michael Landoefa037d2017-02-19 12:57:33 +0200352 it('Save Software product data only', () => {
AviZi280f8012017-06-09 02:39:56 +0300353
354 const softwareProduct = VSPEditorFactoryWithLicensingData.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200355 deepFreeze(softwareProduct);
356
talig8e9c0652017-12-20 14:30:43 +0200357 const version = VersionFactory.build();
358
Michael Landoefa037d2017-02-19 12:57:33 +0200359 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
AviZi280f8012017-06-09 02:39:56 +0300368 const dataForUpdate = {
Michael Landoefa037d2017-02-19 12:57:33 +0200369 name: 'VSP5_UPDATED',
370 description: 'A software model for Fortigate._UPDATED'
371 };
AviZi280f8012017-06-09 02:39:56 +0300372
373 const toBeUpdatedSoftwareProductId = softwareProduct.id;
374 let softwareProductUpdateData = VSPEditorPostFactoryWithLicensingData.build(dataForUpdate);
375 delete softwareProductUpdateData.version;
376
talig8e9c0652017-12-20 14:30:43 +0200377 const softwareProductPutRequest = buildFromExistingObject(VSPEditorFactoryWithLicensingData, softwareProductUpdateData, {id: toBeUpdatedSoftwareProductId});
AviZi280f8012017-06-09 02:39:56 +0300378
Michael Landoefa037d2017-02-19 12:57:33 +0200379 deepFreeze(softwareProductUpdateData);
380
AviZi280f8012017-06-09 02:39:56 +0300381 mockRest.addHandler('put', ({data, options, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200382 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${version.id}`);
AviZi280f8012017-06-09 02:39:56 +0300383 expect(data).toEqual(softwareProductUpdateData);
384 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200385 return {returnCode: 'OK'};
386 });
387
388 return SoftwareProductActionHelper.updateSoftwareProductData(store.dispatch, {
talig8e9c0652017-12-20 14:30:43 +0200389 softwareProduct: softwareProductPutRequest,
390 version
Michael Landoefa037d2017-02-19 12:57:33 +0200391 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300392 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200393 });
394 });
395
396 it('Save Software product questionnaire only', () => {
AviZi280f8012017-06-09 02:39:56 +0300397 const softwareProduct = VSPEditorFactoryWithLicensingData.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200398 deepFreeze(softwareProduct);
399
talig8e9c0652017-12-20 14:30:43 +0200400 const version = VersionFactory.build();
401
Michael Landoefa037d2017-02-19 12:57:33 +0200402 const store = storeCreator({
403 softwareProduct: {
404 softwareProductEditor: {data: softwareProduct},
405 softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
406 }
407 });
408 deepFreeze(store.getState());
409 const expectedStore = store.getState();
410
411 const toBeUpdatedSoftwareProductId = softwareProduct.id;
412 const questionnaireData = {
413 general: {
414 affinityData: {
415 affinityGrouping: true,
416 antiAffinityGrouping: false
417 }
418 }
419 };
420 deepFreeze(questionnaireData);
421
AviZi280f8012017-06-09 02:39:56 +0300422 mockRest.addHandler('put', ({data, options, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200423 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${version.id}/questionnaire`);
AviZi280f8012017-06-09 02:39:56 +0300424 expect(data).toEqual(questionnaireData);
425 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200426 return {returnCode: 'OK'};
427 });
428
429 return SoftwareProductActionHelper.updateSoftwareProductQuestionnaire(store.dispatch, {
430 softwareProductId: softwareProduct.id,
talig8e9c0652017-12-20 14:30:43 +0200431 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200432 qdata: questionnaireData
433 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300434 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200435 });
436 });
437
438 it('Handle category without subcategories', () => {
AviZi280f8012017-06-09 02:39:56 +0300439
440 const categories = CategoryFactory.buildList(3);
441 categories[0].subcategories = CategoryFactory.buildList(3);
442 categories[2].subcategories = CategoryFactory.buildList(3);
443
444 const category = SoftwareProductCategoriesHelper.getCurrentCategoryOfSubCategory(categories[2].subcategories[2].uniqueId, categories);
445 expect(category).toEqual(categories[2].uniqueId);
Michael Landoefa037d2017-02-19 12:57:33 +0200446 });
447
448});