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'; |
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 () { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 38 | it('Get Software Products List', () => { |
| 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 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 60 | return SoftwareProductActionHelper.fetchSoftwareProductList(store.dispatch).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 61 | return SoftwareProductActionHelper.fetchFinalizedSoftwareProductList(store.dispatch); |
| 62 | }).then(() => { |
| 63 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 64 | }); |
| 65 | }); |
| 66 | |
| 67 | it('Add Software Product', () => { |
| 68 | const store = storeCreator(); |
| 69 | deepFreeze(store.getState()); |
| 70 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 71 | const softwareProductPostRequest = VSPEditorPostFactory.build(); |
| 72 | deepFreeze(softwareProductPostRequest); |
| 73 | const idFromResponse = '1'; |
| 74 | const expectedVSP = VSPEditorPostFactory.build({id: idFromResponse, vendorId: softwareProductPostRequest.vendorId}); |
| 75 | deepFreeze(expectedVSP); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 76 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 77 | mockRest.addHandler('post', ({options, data, baseUrl}) => { |
| 78 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/'); |
| 79 | expect(data).toEqual(softwareProductPostRequest); |
| 80 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 81 | return { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 82 | vspId: idFromResponse |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 83 | }; |
| 84 | }); |
| 85 | |
| 86 | return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 87 | softwareProduct: softwareProductPostRequest |
| 88 | }).then((response) => { |
| 89 | expect(response.vspId).toEqual(idFromResponse); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 90 | }); |
| 91 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 92 | |
| 93 | it('Fetch Software Product with manifest', () => { |
| 94 | const store = storeCreator(); |
| 95 | deepFreeze(store.getState()); |
| 96 | |
| 97 | const softwareProductPostRequest = VSPEditorPostFactory.build(); |
| 98 | deepFreeze(softwareProductPostRequest); |
| 99 | |
| 100 | const expectedGenericInfo = { |
| 101 | 'name': { |
| 102 | isValid: true, |
| 103 | errorText: '', |
| 104 | validations: [{type: 'validateName', data: true}, {type: 'maxLength', data: 25}, { |
| 105 | type: 'required', |
| 106 | data: true |
| 107 | }] |
| 108 | }, |
| 109 | 'description': { |
| 110 | isValid: true, |
| 111 | errorText: '', |
| 112 | validations: [{type: 'required', data: true}] |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 113 | } |
| 114 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 115 | const expectedFormName = forms.VENDOR_SOFTWARE_PRODUCT_DETAILS; |
| 116 | |
| 117 | const idFromResponse = '1'; |
| 118 | const version = { id: '0.1', label: '0.1'}; |
| 119 | const expectedVSP = VSPEditorPostFactory.build({id: idFromResponse, vendorId: softwareProductPostRequest.vendorId}); |
| 120 | deepFreeze(expectedVSP); |
| 121 | let expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductEditor.data', expectedVSP); |
| 122 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.genericFieldInfo', expectedGenericInfo); |
| 123 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.formName', expectedFormName); |
| 124 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductQuestionnaire', {qdata: {}, dataMap: {}, qgenericFieldInfo: {}}); |
| 125 | |
| 126 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductAttachments.heatValidation', { |
| 127 | 'attachmentsTree': {}, |
| 128 | 'errorList': [], |
| 129 | 'selectedNode': 'All' |
| 130 | }); |
| 131 | let manifest = heatSetupManifest.build(); |
| 132 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductAttachments.heatSetup', manifest); |
| 133 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 134 | const expectedCurrentScreen = InitializedCurrentScreenFactory.build(); |
| 135 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreen.itemPermission); |
| 136 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.props', expectedCurrentScreen.props); |
| 137 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 138 | mockRest.addHandler('post', ({options, data, baseUrl}) => { |
| 139 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/'); |
| 140 | expect(data).toEqual(softwareProductPostRequest); |
| 141 | expect(options).toEqual(undefined); |
| 142 | return { |
| 143 | vspId: idFromResponse, |
| 144 | version |
| 145 | }; |
| 146 | }); |
| 147 | |
| 148 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 149 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}`); |
| 150 | expect(data).toEqual(undefined); |
| 151 | expect(options).toEqual(undefined); |
| 152 | return expectedVSP; |
| 153 | }); |
| 154 | |
| 155 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 156 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}/questionnaire`); |
| 157 | expect(data).toEqual(undefined); |
| 158 | expect(options).toEqual(undefined); |
| 159 | return {data: JSON.stringify({}), schema: JSON.stringify({})}; |
| 160 | }); |
| 161 | |
| 162 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 163 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}/orchestration-template-candidate/manifest`); |
| 164 | expect(data).toEqual(undefined); |
| 165 | expect(options).toEqual(undefined); |
| 166 | return manifest; |
| 167 | }); |
| 168 | |
| 169 | return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, { |
| 170 | softwareProduct: softwareProductPostRequest |
| 171 | }).then(() => { |
| 172 | return SoftwareProductActionHelper.fetchSoftwareProduct(store.dispatch, {softwareProductId: idFromResponse, version}); |
| 173 | }).then(() => { |
| 174 | return SoftwareProductActionHelper.loadSoftwareProductHeatCandidate(store.dispatch, {softwareProductId: idFromResponse, version}); |
| 175 | }).then(() => { |
| 176 | expect(store.getState()).toEqual(expectedStore); |
| 177 | let newName = 'newName'; |
| 178 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.formReady', null); |
| 179 | ValidationHelper.dataChanged(store.dispatch, {deltaData: {'name': newName}, formName: forms.VENDOR_SOFTWARE_PRODUCT_DETAILS}); |
| 180 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.data.name', newName); |
| 181 | expect(store.getState()).toEqual(expectedStore); |
| 182 | }); |
| 183 | }); |
| 184 | |
| 185 | it('Load and edit Software Product licensing data', () => { |
| 186 | const store = storeCreator(); |
| 187 | |
| 188 | const softwareProductPostRequest = VSPEditorPostFactory.build(); |
| 189 | deepFreeze(softwareProductPostRequest); |
| 190 | |
| 191 | const licenseModelId = softwareProductPostRequest.vendorId; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 192 | const LMVersion = VersionFactory.build(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 193 | const secondLicenseModelId = 'secondLicenseModelId'; |
| 194 | |
| 195 | let FG1 = FeatureGroup.build(); |
| 196 | let LA1 = LicenseAgreement.build({ |
| 197 | featureGroupsIds: [FG1.id] |
| 198 | }); |
| 199 | |
| 200 | let FG2 = FeatureGroup.build(); |
| 201 | let LA2 = LicenseAgreement.build({ |
| 202 | featureGroupsIds: [FG2.id] |
| 203 | }); |
| 204 | |
| 205 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 206 | expect(baseUrl).toEqual('/sdc1/feProxy/rest/v1/categories/resources/'); |
| 207 | expect(data).toEqual(undefined); |
| 208 | expect(options).toEqual(undefined); |
| 209 | return []; |
| 210 | }); |
| 211 | |
| 212 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 213 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-license-models/?versionFilter=Certified'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 214 | expect(data).toEqual(undefined); |
| 215 | expect(options).toEqual(undefined); |
| 216 | return {results: []}; |
| 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/items/${licenseModelId}/versions/${LMVersion.id}`); |
| 221 | expect(data).toEqual(undefined); |
| 222 | expect(options).toEqual(undefined); |
| 223 | return {results: {}}; |
| 224 | }); |
| 225 | |
| 226 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 227 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModelId}/versions/${LMVersion.id}/license-agreements`); |
| 228 | expect(data).toEqual(undefined); |
| 229 | expect(options).toEqual(undefined); |
| 230 | return {results: [LA1]}; |
| 231 | }); |
| 232 | |
| 233 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 234 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModelId}/versions/${LMVersion.id}/feature-groups`); |
| 235 | expect(data).toEqual(undefined); |
| 236 | expect(options).toEqual(undefined); |
| 237 | return {results: [FG1]}; |
| 238 | }); |
| 239 | |
| 240 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 241 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${secondLicenseModelId}/versions/${LMVersion.id}`); |
| 242 | expect(data).toEqual(undefined); |
| 243 | expect(options).toEqual(undefined); |
| 244 | return {results: {}}; |
| 245 | }); |
| 246 | |
| 247 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 248 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${secondLicenseModelId}/versions/${LMVersion.id}/license-agreements`); |
| 249 | expect(data).toEqual(undefined); |
| 250 | expect(options).toEqual(undefined); |
| 251 | return {results: [LA2]}; |
| 252 | }); |
| 253 | |
| 254 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 255 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${secondLicenseModelId}/versions/${LMVersion.id}/feature-groups`); |
| 256 | expect(data).toEqual(undefined); |
| 257 | expect(options).toEqual(undefined); |
| 258 | return {results: [FG2]}; |
| 259 | }); |
| 260 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 261 | return SoftwareProductActionHelper.loadSoftwareProductDetailsData(store.dispatch, {licenseModelId, licensingVersion: LMVersion.id}).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 262 | let state = store.getState(); |
| 263 | expect(state.licenseModel.licenseAgreement.licenseAgreementList).toEqual([LA1]); |
| 264 | expect(state.licenseModel.featureGroup.featureGroupsList).toEqual([FG1]); |
| 265 | return SoftwareProductActionHelper.softwareProductEditorVendorChanged(store.dispatch, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 266 | {deltaData: {vendorId: secondLicenseModelId, licensingVersion: LMVersion.id}, |
| 267 | formName: forms.VENDOR_SOFTWARE_PRODUCT_DETAILS} |
| 268 | ).then(() => { |
| 269 | let state = store.getState(); |
| 270 | expect(state.licenseModel.licenseAgreement.licenseAgreementList).toEqual([LA2]); |
| 271 | expect(state.licenseModel.featureGroup.featureGroupsList).toEqual([FG2]); |
| 272 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 273 | }); |
| 274 | }); |
| 275 | |
| 276 | it('Save Software product', () => { |
| 277 | |
| 278 | const softwareProduct = VSPEditorFactoryWithLicensingData.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 279 | deepFreeze(softwareProduct); |
| 280 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 281 | const version = VersionFactory.build(); |
| 282 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 283 | const store = storeCreator({ |
| 284 | softwareProduct: { |
| 285 | softwareProductEditor: {data: softwareProduct}, |
| 286 | softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}} |
| 287 | } |
| 288 | }); |
| 289 | deepFreeze(store.getState()); |
| 290 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 291 | const dataForUpdate = { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 292 | name: 'VSP5_UPDATED', |
| 293 | description: 'A software model for Fortigate._UPDATED' |
| 294 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 295 | |
| 296 | const toBeUpdatedSoftwareProductId = softwareProduct.id; |
| 297 | let softwareProductUpdateData = VSPEditorPostFactoryWithLicensingData.build(dataForUpdate); |
| 298 | delete softwareProductUpdateData.version; |
| 299 | |
| 300 | const softwareProductPutRequest = buildFromExistingObject(VSPEditorFactoryWithLicensingData, softwareProductUpdateData, {id: toBeUpdatedSoftwareProductId, version: softwareProduct.version}); |
| 301 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 302 | deepFreeze(softwareProductUpdateData); |
| 303 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 304 | const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', [softwareProductPutRequest]); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 305 | const questionnaireData = { |
| 306 | general: { |
| 307 | affinityData: { |
| 308 | affinityGrouping: true, |
| 309 | antiAffinityGrouping: false |
| 310 | } |
| 311 | } |
| 312 | }; |
| 313 | deepFreeze(questionnaireData); |
| 314 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 315 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 316 | 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] | 317 | expect(data).toEqual(softwareProductUpdateData); |
| 318 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 319 | return {returnCode: 'OK'}; |
| 320 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 321 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 322 | 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] | 323 | expect(data).toEqual(questionnaireData); |
| 324 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 325 | return {returnCode: 'OK'}; |
| 326 | }); |
| 327 | |
| 328 | return SoftwareProductActionHelper.updateSoftwareProduct(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 329 | softwareProduct: softwareProductPutRequest, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 330 | qdata: questionnaireData, |
| 331 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 332 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 333 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 334 | }); |
| 335 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 336 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 337 | it('Save Software product data only', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 338 | |
| 339 | const softwareProduct = VSPEditorFactoryWithLicensingData.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 340 | deepFreeze(softwareProduct); |
| 341 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 342 | const version = VersionFactory.build(); |
| 343 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 344 | const store = storeCreator({ |
| 345 | softwareProduct: { |
| 346 | softwareProductEditor: {data: softwareProduct}, |
| 347 | softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}} |
| 348 | } |
| 349 | }); |
| 350 | deepFreeze(store.getState()); |
| 351 | const expectedStore = store.getState(); |
| 352 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 353 | const dataForUpdate = { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 354 | name: 'VSP5_UPDATED', |
| 355 | description: 'A software model for Fortigate._UPDATED' |
| 356 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 357 | |
| 358 | const toBeUpdatedSoftwareProductId = softwareProduct.id; |
| 359 | let softwareProductUpdateData = VSPEditorPostFactoryWithLicensingData.build(dataForUpdate); |
| 360 | delete softwareProductUpdateData.version; |
| 361 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 362 | const softwareProductPutRequest = buildFromExistingObject(VSPEditorFactoryWithLicensingData, softwareProductUpdateData, {id: toBeUpdatedSoftwareProductId}); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 363 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 364 | deepFreeze(softwareProductUpdateData); |
| 365 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 366 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 367 | 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] | 368 | expect(data).toEqual(softwareProductUpdateData); |
| 369 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 370 | return {returnCode: 'OK'}; |
| 371 | }); |
| 372 | |
| 373 | return SoftwareProductActionHelper.updateSoftwareProductData(store.dispatch, { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 374 | softwareProduct: softwareProductPutRequest, |
| 375 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 376 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 377 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 378 | }); |
| 379 | }); |
| 380 | |
| 381 | it('Save Software product questionnaire only', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 382 | const softwareProduct = VSPEditorFactoryWithLicensingData.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 383 | deepFreeze(softwareProduct); |
| 384 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 385 | const version = VersionFactory.build(); |
| 386 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 387 | const store = storeCreator({ |
| 388 | softwareProduct: { |
| 389 | softwareProductEditor: {data: softwareProduct}, |
| 390 | softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}} |
| 391 | } |
| 392 | }); |
| 393 | deepFreeze(store.getState()); |
| 394 | const expectedStore = store.getState(); |
| 395 | |
| 396 | const toBeUpdatedSoftwareProductId = softwareProduct.id; |
| 397 | const questionnaireData = { |
| 398 | general: { |
| 399 | affinityData: { |
| 400 | affinityGrouping: true, |
| 401 | antiAffinityGrouping: false |
| 402 | } |
| 403 | } |
| 404 | }; |
| 405 | deepFreeze(questionnaireData); |
| 406 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 407 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 408 | 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] | 409 | expect(data).toEqual(questionnaireData); |
| 410 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 411 | return {returnCode: 'OK'}; |
| 412 | }); |
| 413 | |
| 414 | return SoftwareProductActionHelper.updateSoftwareProductQuestionnaire(store.dispatch, { |
| 415 | softwareProductId: softwareProduct.id, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 416 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 417 | qdata: questionnaireData |
| 418 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 419 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 420 | }); |
| 421 | }); |
| 422 | |
| 423 | it('Handle category without subcategories', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 424 | |
| 425 | const categories = CategoryFactory.buildList(3); |
| 426 | categories[0].subcategories = CategoryFactory.buildList(3); |
| 427 | categories[2].subcategories = CategoryFactory.buildList(3); |
| 428 | |
| 429 | const category = SoftwareProductCategoriesHelper.getCurrentCategoryOfSubCategory(categories[2].subcategories[2].uniqueId, categories); |
| 430 | expect(category).toEqual(categories[2].uniqueId); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 431 | }); |
| 432 | |
| 433 | }); |