Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame^] | 1 | /*- |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * SDC |
| 4 | * ================================================================================ |
| 5 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 6 | * ================================================================================ |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * ============LICENSE_END========================================================= |
| 19 | */ |
| 20 | |
| 21 | import {expect} from 'chai'; |
| 22 | import deepFreeze from 'deep-freeze'; |
| 23 | import mockRest from 'test-utils/MockRest.js'; |
| 24 | import {cloneAndSet} from 'test-utils/Util.js'; |
| 25 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 26 | |
| 27 | import SoftwareProductCreationActionHelper from 'sdc-app/onboarding/softwareProduct/creation/SoftwareProductCreationActionHelper.js'; |
| 28 | import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js'; |
| 29 | import SoftwareProductCategoriesHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductCategoriesHelper.js'; |
| 30 | |
| 31 | describe('Software Product Module Tests', function () { |
| 32 | it('Get Software Products List', () => { |
| 33 | const store = storeCreator(); |
| 34 | deepFreeze(store.getState()); |
| 35 | |
| 36 | const softwareProductList = [ |
| 37 | { |
| 38 | name: 'VSP1', |
| 39 | description: 'hjhj', |
| 40 | version: '0.1', |
| 41 | id: 'EBADF561B7FA4A788075E1840D0B5971', |
| 42 | subCategory: 'resourceNewCategory.network connectivity.virtual links', |
| 43 | category: 'resourceNewCategory.network connectivity', |
| 44 | vendorId: '5259EDE4CC814DC9897BA6F69E2C971B', |
| 45 | vendorName: 'Vendor', |
| 46 | checkinStatus: 'CHECK_OUT', |
| 47 | licensingData: { |
| 48 | 'featureGroups': [] |
| 49 | } |
| 50 | }, |
| 51 | { |
| 52 | name: 'VSP2', |
| 53 | description: 'dfdfdfd', |
| 54 | version: '0.1', |
| 55 | id: '2F47447D22DB4C53B020CA1E66201EF2', |
| 56 | subCategory: 'resourceNewCategory.network connectivity.virtual links', |
| 57 | category: 'resourceNewCategory.network connectivity', |
| 58 | vendorId: '5259EDE4CC814DC9897BA6F69E2C971B', |
| 59 | vendorName: 'Vendor', |
| 60 | checkinStatus: 'CHECK_OUT', |
| 61 | licensingData: { |
| 62 | featureGroups: [] |
| 63 | } |
| 64 | } |
| 65 | ]; |
| 66 | |
| 67 | deepFreeze(softwareProductList); |
| 68 | |
| 69 | deepFreeze(store.getState()); |
| 70 | |
| 71 | const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', softwareProductList); |
| 72 | |
| 73 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
| 74 | expect(baseUrl).to.equal('/onboarding-api/v1.0/vendor-software-products/'); |
| 75 | expect(data).to.deep.equal(undefined); |
| 76 | expect(options).to.equal(undefined); |
| 77 | return {results: softwareProductList}; |
| 78 | }); |
| 79 | |
| 80 | return SoftwareProductActionHelper.fetchSoftwareProductList(store.dispatch).then(() => { |
| 81 | expect(store.getState()).to.deep.equal(expectedStore); |
| 82 | }); |
| 83 | }); |
| 84 | |
| 85 | it('Add Software Product', () => { |
| 86 | const store = storeCreator(); |
| 87 | deepFreeze(store.getState()); |
| 88 | |
| 89 | const softwareProductPostRequest = deepFreeze({ |
| 90 | name: 'vsp1', |
| 91 | description: 'string', |
| 92 | vendorId: '1', |
| 93 | vendorName: 'Vendor', |
| 94 | icon: 'icon', |
| 95 | subCategory: 'resourceNewCategory.network connectivity.virtual links', |
| 96 | category: 'resourceNewCategory.network connectivity', |
| 97 | licensingData: {} |
| 98 | }); |
| 99 | |
| 100 | const softwareProductToAdd = deepFreeze({ |
| 101 | ...softwareProductPostRequest |
| 102 | }); |
| 103 | |
| 104 | const softwareProductIdFromResponse = 'ADDED_ID'; |
| 105 | const softwareProductAfterAdd = deepFreeze({ |
| 106 | ...softwareProductToAdd, |
| 107 | id: softwareProductIdFromResponse |
| 108 | }); |
| 109 | |
| 110 | const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', [softwareProductAfterAdd]); |
| 111 | |
| 112 | mockRest.addHandler('create', ({options, data, baseUrl}) => { |
| 113 | expect(baseUrl).to.equal('/onboarding-api/v1.0/vendor-software-products/'); |
| 114 | expect(data).to.deep.equal(softwareProductPostRequest); |
| 115 | expect(options).to.equal(undefined); |
| 116 | return { |
| 117 | vspId: softwareProductIdFromResponse |
| 118 | }; |
| 119 | }); |
| 120 | |
| 121 | return SoftwareProductCreationActionHelper.createSoftwareProduct(store.dispatch, { |
| 122 | softwareProduct: softwareProductToAdd |
| 123 | }).then(() => { |
| 124 | expect(store.getState()).to.deep.equal(expectedStore); |
| 125 | }); |
| 126 | }); |
| 127 | it('Save Software product', () => { |
| 128 | const softwareProduct = { |
| 129 | name: 'VSP5', |
| 130 | id: '4730033D16C64E3CA556AB0AC4478218', |
| 131 | description: 'A software model for Fortigate.', |
| 132 | subCategory: 'resourceNewCategory.network connectivity.virtual links', |
| 133 | category: 'resourceNewCategory.network connectivity', |
| 134 | vendorId: '1', |
| 135 | vendorName: 'Vendor', |
| 136 | licensingVersion: '1.0', |
| 137 | icon: 'icon', |
| 138 | licensingData: { |
| 139 | licenceAgreement: '123', |
| 140 | featureGroups: [ |
| 141 | '123', '234' |
| 142 | ] |
| 143 | } |
| 144 | }; |
| 145 | deepFreeze(softwareProduct); |
| 146 | |
| 147 | const store = storeCreator({ |
| 148 | softwareProduct: { |
| 149 | softwareProductEditor: {data: softwareProduct}, |
| 150 | softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}} |
| 151 | } |
| 152 | }); |
| 153 | deepFreeze(store.getState()); |
| 154 | |
| 155 | const toBeUpdatedSoftwareProductId = softwareProduct.id; |
| 156 | const softwareProductUpdateData = { |
| 157 | ...softwareProduct, |
| 158 | name: 'VSP5_UPDATED', |
| 159 | description: 'A software model for Fortigate._UPDATED' |
| 160 | }; |
| 161 | deepFreeze(softwareProductUpdateData); |
| 162 | |
| 163 | const expectedStore = cloneAndSet(store.getState(), 'softwareProductList', [softwareProductUpdateData]); |
| 164 | const questionnaireData = { |
| 165 | general: { |
| 166 | affinityData: { |
| 167 | affinityGrouping: true, |
| 168 | antiAffinityGrouping: false |
| 169 | } |
| 170 | } |
| 171 | }; |
| 172 | deepFreeze(questionnaireData); |
| 173 | |
| 174 | mockRest.addHandler('save', ({data, options, baseUrl}) => { |
| 175 | const expectedData = { |
| 176 | name: 'VSP5_UPDATED', |
| 177 | description: 'A software model for Fortigate._UPDATED', |
| 178 | subCategory: 'resourceNewCategory.network connectivity.virtual links', |
| 179 | category: 'resourceNewCategory.network connectivity', |
| 180 | vendorId: '1', |
| 181 | vendorName: 'Vendor', |
| 182 | licensingVersion: '1.0', |
| 183 | icon: 'icon', |
| 184 | licensingData: { |
| 185 | licenceAgreement: '123', |
| 186 | featureGroups: [ |
| 187 | '123', '234' |
| 188 | ] |
| 189 | } |
| 190 | }; |
| 191 | expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}`); |
| 192 | expect(data).to.deep.equal(expectedData); |
| 193 | expect(options).to.equal(undefined); |
| 194 | return {returnCode: 'OK'}; |
| 195 | }); |
| 196 | mockRest.addHandler('save', ({data, options, baseUrl}) => { |
| 197 | expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/questionnaire`); |
| 198 | expect(data).to.deep.equal(questionnaireData); |
| 199 | expect(options).to.equal(undefined); |
| 200 | return {returnCode: 'OK'}; |
| 201 | }); |
| 202 | |
| 203 | return SoftwareProductActionHelper.updateSoftwareProduct(store.dispatch, { |
| 204 | softwareProduct: softwareProductUpdateData, |
| 205 | qdata: questionnaireData |
| 206 | }).then(() => { |
| 207 | expect(store.getState()).to.deep.equal(expectedStore); |
| 208 | }); |
| 209 | }); |
| 210 | it('Save Software product data only', () => { |
| 211 | const softwareProduct = { |
| 212 | name: 'VSP5', |
| 213 | id: '4730033D16C64E3CA556AB0AC4478218', |
| 214 | description: 'A software model for Fortigate.', |
| 215 | subCategory: 'resourceNewCategory.network connectivity.virtual links', |
| 216 | category: 'resourceNewCategory.network connectivity', |
| 217 | vendorId: '1', |
| 218 | vendorName: 'Vendor', |
| 219 | licensingVersion: '1.0', |
| 220 | icon: 'icon', |
| 221 | licensingData: { |
| 222 | licenceAgreement: '123', |
| 223 | featureGroups: [ |
| 224 | '123', '234' |
| 225 | ] |
| 226 | } |
| 227 | }; |
| 228 | deepFreeze(softwareProduct); |
| 229 | |
| 230 | const store = storeCreator({ |
| 231 | softwareProduct: { |
| 232 | softwareProductEditor: {data: softwareProduct}, |
| 233 | softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}} |
| 234 | } |
| 235 | }); |
| 236 | deepFreeze(store.getState()); |
| 237 | const expectedStore = store.getState(); |
| 238 | |
| 239 | const toBeUpdatedSoftwareProductId = softwareProduct.id; |
| 240 | const softwareProductUpdateData = { |
| 241 | ...softwareProduct, |
| 242 | name: 'VSP5_UPDATED', |
| 243 | description: 'A software model for Fortigate._UPDATED' |
| 244 | }; |
| 245 | deepFreeze(softwareProductUpdateData); |
| 246 | |
| 247 | mockRest.addHandler('save', ({data, options, baseUrl}) => { |
| 248 | const expectedData = { |
| 249 | name: 'VSP5_UPDATED', |
| 250 | description: 'A software model for Fortigate._UPDATED', |
| 251 | subCategory: 'resourceNewCategory.network connectivity.virtual links', |
| 252 | category: 'resourceNewCategory.network connectivity', |
| 253 | vendorId: '1', |
| 254 | vendorName: 'Vendor', |
| 255 | licensingVersion: '1.0', |
| 256 | icon: 'icon', |
| 257 | licensingData: { |
| 258 | licenceAgreement: '123', |
| 259 | featureGroups: [ |
| 260 | '123', '234' |
| 261 | ] |
| 262 | } |
| 263 | }; |
| 264 | expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}`); |
| 265 | expect(data).to.deep.equal(expectedData); |
| 266 | expect(options).to.equal(undefined); |
| 267 | return {returnCode: 'OK'}; |
| 268 | }); |
| 269 | |
| 270 | return SoftwareProductActionHelper.updateSoftwareProductData(store.dispatch, { |
| 271 | softwareProduct: softwareProductUpdateData |
| 272 | }).then(() => { |
| 273 | expect(store.getState()).to.deep.equal(expectedStore); |
| 274 | }); |
| 275 | }); |
| 276 | |
| 277 | it('Save Software product questionnaire only', () => { |
| 278 | const softwareProduct = { |
| 279 | name: 'VSP5', |
| 280 | id: '4730033D16C64E3CA556AB0AC4478218', |
| 281 | description: 'A software model for Fortigate.', |
| 282 | subCategory: 'resourceNewCategory.network connectivity.virtual links', |
| 283 | category: 'resourceNewCategory.network connectivity', |
| 284 | vendorId: '1', |
| 285 | vendorName: 'Vendor', |
| 286 | icon: 'icon', |
| 287 | licensingData: { |
| 288 | licenceAgreement: '123', |
| 289 | featureGroups: [ |
| 290 | '123', '234' |
| 291 | ] |
| 292 | } |
| 293 | }; |
| 294 | deepFreeze(softwareProduct); |
| 295 | |
| 296 | const store = storeCreator({ |
| 297 | softwareProduct: { |
| 298 | softwareProductEditor: {data: softwareProduct}, |
| 299 | softwareProductQuestionnaire: {qdata: 'test', qschema: {type: 'string'}} |
| 300 | } |
| 301 | }); |
| 302 | deepFreeze(store.getState()); |
| 303 | const expectedStore = store.getState(); |
| 304 | |
| 305 | const toBeUpdatedSoftwareProductId = softwareProduct.id; |
| 306 | const questionnaireData = { |
| 307 | general: { |
| 308 | affinityData: { |
| 309 | affinityGrouping: true, |
| 310 | antiAffinityGrouping: false |
| 311 | } |
| 312 | } |
| 313 | }; |
| 314 | deepFreeze(questionnaireData); |
| 315 | |
| 316 | mockRest.addHandler('save', ({data, options, baseUrl}) => { |
| 317 | expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${toBeUpdatedSoftwareProductId}/questionnaire`); |
| 318 | expect(data).to.deep.equal(questionnaireData); |
| 319 | expect(options).to.equal(undefined); |
| 320 | return {returnCode: 'OK'}; |
| 321 | }); |
| 322 | |
| 323 | return SoftwareProductActionHelper.updateSoftwareProductQuestionnaire(store.dispatch, { |
| 324 | softwareProductId: softwareProduct.id, |
| 325 | qdata: questionnaireData |
| 326 | }).then(() => { |
| 327 | expect(store.getState()).to.deep.equal(expectedStore); |
| 328 | }); |
| 329 | }); |
| 330 | |
| 331 | it('Handle category without subcategories', () => { |
| 332 | const categories = deepFreeze([ |
| 333 | { |
| 334 | name: 'Resource Category 1', |
| 335 | normalizedName: 'resource category 1', |
| 336 | uniqueId: 'resourceNewCategory.resource category 1', |
| 337 | subcategories: [ |
| 338 | { |
| 339 | name: 'Sub Category for RC 1', |
| 340 | normalizedName: 'sub category for rc 1', |
| 341 | uniqueId: 'resourceNewCategory.resource category 1.sub category for rc 1' |
| 342 | }, |
| 343 | { |
| 344 | name: 'SC4RC2', |
| 345 | normalizedName: 'sc4rc2', |
| 346 | uniqueId: 'resourceNewCategory.resource category 1.sc4rc2' |
| 347 | }, |
| 348 | { |
| 349 | name: 'SC4RC1', |
| 350 | normalizedName: 'sc4rc1', |
| 351 | uniqueId: 'resourceNewCategory.resource category 1.sc4rc1' |
| 352 | } |
| 353 | ] |
| 354 | }, |
| 355 | { |
| 356 | name: 'Eeeeee', |
| 357 | normalizedName: 'eeeeee', |
| 358 | uniqueId: 'resourceNewCategory.eeeeee' |
| 359 | }, |
| 360 | { |
| 361 | name: 'Some Recource', |
| 362 | normalizedName: 'some recource', |
| 363 | uniqueId: 'resourceNewCategory.some recource', |
| 364 | subcategories: [ |
| 365 | { |
| 366 | name: 'Second Sub Category for S', |
| 367 | normalizedName: 'second sub category for s', |
| 368 | uniqueId: 'resourceNewCategory.some recource.second sub category for s' |
| 369 | }, |
| 370 | { |
| 371 | name: 'Sub Category for Some Rec', |
| 372 | normalizedName: 'sub category for some rec', |
| 373 | uniqueId: 'resourceNewCategory.some recource.sub category for some rec' |
| 374 | } |
| 375 | ] |
| 376 | } |
| 377 | ]); |
| 378 | const category = SoftwareProductCategoriesHelper.getCurrentCategoryOfSubCategory('resourceNewCategory.some recource.sub category for some rec', categories); |
| 379 | expect(category).to.equal('resourceNewCategory.some recource'); |
| 380 | }); |
| 381 | |
| 382 | }); |
| 383 | |