blob: 3be1d68bbcc532d96de69b166574022c8754b80c [file] [log] [blame]
Vodafone804ec682019-03-18 15:46:53 +05301/*
2 * Copyright © 2019 Vodafone Group
3 *
4 * 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 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import 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 SoftwareProductValidationActionHelper from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidationActionHelper.js';
21import { tabsMapping } from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidationConstants.js';
22
23import Configuration from 'sdc-app/config/Configuration.js';
24
25import { VSPComplianceCheckedFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
26import { VSPCertificationCheckedFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
atulpurohit8b346842019-11-05 14:31:56 +053027import { VSPTestResultKeysFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationResultsFactory.js';
Vodafone804ec682019-03-18 15:46:53 +053028import { VSPChecksFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
29import { VSPTestsMapFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
Vodafone18750932019-04-05 15:49:06 +053030import { VSPTestsRequestFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
31import { VSPGeneralInfoFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
32import { VSPTestResultsSuccessFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationResultsFactory.js';
33import { mapActionsToProps } from 'sdc-app/onboarding/softwareProduct/validation/SoftwareProductValidation.js';
atulpurohit8b346842019-11-05 14:31:56 +053034import { VSPTestRequestFactory } from 'test-utils/factories/softwareProduct/SoftwareProductValidationFactory.js';
Vodafone804ec682019-03-18 15:46:53 +053035
36describe('Software Product Validation Action Helper Tests', function() {
Vodafone18750932019-04-05 15:49:06 +053037 const store = storeCreator();
38 deepFreeze(store.getState());
Vodafone804ec682019-03-18 15:46:53 +053039
Vodafone18750932019-04-05 15:49:06 +053040 const vspChecksList = VSPChecksFactory.build();
41 const vspTestsMap = VSPTestsMapFactory.build();
42 const certificationChecked = VSPCertificationCheckedFactory.build();
43 const complianceChecked = VSPComplianceCheckedFactory.build();
44 const activeTab = { activeTab: tabsMapping.INPUTS };
45 const errorMessage = { msg: 'Test Error Message' };
46 const testsRequest = VSPTestsRequestFactory.build();
47 const generalInfo = VSPGeneralInfoFactory.build();
48 const isValidationDisabled = false;
49 const vspTestResults = VSPTestResultsSuccessFactory.build();
atulpurohit8b346842019-11-05 14:31:56 +053050 const testResultKeys = VSPTestResultKeysFactory.build();
Vodafone18750932019-04-05 15:49:06 +053051 let restPrefix = Configuration.get('restPrefix');
52 let onClose = () => {};
atulpurohit8b346842019-11-05 14:31:56 +053053 const vspTestRequest = VSPTestRequestFactory.build();
Vodafone804ec682019-03-18 15:46:53 +053054
Vodafone18750932019-04-05 15:49:06 +053055 const modal = {
56 type: 'error',
57 title: 'Error',
58 modalComponentName: 'Error',
59 modalComponentProps: {
60 onClose: onClose
61 },
62 msg: {
63 msg: 'Test Error Message'
64 },
65 cancelButtonText: 'OK'
66 };
67 // deepFreeze(vspTestsMap.vspTestsMap);
68 // deepFreeze(certificationChecked.certificationChecked);
69 // deepFreeze(complianceChecked.complianceChecked);
70 // deepFreeze(activeTab);
71 // deepFreeze(testsRequest);
72 // deepFreeze(generalInfo.generalInfo);
73 // deepFreeze(isVspValidationDisabled);
Vodafone804ec682019-03-18 15:46:53 +053074
Vodafone18750932019-04-05 15:49:06 +053075 it('Software Products Validation Action Helper : fetch vsp', () => {
Vodafone804ec682019-03-18 15:46:53 +053076 let expectedStore = cloneAndSet(
77 store.getState(),
78 'softwareProduct.softwareProductValidation.vspChecks',
79 vspChecksList
80 );
Vodafone18750932019-04-05 15:49:06 +053081 mockRest.addHandler('fetch', ({ baseUrl }) => {
82 expect(baseUrl).toEqual(
83 `${restPrefix}/v1.0/externaltesting/testcasetree`
84 );
85 return vspChecksList;
Vodafone804ec682019-03-18 15:46:53 +053086 });
Vodafone18750932019-04-05 15:49:06 +053087 return SoftwareProductValidationActionHelper.fetchVspChecks(
88 store.dispatch
89 )
Vodafone804ec682019-03-18 15:46:53 +053090 .then(() => {
91 expect(store.getState()).toEqual(expectedStore);
92 })
Vodafone18750932019-04-05 15:49:06 +053093 .catch(() => {
94 console.log('Fetch VSP returned Error');
95 });
96 });
97
atulpurohit8b346842019-11-05 14:31:56 +053098 it('Software Products Validation Action Helper : post test', () => {
99
100 const str = storeCreator({
101 softwareProduct: {
102 softwareProductValidation: {
103 testResultKeys: testResultKeys.testResultKeys
104 }
105 }
106 });
107 deepFreeze(str.getState());
108 let expectedStore = cloneAndSet(
109 str.getState(),
110 'softwareProduct.softwareProductValidation.vspTestResults',
111 vspTestResults.vspTestResults
112 );
113 const version = {
114 id: 12345,
115 name: 1
116 };
117 const requestId = "1"
118 const softwareProductId = '1234';
119 const status = 'success';
120 mockRest.addHandler('post', ({ options, data, baseUrl }) => {
121 expect(baseUrl).toEqual(
122 `${restPrefix}/v1.0/externaltesting/executions?vspId=${softwareProductId}&vspVersionId=${version.id}&requestId=${requestId}`
123 );
124 return vspTestResults.vspTestResults ;
125 });
126 SoftwareProductValidationActionHelper.navigateToSoftwareProductValidationResults(
127 str.dispatch,{
128 softwareProductId: softwareProductId,
129 version: version,
130 status: status,
131 tests :vspTestRequest.vspTestRequest,
132 requestId: requestId
133 }
134 ).then(() => {
135 expect(str.getState()).toEqual(expectedStore);
136 })
137 .catch((e) => {
138 console.log('Executions test returned Error');
139 });
140
141 });
Vodafone18750932019-04-05 15:49:06 +0530142
143 it('Software Products Validation Action Helper : setCertificationChecked', () => {
144 let expectedStore = cloneAndSet(
145 store.getState(),
146 'softwareProduct.softwareProductValidation.certificationChecked',
147 certificationChecked.certificationChecked
148 );
149 mapActionsToProps(store.dispatch).setCertificationChecked({
150 checked: certificationChecked.certificationChecked
151 });
152 expect(store.getState()).toEqual(expectedStore);
153 });
154
155 it('Software Products Validation Action Helper : onErrorThrown', () => {
156 let expectedStore = cloneAndSet(store.getState(), 'modal', modal);
157 mapActionsToProps(store.dispatch).onErrorThrown(errorMessage);
158 expect(JSON.stringify(store.getState())).toEqual(
159 JSON.stringify(expectedStore)
160 );
161 });
162
163 it('Software Products Validation Action Helper : setComplianceChecked', () => {
164 let expectedStore = cloneAndSet(
165 store.getState(),
166 'softwareProduct.softwareProductValidation.complianceChecked',
167 complianceChecked.complianceChecked
168 );
169 mapActionsToProps(store.dispatch).setComplianceChecked({
170 checked: complianceChecked.complianceChecked
171 });
172 expect(store.getState()).toEqual(expectedStore);
173 });
174
175 it('Software Products Validation Action Helper : setActiveTab', () => {
176 let expectedStore = cloneAndSet(
177 store.getState(),
178 'softwareProduct.softwareProductValidation.activeTab',
179 activeTab.activeTab
180 );
181 mapActionsToProps(store.dispatch).setActiveTab(activeTab);
182 expect(store.getState()).toEqual(expectedStore);
183 });
184
185 it('Software Products Validation Action Helper : setGeneralInfo', () => {
186 let expectedStore = cloneAndSet(
187 store.getState(),
188 'softwareProduct.softwareProductValidation.generalInfo',
189 generalInfo.generalInfo
190 );
191 mapActionsToProps(store.dispatch).setGeneralInfo(
192 generalInfo.generalInfo
193 );
194 expect(store.getState()).toEqual(expectedStore);
195 });
196
197 it('Software Products Validation Action Helper : setIsVspValidationDisabled', () => {
198 let expectedStore = cloneAndSet(
199 store.getState(),
200 'softwareProduct.softwareProductValidation.isValidationDisabled',
201 isValidationDisabled
202 );
203 SoftwareProductValidationActionHelper.setIsVspValidationDisabled(
204 store.dispatch,
205 {
206 isValidationDisabled
207 }
208 );
209 expect(store.getState()).toEqual(expectedStore);
210 });
211
212 it('Software Products Validation Action Helper : setTestsRequest', () => {
213 let expectedStore = cloneAndSet(
214 store.getState(),
215 'softwareProduct.softwareProductValidation.testsRequest',
216 testsRequest.testsRequest
217 );
218 expectedStore = cloneAndSet(
219 expectedStore,
220 'softwareProduct.softwareProductValidation.generalInfo',
221 generalInfo.generalInfo
222 );
223
224 mapActionsToProps(store.dispatch).setTestsRequest(
225 testsRequest.testsRequest,
226 generalInfo.generalInfo
227 );
228 expect(store.getState()).toEqual(expectedStore);
229 });
230
231 it('Software Products Validation Action Helper : setVspTestsMap', () => {
232 let expectedStore = cloneAndSet(
233 store.getState(),
234 'softwareProduct.softwareProductValidation.vspTestsMap',
235 vspTestsMap.vspTestsMap
236 );
237 SoftwareProductValidationActionHelper.setVspTestsMap(
238 store.dispatch,
239 vspTestsMap.vspTestsMap
240 );
241
242 expect(store.getState()).toEqual(expectedStore);
Vodafone804ec682019-03-18 15:46:53 +0530243 });
244});