aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-ui/test/softwareProduct/components/compute/VSPComponentComputeActionHelperManualMode.test.js
blob: ca3d12f3e90f9ceb54f8b6761fbbd32d633ae58e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*!
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
import deepFreeze from 'deep-freeze';
import mockRest from 'test-utils/MockRest.js';
import {cloneAndSet} from 'test-utils/Util.js';
import {storeCreator} from 'sdc-app/AppStore.js';
import Configuration from 'sdc-app/config/Configuration.js';
import ComputeFlavorActionHelper from 'sdc-app/onboarding/softwareProduct/components/compute/ComputeFlavorActionHelper.js';
import {VSPEditorFactory} from 'test-utils/factories/softwareProduct/SoftwareProductEditorFactories.js';

import {ComputeFlavorQData, ComputeFlavorBaseData, ComponentComputeFactory, VSPComponentsComputeDataMapFactory} from 'test-utils/factories/softwareProduct/SoftwareProductComponentsComputeFactory.js';

const softwareProductId = '123';
const vspComponentId = '111';
const computeId = '111';
const version = VSPEditorFactory.build().version;


describe('Software Product Components Compute Module Tests - Manual mode', function () {

	let restPrefix = '';

	beforeAll(function() {
		restPrefix = Configuration.get('restPrefix');
		deepFreeze(restPrefix);
	});


	it('Close Compute Flavor editor', () => {

		const store = storeCreator();
		deepFreeze(store.getState());

		const compute = ComponentComputeFactory.build();
		deepFreeze(compute);

		const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.computeFlavor', compute);

		ComputeFlavorActionHelper.closeComputeEditor(store.dispatch);
		expect(store.getState()).toEqual(expectedStore);
	});

	it('Get Computes List', () => {
		const store = storeCreator();
		deepFreeze(store.getState());

		const computesList = ComputeFlavorBaseData.buildList(2);
		deepFreeze(computesList);

		const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.computeFlavor.computesList', computesList);

		mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
			expect(baseUrl).toEqual(`${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/components/${vspComponentId}/compute-flavors`);
			expect(data).toEqual(undefined);
			expect(options).toEqual(undefined);
			return {results: computesList};
		});

		return ComputeFlavorActionHelper.fetchComputesList(store.dispatch, {softwareProductId, componentId: vspComponentId, version}).then(() => {
			expect(store.getState()).toEqual(expectedStore);
		});
	});

	it('Load Compute data & Questionnaire', () => {
		const store = storeCreator();
		deepFreeze(store.getState());

		const computeData = {
			...ComputeFlavorBaseData.build(),
			id: computeId
		};
		deepFreeze(computeData);
		const qdata = ComputeFlavorQData.build();
		const dataMap = VSPComponentsComputeDataMapFactory.build();

		const softwareProductComponentCompute = {
			data: JSON.stringify(qdata),
			schema: JSON.stringify(qdata)
		};
		deepFreeze(softwareProductComponentCompute);


		const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.computeFlavor.computeEditor', {
			data: computeData,
			qdata,
			dataMap,
			qgenericFieldInfo: {},
			genericFieldInfo: {},
			formReady: true
		});

		mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/components/${vspComponentId}/compute-flavors/${computeId}`);
			expect(data).toEqual(undefined);
			expect(options).toEqual(undefined);
			return {data: computeData};
		});
		mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/components/${vspComponentId}/compute-flavors/${computeId}/questionnaire`);
			expect(data).toEqual(undefined);
			expect(options).toEqual(undefined);
			return softwareProductComponentCompute;
		});

		return ComputeFlavorActionHelper.loadComputeData({softwareProductId, componentId: vspComponentId, version, computeId}).then(() => {
			ComputeFlavorActionHelper.loadComputeQuestionnaire(store.dispatch, {softwareProductId, componentId: vspComponentId, computeId, version}).then(() =>
				expect(store.getState()).toEqual(expectedStore));
		});
	});

	it('Save Compute Flavor data and questionnaire', () => {

		const store = storeCreator();
		deepFreeze(store.getState());

		const qdata = ComputeFlavorQData.build();
		const data = ComputeFlavorBaseData.build();

		const compute = {...data, id: computeId};

		const computeObj = {
			computeEditor: {},
			computesList: [
				compute
			]
		};

		const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.computeFlavor', computeObj);
		deepFreeze(expectedStore);

		mockRest.addHandler('put', ({options, data, baseUrl}) => {
			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/components/${vspComponentId}/compute-flavors/${computeId}/questionnaire`);
			expect(data).toEqual(qdata);
			expect(options).toEqual(undefined);
			return {returnCode: 'OK'};
		});

		mockRest.addHandler('put', ({options, data, baseUrl}) => {
			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/components/${vspComponentId}/compute-flavors/${computeId}`);
			expect(data).toEqual(data);
			expect(options).toEqual(undefined);
			return {returnCode: 'OK'};
		});

		return ComputeFlavorActionHelper.saveComputeDataAndQuestionnaire(store.dispatch, {softwareProductId, componentId: vspComponentId, qdata, data: compute, version}).then(() => {
			expect(store.getState()).toEqual(expectedStore);
		});
	});

	it('Delete Compute Flavor', () => {
		const compute = ComponentComputeFactory.build();
		const computesList = [compute];
		deepFreeze(computesList);

		const store = storeCreator({
			softwareProduct: {
				softwareProductComponents: {
					computeFlavor: {
						computesList: computesList
					}
				}
			}
		});
		deepFreeze(store.getState());

		const computeId = compute.id;

		const expectedStore = cloneAndSet(store.getState(), 'softwareProduct.softwareProductComponents.computeFlavor.computesList', []);

		mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
			expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-software-products/${softwareProductId}/versions/${version.id}/components/${vspComponentId}/compute-flavors/${computeId}`);
			expect(data).toEqual(undefined);
			expect(options).toEqual(undefined);
			return {
				results: {
					returnCode: 'OK'
				}
			};
		});

		return ComputeFlavorActionHelper.deleteCompute(store.dispatch, {softwareProductId, componentId: vspComponentId, computeId, version}).then(() => {
			expect(store.getState()).toEqual(expectedStore);
		});
	});
});