Add new code new version
[sdc.git] / openecomp-ui / test / softwareProduct / components / compute / test.js
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 'expect';
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 import Configuration from 'sdc-app/config/Configuration.js';
27 import SoftwareProductComponentsActionHelper from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsActionHelper.js';
28
29 const softwareProductId = '123';
30 const vspComponentId = '111';
31
32 describe('Software Product Components Compute Module Tests', function () {
33
34         let restPrefix = '';
35
36         before(function() {
37                 restPrefix = Configuration.get('restPrefix');
38                 deepFreeze(restPrefix);
39         });
40
41         it('Get Software Products Components Compute', () => {
42                 const store = storeCreator();
43                 deepFreeze(store.getState());
44
45                 const softwareProductComponentCompute = {
46                         data: JSON.stringify({'vmSizing':{'numOfCPUs':'3','fileSystemSizeGB':'888'},'numOfVMs':{'minimum':'2'}}),
47                         schema: JSON.stringify({'vmSizing':{'numOfCPUs':'3','fileSystemSizeGB':'888'},'numOfVMs':{'minimum':'2'}})
48                 };
49                 deepFreeze(softwareProductComponentCompute);
50
51                 const softwareProductComponentComputeData = {
52                         qdata: JSON.parse(softwareProductComponentCompute.data),
53                         qschema: JSON.parse(softwareProductComponentCompute.schema)
54                 };
55                 deepFreeze(softwareProductComponentComputeData);
56
57                 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor', softwareProductComponentComputeData);
58
59                 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
60                         expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/components/${vspComponentId}/questionnaire`);
61                         expect(data).toEqual(undefined);
62                         expect(options).toEqual(undefined);
63                         return softwareProductComponentCompute;
64                 });
65
66                 return SoftwareProductComponentsActionHelper.fetchSoftwareProductComponentQuestionnaire(store.dispatch, {softwareProductId, vspComponentId}).then(() => {
67                         expect(store.getState()).toEqual(expectedStore);
68                 });
69         });
70
71         it('Get Empty Software Products Components Compute', () => {
72                 const store = storeCreator();
73                 deepFreeze(store.getState());
74
75                 const softwareProductComponentQuestionnaire = {
76                         data: null,
77                         schema: JSON.stringify({'vmSizing':{'numOfCPUs':'3','fileSystemSizeGB':'888'},'numOfVMs':{'minimum':'2'}})
78                 };
79                 deepFreeze(softwareProductComponentQuestionnaire);
80
81                 const softwareProductComponentQuestionnaireData = {
82                         qdata: {},
83                         qschema: JSON.parse(softwareProductComponentQuestionnaire.schema)
84                 };
85                 deepFreeze(softwareProductComponentQuestionnaireData);
86
87                 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor', softwareProductComponentQuestionnaireData);
88
89                 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
90                         expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/components/${vspComponentId}/questionnaire`);
91                         expect(data).toEqual(undefined);
92                         expect(options).toEqual(undefined);
93                         return softwareProductComponentQuestionnaire;
94                 });
95
96                 return SoftwareProductComponentsActionHelper.fetchSoftwareProductComponentQuestionnaire(store.dispatch, {softwareProductId, vspComponentId}).then(() => {
97                         expect(store.getState()).toEqual(expectedStore);
98                 });
99         });
100
101         it('Update Software Products Components Compute', () => {
102                 const store = storeCreator({
103                         softwareProduct: {
104                                 softwareProductComponents: {
105                                         componentEditor: {
106                                                 qdata: {
107                                                         numOfCPUs: 3,
108                                                         fileSystemSizeGB: 999
109                                                 },
110                                                 qschema: {
111                                                         type: 'object',
112                                                         properties: {
113                                                                 numOfCPUs: {type: 'number'},
114                                                                 fileSystemSizeGB: {type: 'number'}
115                                                         }
116                                                 }
117                                         }
118                                 }
119                         }
120                 });
121                 deepFreeze(store);
122
123                 const data = {numOfCPUs: 5, fileSystemSizeGB: 300};
124                 deepFreeze(data);
125
126                 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor.qdata', data);
127
128                 SoftwareProductComponentsActionHelper.componentQuestionnaireUpdated(store.dispatch, {data});
129
130                 expect(store.getState()).toEqual(expectedStore);
131         });
132 });