blob: ab379937c05c0e664f1a2ae711f55bf49d997a2d [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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 *
AviZi280f8012017-06-09 02:39:56 +03008 * http://www.apache.org/licenses/LICENSE-2.0
Michael Landoefa037d2017-02-19 12:57:33 +02009 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * 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 Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import deepFreeze from 'deep-freeze';
17import mockRest from 'test-utils/MockRest.js';
18import {cloneAndSet} from 'test-utils/Util.js';
19import {storeCreator} from 'sdc-app/AppStore.js';
20import SoftwareProductComponentsActionHelper from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsActionHelper.js';
21
AviZi280f8012017-06-09 02:39:56 +030022import {VSPComponentsFactory, VSPComponentsGeneralFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsFactories.js';
talig8e9c0652017-12-20 14:30:43 +020023import VersionFactory from 'test-utils/factories/common/VersionFactory.js';
AviZi280f8012017-06-09 02:39:56 +030024
Michael Landoefa037d2017-02-19 12:57:33 +020025const softwareProductId = '123';
26const vspComponentId = '321';
talig8e9c0652017-12-20 14:30:43 +020027const version = VersionFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +020028
29describe('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 = [
AviZi280f8012017-06-09 02:39:56 +030035 VSPComponentsFactory.build({}, {componentName: 'sd', componentType: 'server'}),
36 VSPComponentsFactory.build({}, {componentName: 'pd', componentType: 'server'})
Michael Landoefa037d2017-02-19 12:57:33 +020037 ];
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}) => {
AviZi280f8012017-06-09 02:39:56 +030046 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 Landoefa037d2017-02-19 12:57:33 +020049 return {results: softwareProductComponentsList};
50 });
51
AviZi280f8012017-06-09 02:39:56 +030052 return SoftwareProductComponentsActionHelper.fetchSoftwareProductComponents(store.dispatch, {softwareProductId, version}).then(() => {
53 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020054 });
55 });
56
57 it('Update SoftwareProduct Component Questionnaire', () => {
58 const store = storeCreator();
59
60 const qdataUpdated = {
AviZi280f8012017-06-09 02:39:56 +030061 general: VSPComponentsGeneralFactory.build()
Michael Landoefa037d2017-02-19 12:57:33 +020062 };
63
64 const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.componentEditor.qdata', qdataUpdated);
65 deepFreeze(expectedStore);
66
67
AviZi280f8012017-06-09 02:39:56 +030068 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 Landoefa037d2017-02-19 12:57:33 +020072 return {returnCode: 'OK'};
73 });
74
AviZi280f8012017-06-09 02:39:56 +030075 return SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(store.dispatch, {softwareProductId, version, vspComponentId, qdata: qdataUpdated}).then(() => {
Michael Landoefa037d2017-02-19 12:57:33 +020076 //TODO think should we add here something or not
77 });
78
79
80 });
81
82});