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 |
| 7 | * |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 9 | * |
| 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'; |
| 18 | import {cloneAndSet} from 'test-utils/Util.js'; |
| 19 | import {storeCreator} from 'sdc-app/AppStore.js'; |
| 20 | import SoftwareProductComponentsActionHelper from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsActionHelper.js'; |
| 21 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 22 | import {VSPComponentsFactory, VSPComponentsGeneralFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsFactories.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 23 | import VersionFactory from 'test-utils/factories/common/VersionFactory.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 24 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 25 | const softwareProductId = '123'; |
| 26 | const vspComponentId = '321'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 27 | const version = VersionFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 28 | |
| 29 | describe('Software Product Components Module Tests', function () { |
| 30 | it('Get Software Products Components List', () => { |
| 31 | const store = storeCreator(); |
| 32 | deepFreeze(store.getState()); |
| 33 | |
| 34 | const softwareProductComponentsList = [ |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 35 | VSPComponentsFactory.build({}, {componentName: 'sd', componentType: 'server'}), |
| 36 | VSPComponentsFactory.build({}, {componentName: 'pd', componentType: 'server'}) |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 37 | ]; |
| 38 | |
| 39 | deepFreeze(softwareProductComponentsList); |
| 40 | |
| 41 | deepFreeze(store.getState()); |
| 42 | |
| 43 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentsList', softwareProductComponentsList); |
| 44 | |
| 45 | mockRest.addHandler('fetch', ({options, data, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 46 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/components`); |
| 47 | expect(data).toEqual(undefined); |
| 48 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 49 | return {results: softwareProductComponentsList}; |
| 50 | }); |
| 51 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 52 | return SoftwareProductComponentsActionHelper.fetchSoftwareProductComponents(store.dispatch, {softwareProductId, version}).then(() => { |
| 53 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 54 | }); |
| 55 | }); |
| 56 | |
| 57 | it('Update SoftwareProduct Component Questionnaire', () => { |
| 58 | const store = storeCreator(); |
| 59 | |
| 60 | const qdataUpdated = { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 61 | general: VSPComponentsGeneralFactory.build() |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor.qdata', qdataUpdated); |
| 65 | deepFreeze(expectedStore); |
| 66 | |
| 67 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 68 | mockRest.addHandler('put', ({options, data, baseUrl}) => { |
| 69 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/components/${vspComponentId}/questionnaire`); |
| 70 | expect(data).toEqual(qdataUpdated); |
| 71 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 72 | return {returnCode: 'OK'}; |
| 73 | }); |
| 74 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 75 | return SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(store.dispatch, {softwareProductId, version, vspComponentId, qdata: qdataUpdated}).then(() => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 76 | //TODO think should we add here something or not |
| 77 | }); |
| 78 | |
| 79 | |
| 80 | }); |
| 81 | |
| 82 | }); |