2 * Copyright © 2016-2018 European Support Limited
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.
17 import deepFreeze from 'deep-freeze';
18 import mockRest from 'test-utils/MockRest.js';
19 import store from 'sdc-app/AppStore.js';
20 import FlowsActions from 'sdc-app/flows/FlowsActions.js';
21 import { enums } from 'sdc-app/flows/FlowsConstants.js';
25 FlowPostRequestFactory,
26 FlowPostResponseFactory,
27 FlowFetchRequestFactory,
28 FlowFetchResponseFactory,
29 FlowDeleteRequestFactory,
30 FlowUpdateRequestFactory
31 } from 'test-utils/factories/flows/FlowsFactories.js';
33 import { buildFromExistingObject } from 'test-utils/Util.js';
35 const NEW_FLOW = true;
37 let 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);
46 describe('Workflows and Management Flows Module Tests:', function() {
47 it('empty artifact should open flow creation modal', () => {
50 deepFreeze(store.getState());
51 deepFreeze(artifacts);
52 FlowsActions.fetchFlowArtifacts(store.dispatch, {
54 diagramType: enums.WORKFLOW,
58 let state = store.getState();
59 expect(state.modal).toBeDefined();
62 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();
69 it('Get Flows List from loaded artifact', () => {
70 deepFreeze(store.getState());
73 test1: FlowPostResponseFactory.build({ artifactName: 'test1' }),
74 kukuriku: FlowPostResponseFactory.build({
75 artifactType: 'PUPPET',
76 artifactName: 'kukuriku'
78 test3: FlowPostResponseFactory.build({ artifactName: 'test3' })
81 const artifactsArray = Object.keys(artifacts).map(artifact => artifact);
83 deepFreeze(artifacts);
85 deepFreeze(store.getState());
89 diagramType: enums.WORKFLOW,
93 FlowsActions.fetchFlowArtifacts(store.dispatch, actionData);
95 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);
102 it('Add New Flow', () => {
103 deepFreeze(store.getState());
105 const flowCreateData = FlowCreateFactory.build();
106 let expectedDataToBeSentInTheRequest = buildFromExistingObject(
107 FlowPostRequestFactory,
111 mockRest.addHandler('post', ({ data, baseUrl, options }) => {
112 expect(baseUrl).toBe(
113 `/sdc1/feProxy/rest/v1/catalog/services/${
114 flowCreateData.serviceID
117 expect(data.artifactLabel).toBe(
118 expectedDataToBeSentInTheRequest.artifactLabel
120 expect(data.artifactName).toBe(
121 expectedDataToBeSentInTheRequest.artifactName
123 expect(data.artifactType).toBe(
124 expectedDataToBeSentInTheRequest.artifactType
126 expect(data.description).toBe(
127 expectedDataToBeSentInTheRequest.description
129 expect(data.payloadData).toBe(
130 expectedDataToBeSentInTheRequest.payloadData
132 expect(options.md5).toBe(true);
133 return buildFromExistingObject(
134 FlowPostResponseFactory,
135 expectedDataToBeSentInTheRequest
139 return FlowsActions.createOrUpdateFlow(
141 { flow: flowCreateData },
144 assertFlowDataAfterCreateFetchAndUpdate(flowCreateData);
148 it('Fetch Flow', () => {
149 deepFreeze(store.getState());
151 const flowFetchData = FlowFetchRequestFactory.build();
153 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}`
160 return buildFromExistingObject(
161 FlowFetchResponseFactory,
166 return FlowsActions.fetchArtifact(store.dispatch, {
169 assertFlowDataAfterCreateFetchAndUpdate(flowFetchData);
173 it('Update Existing Flow', () => {
174 deepFreeze(store.getState());
175 const flowUpdateData = FlowUpdateRequestFactory.build();
177 mockRest.addHandler('post', ({ baseUrl }) => {
178 expect(baseUrl).toBe(
179 `/sdc1/feProxy/rest/v1/catalog/services/${
180 flowUpdateData.serviceID
181 }/artifacts/${flowUpdateData.uniqueId}`
184 return buildFromExistingObject(
185 FlowPostResponseFactory,
190 return FlowsActions.createOrUpdateFlow(
192 { flow: flowUpdateData },
195 assertFlowDataAfterCreateFetchAndUpdate(flowUpdateData);
199 it('Delete Flow', () => {
200 deepFreeze(store.getState());
202 const flowDeleteData = FlowDeleteRequestFactory.build();
204 mockRest.addHandler('destroy', ({ baseUrl }) => {
205 expect(baseUrl).toBe(
206 `/sdc1/feProxy/rest/v1/catalog/services/${
207 flowDeleteData.serviceID
208 }/artifacts/${flowDeleteData.uniqueId}`
213 return FlowsActions.deleteFlow(store.dispatch, {
216 let { flowList } = store.getState().flows;
217 let index = flowList.findIndex(
218 flow => flow.uniqueId === flowDeleteData.uniqueId
220 expect(index).toBe(-1);