2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
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';
29 const softwareProductId = '123';
30 const vspComponentId = '111';
32 describe('Software Product Components Compute Module Tests', function () {
37 restPrefix = Configuration.get('restPrefix');
38 deepFreeze(restPrefix);
41 it('Get Software Products Components Compute', () => {
42 const store = storeCreator();
43 deepFreeze(store.getState());
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'}})
49 deepFreeze(softwareProductComponentCompute);
51 const softwareProductComponentComputeData = {
52 qdata: JSON.parse(softwareProductComponentCompute.data),
53 qschema: JSON.parse(softwareProductComponentCompute.schema)
55 deepFreeze(softwareProductComponentComputeData);
57 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor', softwareProductComponentComputeData);
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;
66 return SoftwareProductComponentsActionHelper.fetchSoftwareProductComponentQuestionnaire(store.dispatch, {softwareProductId, vspComponentId}).then(() => {
67 expect(store.getState()).toEqual(expectedStore);
71 it('Get Empty Software Products Components Compute', () => {
72 const store = storeCreator();
73 deepFreeze(store.getState());
75 const softwareProductComponentQuestionnaire = {
77 schema: JSON.stringify({'vmSizing':{'numOfCPUs':'3','fileSystemSizeGB':'888'},'numOfVMs':{'minimum':'2'}})
79 deepFreeze(softwareProductComponentQuestionnaire);
81 const softwareProductComponentQuestionnaireData = {
83 qschema: JSON.parse(softwareProductComponentQuestionnaire.schema)
85 deepFreeze(softwareProductComponentQuestionnaireData);
87 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor', softwareProductComponentQuestionnaireData);
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;
96 return SoftwareProductComponentsActionHelper.fetchSoftwareProductComponentQuestionnaire(store.dispatch, {softwareProductId, vspComponentId}).then(() => {
97 expect(store.getState()).toEqual(expectedStore);
101 it('Update Software Products Components Compute', () => {
102 const store = storeCreator({
104 softwareProductComponents: {
108 fileSystemSizeGB: 999
113 numOfCPUs: {type: 'number'},
114 fileSystemSizeGB: {type: 'number'}
123 const data = {numOfCPUs: 5, fileSystemSizeGB: 300};
126 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor.qdata', data);
128 SoftwareProductComponentsActionHelper.componentQuestionnaireUpdated(store.dispatch, {data});
130 expect(store.getState()).toEqual(expectedStore);