blob: 60506243ffe72cf432467649ac95f68cf444096a [file] [log] [blame]
svishnev091edfd2018-03-19 12:15:19 +02001/*
2 * Copyright © 2016-2018 European Support Limited
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 *
svishnev091edfd2018-03-19 12:15:19 +02008 * http://www.apache.org/licenses/LICENSE-2.0
AviZi280f8012017-06-09 02:39:56 +03009 *
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,
svishnev091edfd2018-03-19 12:15:19 +020012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * 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';
AviZi280f8012017-06-09 02:39:56 +030033
talig8e9c0652017-12-20 14:30:43 +020034import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
35import {InitializedCurrentScreenFactory} from 'test-utils/factories/common/CurrentScreenFactory.js';
Michael Landoefa037d2017-02-19 12:57:33 +020036
talig8e9c0652017-12-20 14:30:43 +020037describe('Software Product Details Module Tests', function () {
svishnev091edfd2018-03-19 12:15:19 +020038 it('Get Software Products List', async () => {
Michael Landoefa037d2017-02-19 12:57:33 +020039 const store = storeCreator();
40 deepFreeze(store.getState());
AviZi280f8012017-06-09 02:39:56 +030041 const softwareProductList = VSPEditorFactory.buildList(2);
Michael Landoefa037d2017-02-19 12:57:33 +020042 deepFreeze(softwareProductList);
Michael Landoefa037d2017-02-19 12:57:33 +020043 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +020044 const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', softwareProductList);
45
46 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +020047 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/?versionFilter=Draft');
AviZi280f8012017-06-09 02:39:56 +030048 expect(data).toEqual(undefined);
49 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020050 return {results: softwareProductList};
51 });
52
AviZi280f8012017-06-09 02:39:56 +030053 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +020054 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/?versionFilter=Certified');
AviZi280f8012017-06-09 02:39:56 +030055 expect(data).toEqual(undefined);
56 expect(options).toEqual(undefined);
57 return {results: []};
58 });
59
svishnev091edfd2018-03-19 12:15:19 +020060 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
61 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/?Status=ARCHIVED');
62 expect(data).toEqual(undefined);
63 expect(options).toEqual(undefined);
64 return {results: []};
Michael Landoefa037d2017-02-19 12:57:33 +020065 });
svishnev091edfd2018-03-19 12:15:19 +020066
67 await SoftwareProductActionHelper.fetchSoftwareProductList(store.dispatch);
68 await SoftwareProductActionHelper.fetchFinalizedSoftwareProductList(store.dispatch);
69 await SoftwareProductActionHelper.fetchArchivedSoftwareProductList(store.dispatch);
70
71 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020072 });
73
74 it('Add Software Product', () => {
75 const store = storeCreator();
76 deepFreeze(store.getState());
77
AviZi280f8012017-06-09 02:39:56 +030078 const softwareProductPostRequest = VSPEditorPostFactory.build();
79 deepFreeze(softwareProductPostRequest);
80 const idFromResponse = '1';
81 const expectedVSP = VSPEditorPostFactory.build({id: idFromResponse, vendorId: softwareProductPostRequest.vendorId});
82 deepFreeze(expectedVSP);
Michael Landoefa037d2017-02-19 12:57:33 +020083
AviZi280f8012017-06-09 02:39:56 +030084 mockRest.addHandler('post', ({options, data, baseUrl}) => {
85 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/');
86 expect(data).toEqual(softwareProductPostRequest);
87 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020088 return {
AviZi280f8012017-06-09 02:39:56 +030089 vspId: idFromResponse
Michael Landoefa037d2017-02-19 12:57:33 +020090 };
91 });
92
93 return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, {
AviZi280f8012017-06-09 02:39:56 +030094 softwareProduct: softwareProductPostRequest
95 }).then((response) => {
96 expect(response.vspId).toEqual(idFromResponse);
Michael Landoefa037d2017-02-19 12:57:33 +020097 });
98 });
AviZi280f8012017-06-09 02:39:56 +030099
100 it('Fetch Software Product with manifest', () => {
101 const store = storeCreator();
102 deepFreeze(store.getState());
103
104 const softwareProductPostRequest = VSPEditorPostFactory.build();
105 deepFreeze(softwareProductPostRequest);
106
107 const expectedGenericInfo = {
108 'name': {
109 isValid: true,
110 errorText: '',
111 validations: [{type: 'validateName', data: true}, {type: 'maxLength', data: 25}, {
112 type: 'required',
113 data: true
114 }]
115 },
116 'description': {
117 isValid: true,
118 errorText: '',
119 validations: [{type: 'required', data: true}]
Michael Landoefa037d2017-02-19 12:57:33 +0200120 }
121 };
AviZi280f8012017-06-09 02:39:56 +0300122 const expectedFormName = forms.VENDOR_SOFTWARE_PRODUCT_DETAILS;
123
124 const idFromResponse = '1';
125 const version = { id: '0.1', label: '0.1'};
126 const expectedVSP = VSPEditorPostFactory.build({id: idFromResponse, vendorId: softwareProductPostRequest.vendorId});
127 deepFreeze(expectedVSP);
128 let expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductEditor.data', expectedVSP);
129 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.genericFieldInfo', expectedGenericInfo);
130 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.formName', expectedFormName);
131 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductQuestionnaire', {qdata: {}, dataMap: {}, qgenericFieldInfo: {}});
132
133 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductAttachments.heatValidation', {
134 'attachmentsTree': {},
135 'errorList': [],
136 'selectedNode': 'All'
137 });
138 let manifest = heatSetupManifest.build();
139 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductAttachments.heatSetup', manifest);
140
talig8e9c0652017-12-20 14:30:43 +0200141 const expectedCurrentScreen = InitializedCurrentScreenFactory.build();
142 expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreen.itemPermission);
143 expectedStore = cloneAndSet(expectedStore, 'currentScreen.props', expectedCurrentScreen.props);
144
AviZi280f8012017-06-09 02:39:56 +0300145 mockRest.addHandler('post', ({options, data, baseUrl}) => {
146 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/');
147 expect(data).toEqual(softwareProductPostRequest);
148 expect(options).toEqual(undefined);
149 return {
150 vspId: idFromResponse,
151 version
152 };
153 });
154
155 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
156 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}`);
157 expect(data).toEqual(undefined);
158 expect(options).toEqual(undefined);
159 return expectedVSP;
160 });
161
162 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
163 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}/questionnaire`);
164 expect(data).toEqual(undefined);
165 expect(options).toEqual(undefined);
166 return {data: JSON.stringify({}), schema: JSON.stringify({})};
167 });
168
169 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
170 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}/orchestration-template-candidate/manifest`);
171 expect(data).toEqual(undefined);
172 expect(options).toEqual(undefined);
173 return manifest;
174 });
175
176 return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, {
177 softwareProduct: softwareProductPostRequest
178 }).then(() => {
179 return SoftwareProductActionHelper.fetchSoftwareProduct(store.dispatch, {softwareProductId: idFromResponse, version});
180 }).then(() => {
181 return SoftwareProductActionHelper.loadSoftwareProductHeatCandidate(store.dispatch, {softwareProductId: idFromResponse, version});
182 }).then(() => {
183 expect(store.getState()).toEqual(expectedStore);
184 let newName = 'newName';
185 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.formReady', null);
186 ValidationHelper.dataChanged(store.dispatch, {deltaData: {'name': newName}, formName: forms.VENDOR_SOFTWARE_PRODUCT_DETAILS});
187 expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.data.name', newName);
188 expect(store.getState()).toEqual(expectedStore);
189 });
190 });
191
192 it('Load and edit Software Product licensing data', () => {
193 const store = storeCreator();
194
195 const softwareProductPostRequest = VSPEditorPostFactory.build();
196 deepFreeze(softwareProductPostRequest);
197
198 const licenseModelId = softwareProductPostRequest.vendorId;
talig8e9c0652017-12-20 14:30:43 +0200199 const LMVersion = VersionFactory.build();
AviZi280f8012017-06-09 02:39:56 +0300200 const secondLicenseModelId = 'secondLicenseModelId';
201
202 let FG1 = FeatureGroup.build();
203 let LA1 = LicenseAgreement.build({
204 featureGroupsIds: [FG1.id]
205 });
206
207 let FG2 = FeatureGroup.build();
208 let LA2 = LicenseAgreement.build({
209 featureGroupsIds: [FG2.id]
210 });
211
212 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
213 expect(baseUrl).toEqual('/sdc1/feProxy/rest/v1/categories/resources/');
214 expect(data).toEqual(undefined);
215 expect(options).toEqual(undefined);
216 return [];
217 });
218
219 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200220 expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-license-models/?versionFilter=Certified');
AviZi280f8012017-06-09 02:39:56 +0300221 expect(data).toEqual(undefined);
222 expect(options).toEqual(undefined);
223 return {results: []};
224 });
225
226 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200227 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${licenseModelId}/versions/${LMVersion.id}`);
228 expect(data).toEqual(undefined);
229 expect(options).toEqual(undefined);
230 return {results: {}};
231 });
232
233 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +0300234 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModelId}/versions/${LMVersion.id}/license-agreements`);
235 expect(data).toEqual(undefined);
236 expect(options).toEqual(undefined);
237 return {results: [LA1]};
238 });
239
240 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
241 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModelId}/versions/${LMVersion.id}/feature-groups`);
242 expect(data).toEqual(undefined);
243 expect(options).toEqual(undefined);
244 return {results: [FG1]};
245 });
246
247 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200248 expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${secondLicenseModelId}/versions/${LMVersion.id}`);
249 expect(data).toEqual(undefined);
250 expect(options).toEqual(undefined);
251 return {results: {}};
252 });
253
254 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +0300255 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${secondLicenseModelId}/versions/${LMVersion.id}/license-agreements`);
256 expect(data).toEqual(undefined);
257 expect(options).toEqual(undefined);
258 return {results: [LA2]};
259 });
260
261 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
262 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${secondLicenseModelId}/versions/${LMVersion.id}/feature-groups`);
263 expect(data).toEqual(undefined);
264 expect(options).toEqual(undefined);
265 return {results: [FG2]};
266 });
267
talig8e9c0652017-12-20 14:30:43 +0200268 return SoftwareProductActionHelper.loadSoftwareProductDetailsData(store.dispatch, {licenseModelId, licensingVersion: LMVersion.id}).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300269 let state = store.getState();
270 expect(state.licenseModel.licenseAgreement.licenseAgreementList).toEqual([LA1]);
271 expect(state.licenseModel.featureGroup.featureGroupsList).toEqual([FG1]);
272 return SoftwareProductActionHelper.softwareProductEditorVendorChanged(store.dispatch,
talig8e9c0652017-12-20 14:30:43 +0200273 {deltaData: {vendorId: secondLicenseModelId, licensingVersion: LMVersion.id},
274 formName: forms.VENDOR_SOFTWARE_PRODUCT_DETAILS}
275 ).then(() => {
276 let state = store.getState();
277 expect(state.licenseModel.licenseAgreement.licenseAgreementList).toEqual([LA2]);
278 expect(state.licenseModel.featureGroup.featureGroupsList).toEqual([FG2]);
279 });
AviZi280f8012017-06-09 02:39:56 +0300280 });
281 });
282
283 it('Save Software product', () => {
284
285 const softwareProduct = VSPEditorFactoryWithLicensingData.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200286 deepFreeze(softwareProduct);
287
talig8e9c0652017-12-20 14:30:43 +0200288 const version = VersionFactory.build();
289
Michael Landoefa037d2017-02-19 12:57:33 +0200290 const store = storeCreator({
291 softwareProduct: {
292 softwareProductEditor: {data: softwareProduct},
293 softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
294 }
295 });
296 deepFreeze(store.getState());
297
AviZi280f8012017-06-09 02:39:56 +0300298 const dataForUpdate = {
Michael Landoefa037d2017-02-19 12:57:33 +0200299 name: 'VSP5_UPDATED',
300 description: 'A software model for Fortigate._UPDATED'
301 };
AviZi280f8012017-06-09 02:39:56 +0300302
303 const toBeUpdatedSoftwareProductId = softwareProduct.id;
304 let softwareProductUpdateData = VSPEditorPostFactoryWithLicensingData.build(dataForUpdate);
305 delete softwareProductUpdateData.version;
306
307 const softwareProductPutRequest = buildFromExistingObject(VSPEditorFactoryWithLicensingData, softwareProductUpdateData, {id: toBeUpdatedSoftwareProductId, version: softwareProduct.version});
308
Michael Landoefa037d2017-02-19 12:57:33 +0200309 deepFreeze(softwareProductUpdateData);
310
AviZi280f8012017-06-09 02:39:56 +0300311 const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', [softwareProductPutRequest]);
Michael Landoefa037d2017-02-19 12:57:33 +0200312 const questionnaireData = {
313 general: {
314 affinityData: {
315 affinityGrouping: true,
316 antiAffinityGrouping: false
317 }
318 }
319 };
320 deepFreeze(questionnaireData);
321
AviZi280f8012017-06-09 02:39:56 +0300322 mockRest.addHandler('put', ({data, options, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200323 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${version.id}`);
AviZi280f8012017-06-09 02:39:56 +0300324 expect(data).toEqual(softwareProductUpdateData);
325 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200326 return {returnCode: 'OK'};
327 });
AviZi280f8012017-06-09 02:39:56 +0300328 mockRest.addHandler('put', ({data, options, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200329 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${version.id}/questionnaire`);
AviZi280f8012017-06-09 02:39:56 +0300330 expect(data).toEqual(questionnaireData);
331 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200332 return {returnCode: 'OK'};
333 });
334
335 return SoftwareProductActionHelper.updateSoftwareProduct(store.dispatch, {
AviZi280f8012017-06-09 02:39:56 +0300336 softwareProduct: softwareProductPutRequest,
talig8e9c0652017-12-20 14:30:43 +0200337 qdata: questionnaireData,
338 version
Michael Landoefa037d2017-02-19 12:57:33 +0200339 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300340 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200341 });
342 });
AviZi280f8012017-06-09 02:39:56 +0300343
Michael Landoefa037d2017-02-19 12:57:33 +0200344 it('Save Software product data only', () => {
AviZi280f8012017-06-09 02:39:56 +0300345
346 const softwareProduct = VSPEditorFactoryWithLicensingData.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200347 deepFreeze(softwareProduct);
348
talig8e9c0652017-12-20 14:30:43 +0200349 const version = VersionFactory.build();
350
Michael Landoefa037d2017-02-19 12:57:33 +0200351 const store = storeCreator({
352 softwareProduct: {
353 softwareProductEditor: {data: softwareProduct},
354 softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
355 }
356 });
357 deepFreeze(store.getState());
358 const expectedStore = store.getState();
359
AviZi280f8012017-06-09 02:39:56 +0300360 const dataForUpdate = {
Michael Landoefa037d2017-02-19 12:57:33 +0200361 name: 'VSP5_UPDATED',
362 description: 'A software model for Fortigate._UPDATED'
363 };
AviZi280f8012017-06-09 02:39:56 +0300364
365 const toBeUpdatedSoftwareProductId = softwareProduct.id;
366 let softwareProductUpdateData = VSPEditorPostFactoryWithLicensingData.build(dataForUpdate);
367 delete softwareProductUpdateData.version;
368
talig8e9c0652017-12-20 14:30:43 +0200369 const softwareProductPutRequest = buildFromExistingObject(VSPEditorFactoryWithLicensingData, softwareProductUpdateData, {id: toBeUpdatedSoftwareProductId});
AviZi280f8012017-06-09 02:39:56 +0300370
Michael Landoefa037d2017-02-19 12:57:33 +0200371 deepFreeze(softwareProductUpdateData);
372
AviZi280f8012017-06-09 02:39:56 +0300373 mockRest.addHandler('put', ({data, options, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200374 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${version.id}`);
AviZi280f8012017-06-09 02:39:56 +0300375 expect(data).toEqual(softwareProductUpdateData);
376 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200377 return {returnCode: 'OK'};
378 });
379
380 return SoftwareProductActionHelper.updateSoftwareProductData(store.dispatch, {
talig8e9c0652017-12-20 14:30:43 +0200381 softwareProduct: softwareProductPutRequest,
382 version
Michael Landoefa037d2017-02-19 12:57:33 +0200383 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300384 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200385 });
386 });
387
388 it('Save Software product questionnaire only', () => {
AviZi280f8012017-06-09 02:39:56 +0300389 const softwareProduct = VSPEditorFactoryWithLicensingData.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200390 deepFreeze(softwareProduct);
391
talig8e9c0652017-12-20 14:30:43 +0200392 const version = VersionFactory.build();
393
Michael Landoefa037d2017-02-19 12:57:33 +0200394 const store = storeCreator({
395 softwareProduct: {
396 softwareProductEditor: {data: softwareProduct},
397 softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}}
398 }
399 });
400 deepFreeze(store.getState());
401 const expectedStore = store.getState();
402
403 const toBeUpdatedSoftwareProductId = softwareProduct.id;
404 const questionnaireData = {
405 general: {
406 affinityData: {
407 affinityGrouping: true,
408 antiAffinityGrouping: false
409 }
410 }
411 };
412 deepFreeze(questionnaireData);
413
AviZi280f8012017-06-09 02:39:56 +0300414 mockRest.addHandler('put', ({data, options, baseUrl}) => {
talig8e9c0652017-12-20 14:30:43 +0200415 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${version.id}/questionnaire`);
AviZi280f8012017-06-09 02:39:56 +0300416 expect(data).toEqual(questionnaireData);
417 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200418 return {returnCode: 'OK'};
419 });
420
421 return SoftwareProductActionHelper.updateSoftwareProductQuestionnaire(store.dispatch, {
422 softwareProductId: softwareProduct.id,
talig8e9c0652017-12-20 14:30:43 +0200423 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200424 qdata: questionnaireData
425 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300426 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200427 });
428 });
429
430 it('Handle category without subcategories', () => {
AviZi280f8012017-06-09 02:39:56 +0300431
432 const categories = CategoryFactory.buildList(3);
433 categories[0].subcategories = CategoryFactory.buildList(3);
434 categories[2].subcategories = CategoryFactory.buildList(3);
435
436 const category = SoftwareProductCategoriesHelper.getCurrentCategoryOfSubCategory(categories[2].subcategories[2].uniqueId, categories);
437 expect(category).toEqual(categories[2].uniqueId);
Michael Landoefa037d2017-02-19 12:57:33 +0200438 });
439
440});