blob: 621b6a1447182b4adb96b4244ba51c21972192d3 [file] [log] [blame]
Einav Weiss Keidar1801b242018-08-13 16:19:46 +03001/*
2 * Copyright © 2016-2018 European Support Limited
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
AviZi280f8012017-06-09 02:39:56 +03007 *
Einav Weiss Keidar1801b242018-08-13 16:19:46 +03008 * http://www.apache.org/licenses/LICENSE-2.0
AviZi280f8012017-06-09 02:39:56 +03009 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030012 * 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.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
16
Michael Landoefa037d2017-02-19 12:57:33 +020017import deepFreeze from 'deep-freeze';
18import mockRest from 'test-utils/MockRest.js';
19import store from 'sdc-app/AppStore.js';
20import FlowsActions from 'sdc-app/flows/FlowsActions.js';
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030021import { enums } from 'sdc-app/flows/FlowsConstants.js';
Michael Landoefa037d2017-02-19 12:57:33 +020022
AviZi280f8012017-06-09 02:39:56 +030023import {
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030024 FlowCreateFactory,
25 FlowPostRequestFactory,
26 FlowPostResponseFactory,
27 FlowFetchRequestFactory,
28 FlowFetchResponseFactory,
29 FlowDeleteRequestFactory,
30 FlowUpdateRequestFactory
31} from 'test-utils/factories/flows/FlowsFactories.js';
AviZi280f8012017-06-09 02:39:56 +030032
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030033import { buildFromExistingObject } from 'test-utils/Util.js';
AviZi280f8012017-06-09 02:39:56 +030034
Michael Landoefa037d2017-02-19 12:57:33 +020035const NEW_FLOW = true;
36
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030037let assertFlowDataAfterCreateFetchAndUpdate = data => {
38 let { flowList, serviceID, diagramType } = store.getState().flows;
39 expect(serviceID).toBe(data.serviceID);
40 expect(diagramType).toBe(data.artifactType);
41 let uniqueId = data.uniqueId || `${data.serviceID}.${data.artifactName}`;
42 let index = flowList.findIndex(flow => flow.uniqueId === uniqueId);
43 expect(index).not.toBe(-1);
Michael Landoefa037d2017-02-19 12:57:33 +020044};
45
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030046describe('Workflows and Management Flows Module Tests:', function() {
47 it('empty artifact should open flow creation modal', () => {
48 const artifacts = {};
Michael Landoefa037d2017-02-19 12:57:33 +020049
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030050 deepFreeze(store.getState());
51 deepFreeze(artifacts);
52 FlowsActions.fetchFlowArtifacts(store.dispatch, {
53 artifacts,
54 diagramType: enums.WORKFLOW,
55 participants: [],
56 serviceID: '1234'
57 });
58 let state = store.getState();
59 expect(state.modal).toBeDefined();
60 });
Michael Landoefa037d2017-02-19 12:57:33 +020061
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030062 it('Close flow details editor modal', () => {
63 deepFreeze(store.getState());
64 FlowsActions.closeEditCreateWFModal(store.dispatch);
65 let state = store.getState();
66 expect(state.modal).toBeFalsy();
67 });
Michael Landoefa037d2017-02-19 12:57:33 +020068
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030069 it('Get Flows List from loaded artifact', () => {
70 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +020071
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030072 const artifacts = {
73 test1: FlowPostResponseFactory.build({ artifactName: 'test1' }),
74 kukuriku: FlowPostResponseFactory.build({
75 artifactType: 'PUPPET',
76 artifactName: 'kukuriku'
77 }),
78 test3: FlowPostResponseFactory.build({ artifactName: 'test3' })
79 };
Michael Landoefa037d2017-02-19 12:57:33 +020080
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030081 const artifactsArray = Object.keys(artifacts).map(artifact => artifact);
Michael Landoefa037d2017-02-19 12:57:33 +020082
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030083 deepFreeze(artifacts);
Michael Landoefa037d2017-02-19 12:57:33 +020084
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030085 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +020086
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030087 let actionData = {
88 artifacts,
89 diagramType: enums.WORKFLOW,
90 participants: [],
91 serviceID: '1234'
92 };
93 FlowsActions.fetchFlowArtifacts(store.dispatch, actionData);
Michael Landoefa037d2017-02-19 12:57:33 +020094
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030095 let state = store.getState();
96 expect(state.flows.flowList.length).toEqual(artifactsArray.length);
97 expect(state.flows.flowParticipants).toEqual(actionData.participants);
98 expect(state.flows.serviceID).toBe(actionData.serviceID);
99 expect(state.flows.diagramType).toBe(actionData.diagramType);
100 });
Michael Landoefa037d2017-02-19 12:57:33 +0200101
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300102 it('Add New Flow', () => {
103 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +0200104
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300105 const flowCreateData = FlowCreateFactory.build();
106 let expectedDataToBeSentInTheRequest = buildFromExistingObject(
107 FlowPostRequestFactory,
108 flowCreateData
109 );
Michael Landoefa037d2017-02-19 12:57:33 +0200110
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300111 mockRest.addHandler('post', ({ data, baseUrl, options }) => {
112 expect(baseUrl).toBe(
113 `/sdc1/feProxy/rest/v1/catalog/services/${
114 flowCreateData.serviceID
115 }/artifacts/`
116 );
117 expect(data.artifactLabel).toBe(
118 expectedDataToBeSentInTheRequest.artifactLabel
119 );
120 expect(data.artifactName).toBe(
121 expectedDataToBeSentInTheRequest.artifactName
122 );
123 expect(data.artifactType).toBe(
124 expectedDataToBeSentInTheRequest.artifactType
125 );
126 expect(data.description).toBe(
127 expectedDataToBeSentInTheRequest.description
128 );
129 expect(data.payloadData).toBe(
130 expectedDataToBeSentInTheRequest.payloadData
131 );
132 expect(options.md5).toBe(true);
133 return buildFromExistingObject(
134 FlowPostResponseFactory,
135 expectedDataToBeSentInTheRequest
136 );
137 });
Michael Landoefa037d2017-02-19 12:57:33 +0200138
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300139 return FlowsActions.createOrUpdateFlow(
140 store.dispatch,
141 { flow: flowCreateData },
142 NEW_FLOW
143 ).then(() => {
144 assertFlowDataAfterCreateFetchAndUpdate(flowCreateData);
145 });
146 });
Michael Landoefa037d2017-02-19 12:57:33 +0200147
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300148 it('Fetch Flow', () => {
149 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +0200150
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300151 const flowFetchData = FlowFetchRequestFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200152
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300153 mockRest.addHandler('fetch', ({ baseUrl }) => {
154 //sdc1/feProxy/rest/v1/catalog/services/338d75f0-aec8-4eb4-89c9-8733fcd9bf3b/artifacts/338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi
155 expect(baseUrl).toBe(
156 `/sdc1/feProxy/rest/v1/catalog/services/${
157 flowFetchData.serviceID
158 }/artifacts/${flowFetchData.uniqueId}`
159 );
160 return buildFromExistingObject(
161 FlowFetchResponseFactory,
162 flowFetchData
163 );
164 });
Michael Landoefa037d2017-02-19 12:57:33 +0200165
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300166 return FlowsActions.fetchArtifact(store.dispatch, {
167 flow: flowFetchData
168 }).then(() => {
169 assertFlowDataAfterCreateFetchAndUpdate(flowFetchData);
170 });
171 });
Michael Landoefa037d2017-02-19 12:57:33 +0200172
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300173 it('Update Existing Flow', () => {
174 deepFreeze(store.getState());
175 const flowUpdateData = FlowUpdateRequestFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200176
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300177 mockRest.addHandler('post', ({ baseUrl }) => {
178 expect(baseUrl).toBe(
179 `/sdc1/feProxy/rest/v1/catalog/services/${
180 flowUpdateData.serviceID
181 }/artifacts/${flowUpdateData.uniqueId}`
182 );
Michael Landoefa037d2017-02-19 12:57:33 +0200183
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300184 return buildFromExistingObject(
185 FlowPostResponseFactory,
186 flowUpdateData
187 );
188 });
AviZi280f8012017-06-09 02:39:56 +0300189
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300190 return FlowsActions.createOrUpdateFlow(
191 store.dispatch,
192 { flow: flowUpdateData },
193 !NEW_FLOW
194 ).then(() => {
195 assertFlowDataAfterCreateFetchAndUpdate(flowUpdateData);
196 });
197 });
Michael Landoefa037d2017-02-19 12:57:33 +0200198
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300199 it('Delete Flow', () => {
200 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +0200201
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300202 const flowDeleteData = FlowDeleteRequestFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200203
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300204 mockRest.addHandler('destroy', ({ baseUrl }) => {
205 expect(baseUrl).toBe(
206 `/sdc1/feProxy/rest/v1/catalog/services/${
207 flowDeleteData.serviceID
208 }/artifacts/${flowDeleteData.uniqueId}`
209 );
210 return {};
211 });
Michael Landoefa037d2017-02-19 12:57:33 +0200212
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300213 return FlowsActions.deleteFlow(store.dispatch, {
214 flow: flowDeleteData
215 }).then(() => {
216 let { flowList } = store.getState().flows;
217 let index = flowList.findIndex(
218 flow => flow.uniqueId === flowDeleteData.uniqueId
219 );
220 expect(index).toBe(-1);
221 });
222 });
Michael Landoefa037d2017-02-19 12:57:33 +0200223});