blob: 839e1b7cf7f4eaf47918a1d0526a9360e2b45f06 [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001/*-
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
21import {expect} from 'chai';
22import deepFreeze from 'deep-freeze';
23import mockRest from 'test-utils/MockRest.js';
24import {cloneAndSet} from 'test-utils/Util.js';
25import {storeCreator} from 'sdc-app/AppStore.js';
26import SoftwareProductComponentsActionHelper from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsActionHelper.js';
27
28const softwareProductId = '123';
29const vspComponentId = '321';
30
31describe('Software Product Components Module Tests', function () {
32 it('Get Software Products Components List', () => {
33 const store = storeCreator();
34 deepFreeze(store.getState());
35
36 const softwareProductComponentsList = [
37 {
38 name: 'com.d2.resource.vfc.nodes.heat.sm_server',
39 displayName: 'sm_server',
40 description: 'hjhj',
41 id: 'EBADF561B7FA4A788075E1840D0B5971'
42 },
43 {
44 name: 'com.d2.resource.vfc.nodes.heat.pd_server',
45 displayName: 'pd_server',
46 description: 'hjhj',
47 id: '2F47447D22DB4C53B020CA1E66201EF2'
48 }
49 ];
50
51 deepFreeze(softwareProductComponentsList);
52
53 deepFreeze(store.getState());
54
55 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentsList', softwareProductComponentsList);
56
57 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
58 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components`);
59 expect(data).to.deep.equal(undefined);
60 expect(options).to.equal(undefined);
61 return {results: softwareProductComponentsList};
62 });
63
64 return SoftwareProductComponentsActionHelper.fetchSoftwareProductComponents(store.dispatch, {softwareProductId}).then(() => {
65 expect(store.getState()).to.deep.equal(expectedStore);
66 });
67 });
68
69 it('Update SoftwareProduct Component Questionnaire', () => {
70 const store = storeCreator();
71
72 const qdataUpdated = {
73 general: {
74 hypervisor: {
75 containerFeatureDescription: 'aaaUpdated',
76 drivers: 'bbbUpdated',
77 hypervisor: 'cccUpdated'
78 }
79 }
80 };
81
82 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor.qdata', qdataUpdated);
83 deepFreeze(expectedStore);
84
85
86 mockRest.addHandler('save', ({options, data, baseUrl}) => {
87 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/components/${vspComponentId}/questionnaire`);
88 expect(data).to.deep.equal(qdataUpdated);
89 expect(options).to.equal(undefined);
90 return {returnCode: 'OK'};
91 });
92
93 return SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(store.dispatch, {softwareProductId, vspComponentId, qdata: qdataUpdated}).then(() => {
94 //TODO think should we add here something or not
95 });
96
97
98 });
99
100});
101