svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
andre.schmid | 36fa9cd | 2021-07-22 11:54:07 +0100 | [diff] [blame] | 3 | * Modifications Copyright (C) 2021 Nordix Foundation. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 4 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 8 | * |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 10 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 17 | import deepFreeze from 'deep-freeze'; |
| 18 | import mockRest from 'test-utils/MockRest.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 19 | import {cloneAndSet, buildFromExistingObject} from 'test-utils/Util.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 20 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 21 | |
| 22 | import SoftwareProductCreationActionHelper from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationActionHelper.js'; |
| 23 | import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js'; |
| 24 | import SoftwareProductCategoriesHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductCategoriesHelper.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 25 | import {forms} from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js'; |
| 26 | import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js'; |
| 27 | |
| 28 | import {VSPEditorFactory, VSPEditorPostFactory, VSPEditorFactoryWithLicensingData, VSPEditorPostFactoryWithLicensingData} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js'; |
| 29 | import {CategoryFactory} from 'test-utils/factories/softwareProduct/VSPCategoriesFactory.js'; |
| 30 | import {heatSetupManifest} from 'test-utils/factories/softwareProduct/SoftwareProductAttachmentsFactories.js'; |
| 31 | |
| 32 | import { FeatureGroupStoreFactory as FeatureGroup} from 'test-utils/factories/licenseModel/FeatureGroupFactories.js'; |
| 33 | import {LicenseAgreementStoreFactory as LicenseAgreement} from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 34 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 35 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
| 36 | import {InitializedCurrentScreenFactory} from 'test-utils/factories/common/CurrentScreenFactory.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 37 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 38 | describe('Software Product Details Module Tests', function () { |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 39 | it('Get Software Products List', async () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 40 | const store = storeCreator(); |
| 41 | deepFreeze(store.getState()); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 42 | const softwareProductList = VSPEditorFactory.buildList(2); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 43 | deepFreeze(softwareProductList); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 44 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 45 | const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', softwareProductList); |
| 46 | |
| 47 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 48 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/?versionFilter=Draft'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 49 | expect(data).toEqual(undefined); |
| 50 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 51 | return {results: softwareProductList}; |
| 52 | }); |
| 53 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 54 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 55 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/?versionFilter=Certified'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 56 | expect(data).toEqual(undefined); |
| 57 | expect(options).toEqual(undefined); |
| 58 | return {results: []}; |
| 59 | }); |
| 60 | |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 61 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 62 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/?Status=ARCHIVED'); |
| 63 | expect(data).toEqual(undefined); |
| 64 | expect(options).toEqual(undefined); |
| 65 | return {results: []}; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 66 | }); |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 67 | |
| 68 | await SoftwareProductActionHelper.fetchSoftwareProductList(store.dispatch); |
| 69 | await SoftwareProductActionHelper.fetchFinalizedSoftwareProductList(store.dispatch); |
| 70 | await SoftwareProductActionHelper.fetchArchivedSoftwareProductList(store.dispatch); |
aribeiro | cba52c9 | 2021-07-12 15:10:19 +0100 | [diff] [blame] | 71 | |
| 72 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 73 | }); |
| 74 | |
| 75 | it('Add Software Product', () => { |
| 76 | const store = storeCreator(); |
| 77 | deepFreeze(store.getState()); |
| 78 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 79 | const softwareProductPostRequest = VSPEditorPostFactory.build(); |
| 80 | deepFreeze(softwareProductPostRequest); |
| 81 | const idFromResponse = '1'; |
| 82 | const expectedVSP = VSPEditorPostFactory.build({id: idFromResponse, vendorId: softwareProductPostRequest.vendorId}); |
| 83 | deepFreeze(expectedVSP); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 84 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 85 | mockRest.addHandler('post', ({options, data, baseUrl}) => { |
| 86 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/'); |
| 87 | expect(data).toEqual(softwareProductPostRequest); |
| 88 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 89 | return { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 90 | vspId: idFromResponse |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 91 | }; |
| 92 | }); |
| 93 | |
| 94 | return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 95 | softwareProduct: softwareProductPostRequest |
| 96 | }).then((response) => { |
| 97 | expect(response.vspId).toEqual(idFromResponse); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 98 | }); |
| 99 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 100 | |
| 101 | it('Fetch Software Product with manifest', () => { |
| 102 | const store = storeCreator(); |
| 103 | deepFreeze(store.getState()); |
| 104 | |
| 105 | const softwareProductPostRequest = VSPEditorPostFactory.build(); |
| 106 | deepFreeze(softwareProductPostRequest); |
| 107 | |
| 108 | const expectedGenericInfo = { |
| 109 | 'name': { |
| 110 | isValid: true, |
| 111 | errorText: '', |
| 112 | validations: [{type: 'validateName', data: true}, {type: 'maxLength', data: 25}, { |
| 113 | type: 'required', |
| 114 | data: true |
| 115 | }] |
| 116 | }, |
| 117 | 'description': { |
| 118 | isValid: true, |
| 119 | errorText: '', |
aribeiro | cba52c9 | 2021-07-12 15:10:19 +0100 | [diff] [blame] | 120 | validations: [{type: 'validateName', data: true}, {type: 'required', data: true}] |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 121 | } |
| 122 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 123 | const expectedFormName = forms.VENDOR_SOFTWARE_PRODUCT_DETAILS; |
| 124 | |
| 125 | const idFromResponse = '1'; |
| 126 | const version = { id: '0.1', label: '0.1'}; |
| 127 | const expectedVSP = VSPEditorPostFactory.build({id: idFromResponse, vendorId: softwareProductPostRequest.vendorId}); |
| 128 | deepFreeze(expectedVSP); |
| 129 | let expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductEditor.data', expectedVSP); |
| 130 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.genericFieldInfo', expectedGenericInfo); |
| 131 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.formName', expectedFormName); |
| 132 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductQuestionnaire', {qdata: {}, dataMap: {}, qgenericFieldInfo: {}}); |
| 133 | |
| 134 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductAttachments.heatValidation', { |
| 135 | 'attachmentsTree': {}, |
| 136 | 'errorList': [], |
| 137 | 'selectedNode': 'All' |
| 138 | }); |
| 139 | let manifest = heatSetupManifest.build(); |
| 140 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductAttachments.heatSetup', manifest); |
| 141 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 142 | const expectedCurrentScreen = InitializedCurrentScreenFactory.build(); |
| 143 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.itemPermission', expectedCurrentScreen.itemPermission); |
| 144 | expectedStore = cloneAndSet(expectedStore, 'currentScreen.props', expectedCurrentScreen.props); |
| 145 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 146 | mockRest.addHandler('post', ({options, data, baseUrl}) => { |
| 147 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-software-products/'); |
| 148 | expect(data).toEqual(softwareProductPostRequest); |
| 149 | expect(options).toEqual(undefined); |
| 150 | return { |
| 151 | vspId: idFromResponse, |
| 152 | version |
| 153 | }; |
| 154 | }); |
| 155 | |
| 156 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 157 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}`); |
| 158 | expect(data).toEqual(undefined); |
| 159 | expect(options).toEqual(undefined); |
| 160 | return expectedVSP; |
| 161 | }); |
| 162 | |
| 163 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 164 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}/questionnaire`); |
| 165 | expect(data).toEqual(undefined); |
| 166 | expect(options).toEqual(undefined); |
| 167 | return {data: JSON.stringify({}), schema: JSON.stringify({})}; |
| 168 | }); |
| 169 | |
| 170 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 171 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${idFromResponse}/versions/${version.id}/orchestration-template-candidate/manifest`); |
| 172 | expect(data).toEqual(undefined); |
| 173 | expect(options).toEqual(undefined); |
| 174 | return manifest; |
| 175 | }); |
| 176 | |
| 177 | return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, { |
| 178 | softwareProduct: softwareProductPostRequest |
| 179 | }).then(() => { |
| 180 | return SoftwareProductActionHelper.fetchSoftwareProduct(store.dispatch, {softwareProductId: idFromResponse, version}); |
| 181 | }).then(() => { |
| 182 | return SoftwareProductActionHelper.loadSoftwareProductHeatCandidate(store.dispatch, {softwareProductId: idFromResponse, version}); |
| 183 | }).then(() => { |
| 184 | expect(store.getState()).toEqual(expectedStore); |
| 185 | let newName = 'newName'; |
| 186 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.formReady', null); |
| 187 | ValidationHelper.dataChanged(store.dispatch, {deltaData: {'name': newName}, formName: forms.VENDOR_SOFTWARE_PRODUCT_DETAILS}); |
| 188 | expectedStore = cloneAndSet(expectedStore, 'softwareProduct.softwareProductEditor.data.name', newName); |
| 189 | expect(store.getState()).toEqual(expectedStore); |
| 190 | }); |
| 191 | }); |
| 192 | |
| 193 | it('Load and edit Software Product licensing data', () => { |
| 194 | const store = storeCreator(); |
| 195 | |
| 196 | const softwareProductPostRequest = VSPEditorPostFactory.build(); |
| 197 | deepFreeze(softwareProductPostRequest); |
| 198 | |
| 199 | const licenseModelId = softwareProductPostRequest.vendorId; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 200 | const LMVersion = VersionFactory.build(); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 201 | const secondLicenseModelId = 'secondLicenseModelId'; |
| 202 | |
| 203 | let FG1 = FeatureGroup.build(); |
| 204 | let LA1 = LicenseAgreement.build({ |
| 205 | featureGroupsIds: [FG1.id] |
| 206 | }); |
| 207 | |
| 208 | let FG2 = FeatureGroup.build(); |
| 209 | let LA2 = LicenseAgreement.build({ |
| 210 | featureGroupsIds: [FG2.id] |
| 211 | }); |
| 212 | |
| 213 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 214 | expect(baseUrl).toEqual('/sdc1/feProxy/rest/v1/categories/resources/'); |
| 215 | expect(data).toEqual(undefined); |
| 216 | expect(options).toEqual(undefined); |
| 217 | return []; |
| 218 | }); |
| 219 | |
| 220 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
andre.schmid | 36fa9cd | 2021-07-22 11:54:07 +0100 | [diff] [blame] | 221 | expect(baseUrl).toEqual('/sdc1/feProxy/rest/v1/catalog/model/'); |
| 222 | expect(data).toEqual(undefined); |
| 223 | expect(options).toEqual(undefined); |
| 224 | return []; |
| 225 | }); |
| 226 | |
| 227 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 228 | expect(baseUrl).toEqual('/onboarding-api/v1.0/vendor-license-models/?versionFilter=Certified'); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 229 | expect(data).toEqual(undefined); |
| 230 | expect(options).toEqual(undefined); |
| 231 | return {results: []}; |
| 232 | }); |
| 233 | |
| 234 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 235 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${licenseModelId}/versions/${LMVersion.id}`); |
| 236 | expect(data).toEqual(undefined); |
| 237 | expect(options).toEqual(undefined); |
| 238 | return {results: {}}; |
| 239 | }); |
| 240 | |
| 241 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 242 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModelId}/versions/${LMVersion.id}/license-agreements`); |
| 243 | expect(data).toEqual(undefined); |
| 244 | expect(options).toEqual(undefined); |
| 245 | return {results: [LA1]}; |
| 246 | }); |
| 247 | |
| 248 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 249 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${licenseModelId}/versions/${LMVersion.id}/feature-groups`); |
| 250 | expect(data).toEqual(undefined); |
| 251 | expect(options).toEqual(undefined); |
| 252 | return {results: [FG1]}; |
| 253 | }); |
| 254 | |
| 255 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 256 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/items/${secondLicenseModelId}/versions/${LMVersion.id}`); |
| 257 | expect(data).toEqual(undefined); |
| 258 | expect(options).toEqual(undefined); |
| 259 | return {results: {}}; |
| 260 | }); |
| 261 | |
| 262 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 263 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${secondLicenseModelId}/versions/${LMVersion.id}/license-agreements`); |
| 264 | expect(data).toEqual(undefined); |
| 265 | expect(options).toEqual(undefined); |
| 266 | return {results: [LA2]}; |
| 267 | }); |
| 268 | |
| 269 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 270 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${secondLicenseModelId}/versions/${LMVersion.id}/feature-groups`); |
| 271 | expect(data).toEqual(undefined); |
| 272 | expect(options).toEqual(undefined); |
| 273 | return {results: [FG2]}; |
| 274 | }); |
| 275 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 276 | return SoftwareProductActionHelper.loadSoftwareProductDetailsData(store.dispatch, {licenseModelId, licensingVersion: LMVersion.id}).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 277 | let state = store.getState(); |
| 278 | expect(state.licenseModel.licenseAgreement.licenseAgreementList).toEqual([LA1]); |
| 279 | expect(state.licenseModel.featureGroup.featureGroupsList).toEqual([FG1]); |
| 280 | return SoftwareProductActionHelper.softwareProductEditorVendorChanged(store.dispatch, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 281 | {deltaData: {vendorId: secondLicenseModelId, licensingVersion: LMVersion.id}, |
| 282 | formName: forms.VENDOR_SOFTWARE_PRODUCT_DETAILS} |
| 283 | ).then(() => { |
| 284 | let state = store.getState(); |
| 285 | expect(state.licenseModel.licenseAgreement.licenseAgreementList).toEqual([LA2]); |
| 286 | expect(state.licenseModel.featureGroup.featureGroupsList).toEqual([FG2]); |
| 287 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 288 | }); |
| 289 | }); |
| 290 | |
| 291 | it('Save Software product', () => { |
| 292 | |
| 293 | const softwareProduct = VSPEditorFactoryWithLicensingData.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 294 | deepFreeze(softwareProduct); |
| 295 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 296 | const version = VersionFactory.build(); |
| 297 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 298 | const store = storeCreator({ |
| 299 | softwareProduct: { |
| 300 | softwareProductEditor: {data: softwareProduct}, |
| 301 | softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}} |
| 302 | } |
| 303 | }); |
| 304 | deepFreeze(store.getState()); |
| 305 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 306 | const dataForUpdate = { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 307 | name: 'VSP5_UPDATED', |
| 308 | description: 'A software model for Fortigate._UPDATED' |
| 309 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 310 | |
| 311 | const toBeUpdatedSoftwareProductId = softwareProduct.id; |
| 312 | let softwareProductUpdateData = VSPEditorPostFactoryWithLicensingData.build(dataForUpdate); |
| 313 | delete softwareProductUpdateData.version; |
| 314 | |
| 315 | const softwareProductPutRequest = buildFromExistingObject(VSPEditorFactoryWithLicensingData, softwareProductUpdateData, {id: toBeUpdatedSoftwareProductId, version: softwareProduct.version}); |
| 316 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 317 | deepFreeze(softwareProductUpdateData); |
| 318 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 319 | const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', [softwareProductPutRequest]); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 320 | const questionnaireData = { |
| 321 | general: { |
| 322 | affinityData: { |
| 323 | affinityGrouping: true, |
| 324 | antiAffinityGrouping: false |
| 325 | } |
| 326 | } |
| 327 | }; |
| 328 | deepFreeze(questionnaireData); |
| 329 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 330 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 331 | 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] | 332 | expect(data).toEqual(softwareProductUpdateData); |
| 333 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 334 | return {returnCode: 'OK'}; |
| 335 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 336 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 337 | 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] | 338 | expect(data).toEqual(questionnaireData); |
| 339 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 340 | return {returnCode: 'OK'}; |
| 341 | }); |
| 342 | |
| 343 | return SoftwareProductActionHelper.updateSoftwareProduct(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 344 | softwareProduct: softwareProductPutRequest, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 345 | qdata: questionnaireData, |
| 346 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 347 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 348 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 349 | }); |
| 350 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 351 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 352 | it('Save Software product data only', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 353 | |
| 354 | const softwareProduct = VSPEditorFactoryWithLicensingData.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 355 | deepFreeze(softwareProduct); |
| 356 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 357 | const version = VersionFactory.build(); |
| 358 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 368 | const dataForUpdate = { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 369 | name: 'VSP5_UPDATED', |
| 370 | description: 'A software model for Fortigate._UPDATED' |
| 371 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 372 | |
| 373 | const toBeUpdatedSoftwareProductId = softwareProduct.id; |
| 374 | let softwareProductUpdateData = VSPEditorPostFactoryWithLicensingData.build(dataForUpdate); |
| 375 | delete softwareProductUpdateData.version; |
| 376 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 377 | const softwareProductPutRequest = buildFromExistingObject(VSPEditorFactoryWithLicensingData, softwareProductUpdateData, {id: toBeUpdatedSoftwareProductId}); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 378 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 379 | deepFreeze(softwareProductUpdateData); |
| 380 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 381 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 382 | 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] | 383 | expect(data).toEqual(softwareProductUpdateData); |
| 384 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 385 | return {returnCode: 'OK'}; |
| 386 | }); |
| 387 | |
| 388 | return SoftwareProductActionHelper.updateSoftwareProductData(store.dispatch, { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 389 | softwareProduct: softwareProductPutRequest, |
| 390 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 391 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 392 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 393 | }); |
| 394 | }); |
| 395 | |
| 396 | it('Save Software product questionnaire only', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 397 | const softwareProduct = VSPEditorFactoryWithLicensingData.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 398 | deepFreeze(softwareProduct); |
| 399 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 400 | const version = VersionFactory.build(); |
| 401 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 402 | const store = storeCreator({ |
| 403 | softwareProduct: { |
| 404 | softwareProductEditor: {data: softwareProduct}, |
| 405 | softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}} |
| 406 | } |
| 407 | }); |
| 408 | deepFreeze(store.getState()); |
| 409 | const expectedStore = store.getState(); |
| 410 | |
| 411 | const toBeUpdatedSoftwareProductId = softwareProduct.id; |
| 412 | const questionnaireData = { |
| 413 | general: { |
| 414 | affinityData: { |
| 415 | affinityGrouping: true, |
| 416 | antiAffinityGrouping: false |
| 417 | } |
| 418 | } |
| 419 | }; |
| 420 | deepFreeze(questionnaireData); |
| 421 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 422 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 423 | 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] | 424 | expect(data).toEqual(questionnaireData); |
| 425 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 426 | return {returnCode: 'OK'}; |
| 427 | }); |
| 428 | |
| 429 | return SoftwareProductActionHelper.updateSoftwareProductQuestionnaire(store.dispatch, { |
| 430 | softwareProductId: softwareProduct.id, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 431 | version, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 432 | qdata: questionnaireData |
| 433 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 434 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 435 | }); |
| 436 | }); |
| 437 | |
| 438 | it('Handle category without subcategories', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 439 | |
| 440 | const categories = CategoryFactory.buildList(3); |
| 441 | categories[0].subcategories = CategoryFactory.buildList(3); |
| 442 | categories[2].subcategories = CategoryFactory.buildList(3); |
| 443 | |
| 444 | const category = SoftwareProductCategoriesHelper.getCurrentCategoryOfSubCategory(categories[2].subcategories[2].uniqueId, categories); |
| 445 | expect(category).toEqual(categories[2].uniqueId); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 446 | }); |
| 447 | |
| 448 | }); |