AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 4 | * 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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 12 | * 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import deepFreeze from 'deep-freeze'; |
| 17 | import mockRest from 'test-utils/MockRest.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 18 | import {cloneAndSet, buildFromExistingObject} from 'test-utils/Util.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 19 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 20 | |
| 21 | import SoftwareProductCreationActionHelper from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationActionHelper.js'; |
| 22 | import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js'; |
| 23 | import SoftwareProductCategoriesHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductCategoriesHelper.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 24 | import {forms} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js'; |
| 25 | import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js'; |
| 26 | |
| 27 | import {VSPEditorFactory, VSPEditorPostFactory, VSPEditorFactoryWithLicensingData, VSPEditorPostFactoryWithLicensingData} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js'; |
| 28 | import {CategoryFactory} from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js'; |
| 29 | import {heatSetupManifest} from 'test-utils/factories/softwareProduct/SoftwareProductAttachmentsFactories.js'; |
| 30 | |
| 31 | import { FeatureGroupStoreFactory as FeatureGroup} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; |
| 32 | import {LicenseAgreementStoreFactory as LicenseAgreement} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js'; |
| 33 | import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; |
| 34 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 35 | |
| 36 | describe('Software Product Module Tests', function () { |
| 37 | it('Get Software Products List', () => { |
| 38 | const store = storeCreator(); |
| 39 | deepFreeze(store.getState()); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 40 | const softwareProductList = VSPEditorFactory.buildList(2); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 41 | deepFreeze(softwareProductList); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 42 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 43 | const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', softwareProductList); |
| 44 | |
| 45 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 46 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/'); |
| 47 | expect(data).toEqual(undefined); |
| 48 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 49 | return {results: softwareProductList}; |
| 50 | }); |
| 51 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 52 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 59 | return SoftwareProductActionHelper.fetchSoftwareProductList(store.dispatch).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 60 | return SoftwareProductActionHelper.fetchFinalizedSoftwareProductList(store.dispatch); |
| 61 | }).then(() => { |
| 62 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 63 | }); |
| 64 | }); |
| 65 | |
| 66 | it('Add Software Product', () => { |
| 67 | const store = storeCreator(); |
| 68 | deepFreeze(store.getState()); |
| 69 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 70 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 75 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 76 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 80 | return { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 81 | vspId: idFromResponse |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 82 | }; |
| 83 | }); |
| 84 | |
| 85 | return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 86 | softwareProduct: softwareProductPostRequest |
| 87 | }).then((response) => { |
| 88 | expect(response.vspId).toEqual(idFromResponse); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 89 | }); |
| 90 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 91 | |
| 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 112 | } |
| 113 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 114 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 259 | 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 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 269 | const dataForUpdate = { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 270 | name: 'VSP5_UPDATED', |
| 271 | description: 'A software model for Fortigate._UPDATED' |
| 272 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 273 | |
| 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 280 | deepFreeze(softwareProductUpdateData); |
| 281 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 282 | const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', [softwareProductPutRequest]); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 283 | const questionnaireData = { |
| 284 | general: { |
| 285 | affinityData: { |
| 286 | affinityGrouping: true, |
| 287 | antiAffinityGrouping: false |
| 288 | } |
| 289 | } |
| 290 | }; |
| 291 | deepFreeze(questionnaireData); |
| 292 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 293 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 297 | return {returnCode: 'OK'}; |
| 298 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 299 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 303 | return {returnCode: 'OK'}; |
| 304 | }); |
| 305 | |
| 306 | return SoftwareProductActionHelper.updateSoftwareProduct(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 307 | softwareProduct: softwareProductPutRequest, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 308 | qdata: questionnaireData |
| 309 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 310 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 311 | }); |
| 312 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 313 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 314 | it('Save Software product data only', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 315 | |
| 316 | const softwareProduct = VSPEditorFactoryWithLicensingData.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 317 | 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 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 328 | const dataForUpdate = { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 329 | name: 'VSP5_UPDATED', |
| 330 | description: 'A software model for Fortigate._UPDATED' |
| 331 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 332 | |
| 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 339 | deepFreeze(softwareProductUpdateData); |
| 340 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 341 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 345 | return {returnCode: 'OK'}; |
| 346 | }); |
| 347 | |
| 348 | return SoftwareProductActionHelper.updateSoftwareProductData(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 349 | softwareProduct: softwareProductPutRequest |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 350 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 351 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 352 | }); |
| 353 | }); |
| 354 | |
| 355 | it('Save Software product questionnaire only', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 356 | const softwareProduct = VSPEditorFactoryWithLicensingData.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 357 | 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 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 379 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 383 | return {returnCode: 'OK'}; |
| 384 | }); |
| 385 | |
| 386 | return SoftwareProductActionHelper.updateSoftwareProductQuestionnaire(store.dispatch, { |
| 387 | softwareProductId: softwareProduct.id, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 388 | version: softwareProduct.version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 389 | qdata: questionnaireData |
| 390 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 391 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 392 | }); |
| 393 | }); |
| 394 | |
| 395 | it('Handle category without subcategories', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 396 | |
| 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 403 | }); |
| 404 | |
| 405 | }); |