2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
13 * or implied. See the License for the specific language governing
14 * permissions and 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 } from 'test-utils/factories/flows/FlowsFactories.js';
32 import {buildFromExistingObject} from 'test-utils/Util.js';
34 const NEW_FLOW = true;
36 let assertFlowDataAfterCreateFetchAndUpdate = (data) => {
37 let {flowList, serviceID, diagramType} = store.getState().flows;
38 expect(serviceID).toBe(data.serviceID);
39 expect(diagramType).toBe(data.artifactType);
40 let uniqueId = data.uniqueId || `${data.serviceID}.${data.artifactName}`;
41 let index = flowList.findIndex(flow => flow.uniqueId === uniqueId);
42 expect(index).not.toBe(-1);
45 describe('Workflows and Management Flows Module Tests:', function () {
48 it('empty artifact should open flow creation modal', () => {
52 deepFreeze(store.getState());
53 deepFreeze(artifacts);
54 FlowsActions.fetchFlowArtifacts(store.dispatch, {
56 diagramType: enums.WORKFLOW,
60 let state = store.getState();
61 expect(state.flows.isDisplayModal).toBe(true);
62 expect(state.flows.isModalInEditMode).toBe(false);
65 it('Close flow details editor modal', () => {
66 deepFreeze(store.getState());
67 FlowsActions.closeFlowDetailsEditor(store.dispatch);
68 let state = store.getState();
69 expect(state.flows.isDisplayModal).toBe(false);
70 expect(state.flows.isModalInEditMode).toBe(false);
73 it('Get Flows List from loaded artifact', () => {
75 deepFreeze(store.getState());
78 'test1': FlowPostResponseFactory.build({artifactName: 'test1'}),
79 'kukuriku': FlowPostResponseFactory.build({
80 'artifactType': 'PUPPET',
81 'artifactName': 'kukuriku',
83 'test3': FlowPostResponseFactory.build({artifactName: 'test3'})
86 const artifactsArray = Object.keys(artifacts).map(artifact => artifact);
88 deepFreeze(artifacts);
90 deepFreeze(store.getState());
94 diagramType: enums.WORKFLOW,
98 FlowsActions.fetchFlowArtifacts(store.dispatch, actionData);
100 let state = store.getState();
101 expect(state.flows.isDisplayModal).toBe(false);
102 expect(state.flows.isModalInEditMode).toBe(false);
103 expect(state.flows.flowList.length).toEqual(artifactsArray.length);
104 expect(state.flows.flowParticipants).toEqual(actionData.participants);
105 expect(state.flows.serviceID).toBe(actionData.serviceID);
106 expect(state.flows.diagramType).toBe(actionData.diagramType);
111 it('Add New Flow', () => {
113 deepFreeze(store.getState());
115 const flowCreateData = FlowCreateFactory.build();
116 let expectedDataToBeSentInTheRequest = buildFromExistingObject(FlowPostRequestFactory, flowCreateData);
118 mockRest.addHandler('post', ({data, baseUrl, options}) => {
119 expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowCreateData.serviceID}/artifacts/`);
120 expect(data.artifactLabel).toBe(expectedDataToBeSentInTheRequest.artifactLabel);
121 expect(data.artifactName).toBe(expectedDataToBeSentInTheRequest.artifactName);
122 expect(data.artifactType).toBe(expectedDataToBeSentInTheRequest.artifactType);
123 expect(data.description).toBe(expectedDataToBeSentInTheRequest.description);
124 expect(data.payloadData).toBe(expectedDataToBeSentInTheRequest.payloadData);
125 expect(options.md5).toBe(true);
126 return buildFromExistingObject(FlowPostResponseFactory, expectedDataToBeSentInTheRequest);
129 return FlowsActions.createOrUpdateFlow(store.dispatch, {flow: flowCreateData}, NEW_FLOW).then(() => {
130 assertFlowDataAfterCreateFetchAndUpdate(flowCreateData);
136 it('Fetch Flow', () => {
138 deepFreeze(store.getState());
140 const flowFetchData = FlowFetchRequestFactory.build();
142 mockRest.addHandler('fetch', ({baseUrl}) => {
143 //sdc1/feProxy/rest/v1/catalog/services/338d75f0-aec8-4eb4-89c9-8733fcd9bf3b/artifacts/338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi
144 expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowFetchData.serviceID}/artifacts/${flowFetchData.uniqueId}`);
145 return buildFromExistingObject(FlowFetchResponseFactory, flowFetchData);
148 return FlowsActions.fetchArtifact(store.dispatch, {flow: flowFetchData}).then(() => {
149 assertFlowDataAfterCreateFetchAndUpdate(flowFetchData);
153 it('Update Existing Flow', () => {
155 deepFreeze(store.getState());
156 const flowUpdateData = FlowUpdateRequestFactory.build();
158 mockRest.addHandler('post', ({baseUrl}) => {
159 expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowUpdateData.serviceID}/artifacts/${flowUpdateData.uniqueId}`);
161 return buildFromExistingObject(FlowPostResponseFactory, flowUpdateData);
164 return FlowsActions.createOrUpdateFlow(store.dispatch, {flow: flowUpdateData}, !NEW_FLOW).then(() => {
165 assertFlowDataAfterCreateFetchAndUpdate(flowUpdateData);
170 it('Delete Flow', () => {
172 deepFreeze(store.getState());
174 const flowDeleteData = FlowDeleteRequestFactory.build();
176 mockRest.addHandler('destroy', ({baseUrl}) => {
177 expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowDeleteData.serviceID}/artifacts/${flowDeleteData.uniqueId}`);
181 return FlowsActions.deleteFlow(store.dispatch, {flow: flowDeleteData}).then(() => {
182 let {flowList} = store.getState().flows;
183 let index = flowList.findIndex(flow => flow.uniqueId === flowDeleteData.uniqueId);
184 expect(index).toBe(-1);