svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
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 | * |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 12 | * 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 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'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 33 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 34 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
| 35 | import {InitializedCurrentScreenFactory} from 'test-utils/factories/common/CurrentScreenFactory.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 36 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 37 | describe('Software Product Details Module Tests', function () { |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 38 | it('Get Software Products List', async () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 39 | const store = storeCreator(); |
| 40 | deepFreeze(store.getState()); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 41 | const softwareProductList = VSPEditorFactory.buildList(2); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 42 | deepFreeze(softwareProductList); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 43 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 44 | const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', softwareProductList); |
| 45 | |
| 46 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 47 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/?versionFilter=Draft'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 48 | expect(data).toEqual(undefined); |
| 49 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 50 | return {results: softwareProductList}; |
| 51 | }); |
| 52 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 53 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 54 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/?versionFilter=Certified'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 55 | expect(data).toEqual(undefined); |
| 56 | expect(options).toEqual(undefined); |
| 57 | return {results: []}; |
| 58 | }); |
| 59 | |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 60 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 65 | }); |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 66 | |
| 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 72 | }); |
| 73 | |
| 74 | it('Add Software Product', () => { |
| 75 | const store = storeCreator(); |
| 76 | deepFreeze(store.getState()); |
| 77 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 78 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 83 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 84 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 88 | return { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 89 | vspId: idFromResponse |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 90 | }; |
| 91 | }); |
| 92 | |
| 93 | return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 94 | softwareProduct: softwareProductPostRequest |
| 95 | }).then((response) => { |
| 96 | expect(response.vspId).toEqual(idFromResponse); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 97 | }); |
| 98 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 99 | |
| 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 120 | } |
| 121 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 122 | 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 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 141 | const expectedCurrentScreen = InitializedCurrentScreenFactory.build(); |
| 142 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreen.itemPermission); |
| 143 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.props', expectedCurrentScreen.props); |
| 144 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 145 | 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; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 199 | const LMVersion = VersionFactory.build(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 200 | 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}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 220 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-license-models/?versionFilter=Certified'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 221 | expect(data).toEqual(undefined); |
| 222 | expect(options).toEqual(undefined); |
| 223 | return {results: []}; |
| 224 | }); |
| 225 | |
| 226 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 227 | 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}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 234 | 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}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 248 | 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}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 255 | 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 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 268 | return SoftwareProductActionHelper.loadSoftwareProductDetailsData(store.dispatch, {licenseModelId, licensingVersion: LMVersion.id}).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 269 | 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, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 273 | {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 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 280 | }); |
| 281 | }); |
| 282 | |
| 283 | it('Save Software product', () => { |
| 284 | |
| 285 | const softwareProduct = VSPEditorFactoryWithLicensingData.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 286 | deepFreeze(softwareProduct); |
| 287 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 288 | const version = VersionFactory.build(); |
| 289 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 290 | const store = storeCreator({ |
| 291 | softwareProduct: { |
| 292 | softwareProductEditor: {data: softwareProduct}, |
| 293 | softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}} |
| 294 | } |
| 295 | }); |
| 296 | deepFreeze(store.getState()); |
| 297 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 298 | const dataForUpdate = { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 299 | name: 'VSP5_UPDATED', |
| 300 | description: 'A software model for Fortigate._UPDATED' |
| 301 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 302 | |
| 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 309 | deepFreeze(softwareProductUpdateData); |
| 310 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 311 | const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', [softwareProductPutRequest]); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 312 | const questionnaireData = { |
| 313 | general: { |
| 314 | affinityData: { |
| 315 | affinityGrouping: true, |
| 316 | antiAffinityGrouping: false |
| 317 | } |
| 318 | } |
| 319 | }; |
| 320 | deepFreeze(questionnaireData); |
| 321 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 322 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 323 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${version.id}`); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 324 | expect(data).toEqual(softwareProductUpdateData); |
| 325 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 326 | return {returnCode: 'OK'}; |
| 327 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 328 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 329 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${version.id}/questionnaire`); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 330 | expect(data).toEqual(questionnaireData); |
| 331 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 332 | return {returnCode: 'OK'}; |
| 333 | }); |
| 334 | |
| 335 | return SoftwareProductActionHelper.updateSoftwareProduct(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 336 | softwareProduct: softwareProductPutRequest, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 337 | qdata: questionnaireData, |
| 338 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 339 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 340 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 341 | }); |
| 342 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 343 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 344 | it('Save Software product data only', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 345 | |
| 346 | const softwareProduct = VSPEditorFactoryWithLicensingData.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 347 | deepFreeze(softwareProduct); |
| 348 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 349 | const version = VersionFactory.build(); |
| 350 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 351 | 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 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 360 | const dataForUpdate = { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 361 | name: 'VSP5_UPDATED', |
| 362 | description: 'A software model for Fortigate._UPDATED' |
| 363 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 364 | |
| 365 | const toBeUpdatedSoftwareProductId = softwareProduct.id; |
| 366 | let softwareProductUpdateData = VSPEditorPostFactoryWithLicensingData.build(dataForUpdate); |
| 367 | delete softwareProductUpdateData.version; |
| 368 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 369 | const softwareProductPutRequest = buildFromExistingObject(VSPEditorFactoryWithLicensingData, softwareProductUpdateData, {id: toBeUpdatedSoftwareProductId}); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 370 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 371 | deepFreeze(softwareProductUpdateData); |
| 372 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 373 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 374 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${version.id}`); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 375 | expect(data).toEqual(softwareProductUpdateData); |
| 376 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 377 | return {returnCode: 'OK'}; |
| 378 | }); |
| 379 | |
| 380 | return SoftwareProductActionHelper.updateSoftwareProductData(store.dispatch, { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 381 | softwareProduct: softwareProductPutRequest, |
| 382 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 383 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 384 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 385 | }); |
| 386 | }); |
| 387 | |
| 388 | it('Save Software product questionnaire only', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 389 | const softwareProduct = VSPEditorFactoryWithLicensingData.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 390 | deepFreeze(softwareProduct); |
| 391 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 392 | const version = VersionFactory.build(); |
| 393 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 394 | 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 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 414 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 415 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/versions/${version.id}/questionnaire`); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 416 | expect(data).toEqual(questionnaireData); |
| 417 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 418 | return {returnCode: 'OK'}; |
| 419 | }); |
| 420 | |
| 421 | return SoftwareProductActionHelper.updateSoftwareProductQuestionnaire(store.dispatch, { |
| 422 | softwareProductId: softwareProduct.id, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 423 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 424 | qdata: questionnaireData |
| 425 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 426 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 427 | }); |
| 428 | }); |
| 429 | |
| 430 | it('Handle category without subcategories', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 431 | |
| 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 438 | }); |
| 439 | |
| 440 | }); |