2 * Copyright (c) 2019 Vodafone Group
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
17 import Configuration from 'sdc-app/config/Configuration.js';
18 import { actionTypes } from './SoftwareProductValidationConstants.js';
19 import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
20 import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
21 import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js';
22 import i18n from 'nfvo-utils/i18n/i18n.js';
24 function createCertificationFormData(tests) {
25 var formData = new FormData();
27 for (var test of tests) {
29 for (var file of test.files) {
30 formData.append('files', file.file, file.name);
36 formData.append('testdata', JSON.stringify(testData));
40 function postVSPCertificationChecks(
46 const restPrefix = Configuration.get('restPrefix');
48 var formData = createCertificationFormData(tests);
49 return RestAPIUtil.post(
50 `${restPrefix}/v1.0/externaltesting/executions?vspId=${softwareProductId}&vspVersionId=${id}&requestId=${requestId}`,
55 function fetchVspChecks() {
56 const restPrefix = Configuration.get('restPrefix');
57 return RestAPIUtil.fetch(`${restPrefix}/v1.0/externaltesting/testcasetree`);
60 function extractEndPoint(tests) {
61 return [...new Set(tests.map(test => test.endpoint))];
63 const SoftwareProductValidationActionHelper = {
64 navigateToSoftwareProductValidationResults(
66 { softwareProductId, version, status, tests, requestId }
68 return new Promise((resolve, reject) => {
69 postVSPCertificationChecks(
76 var testResultKeys = {};
77 testResultKeys.endPoints = extractEndPoint(tests);
78 testResultKeys.requestId = requestId;
80 type: actionTypes.POST_VSP_TESTS,
81 vspTestResults: response,
82 testResultKeys: testResultKeys
84 ScreensHelper.loadScreen(dispatch, {
86 enums.SCREEN.SOFTWARE_PRODUCT_VALIDATION_RESULTS,
87 screenType: screenTypes.SOFTWARE_PRODUCT,
98 error.message || error.responseJSON.message;
99 let title = error.responseJSON
100 ? error.responseJSON.status
103 type: modalActionTypes.GLOBAL_MODAL_ERROR,
107 cancelButtonText: i18n('OK')
115 fetchVspChecks(dispatch) {
116 return new Promise((resolve, reject) => {
120 type: actionTypes.FETCH_VSP_CHECKS,
131 setActiveTab(dispatch, { activeTab }) {
133 type: actionTypes.SET_ACTIVE_TAB,
138 onErrorThrown(dispatch, msg) {
140 type: modalActionTypes.GLOBAL_MODAL_ERROR,
142 title: i18n('Error'),
143 modalComponentName: i18n('Error'),
144 modalComponentProps: {
147 type: modalActionTypes.GLOBAL_MODAL_CLOSE
151 cancelButtonText: i18n('OK')
156 setVspTestsMap(dispatch, map) {
158 type: actionTypes.SET_VSP_TESTS_MAP,
163 setComplianceChecked(dispatch, checked) {
165 type: actionTypes.SET_COMPLIANCE_CHECKED,
166 complianceChecked: checked
170 setCertificationChecked(dispatch, checked) {
172 type: actionTypes.SET_CERTIFICATION_CHECKED,
173 certificationChecked: checked
177 setTestsRequest(dispatch, request, info) {
179 type: actionTypes.SET_TESTS_REQUEST,
180 testsRequest: request,
185 setGeneralInfo(dispatch, info) {
187 type: actionTypes.SET_GENERAL_INFO,
192 setIsVspValidationDisabled(dispatch, { isValidationDisabled }) {
194 type: actionTypes.SET_VSP_VALIDATION_DISABLED,
195 isValidationDisabled: isValidationDisabled
200 export default SoftwareProductValidationActionHelper;