[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / test / softwareProduct / components / test.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
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  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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,
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.
15  */
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
22 import {VSPComponentsFactory, VSPComponentsGeneralFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsFactories.js';
23 import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
24
25 const softwareProductId = '123';
26 const vspComponentId = '321';
27 const version = VersionControllerUtilsFactory.build().version;
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 = [
35                         VSPComponentsFactory.build({}, {componentName: 'sd', componentType: 'server'}),
36                         VSPComponentsFactory.build({}, {componentName: 'pd', componentType: 'server'})
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}) => {
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);
49                         return {results: softwareProductComponentsList};
50                 });
51
52                 return SoftwareProductComponentsActionHelper.fetchSoftwareProductComponents(store.dispatch, {softwareProductId, version}).then(() => {
53                         expect(store.getState()).toEqual(expectedStore);
54                 });
55         });
56
57         it('Update SoftwareProduct Component Questionnaire', () => {
58                 const store = storeCreator();
59
60                 const qdataUpdated = {
61                         general: VSPComponentsGeneralFactory.build()
62                 };
63
64                 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor.qdata', qdataUpdated);
65                 deepFreeze(expectedStore);
66
67
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);
72                         return {returnCode: 'OK'};
73                 });
74
75                 return SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(store.dispatch, {softwareProductId, version, vspComponentId, qdata: qdataUpdated}).then(() => {
76                         //TODO think should we add here something or not
77                 });
78
79
80         });
81
82 });