2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import expect from 'expect';
22 import deepFreeze from 'deep-freeze';
23 import mockRest from 'test-utils/MockRest.js';
24 import store from 'sdc-app/AppStore.js';
25 import FlowsActions from 'sdc-app/flows/FlowsActions.js';
26 import {enums} from 'sdc-app/flows/FlowsConstants.js';
28 const NEW_FLOW = true;
30 let assertFlowDataAfterCreateFetchAndUpdate = (data) => {
31 let {flowList, serviceID, diagramType} = store.getState().flows;
32 expect(serviceID).toBe(data.serviceID);
33 expect(diagramType).toBe(data.artifactType);
34 let uniqueId = data.uniqueId || `${data.serviceID}.${data.artifactName}`;
35 let index = flowList.findIndex(flow => flow.uniqueId === uniqueId);
36 expect(index).toNotBe(-1);
39 describe('Workflows and Management Flows Module Tests:', function () {
42 it('empty artifact should open flow creation modal', done => {
46 deepFreeze(store.getState());
47 deepFreeze(artifacts);
48 FlowsActions.fetchFlowArtifacts(store.dispatch, {
50 diagramType: enums.WORKFLOW,
55 let state = store.getState();
56 expect(state.flows.isDisplayModal).toBe(true);
57 expect(state.flows.isModalInEditMode).toBe(false);
62 it('Close flow details editor modal', done => {
63 deepFreeze(store.getState());
64 FlowsActions.closeFlowDetailsEditor(store.dispatch);
66 let state = store.getState();
67 expect(state.flows.isDisplayModal).toBe(false);
68 expect(state.flows.isModalInEditMode).toBe(false);
73 it('Get Flows List from loaded artifact', done => {
75 deepFreeze(store.getState());
79 'uniqueId': '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.test1',
80 'artifactType': 'NETWORK_CALL_FLOW',
81 'artifactName': 'test1',
82 'artifactChecksum': 'MzYxZGIyNjlkNjRmMTM4ZWMxM2FjNDUyNDQwMTI3NzM=',
83 'attUidLastUpdater': 'cs0008',
84 'updaterFullName': 'Carlos Santana',
85 'creationDate': 1468164899724,
86 'lastUpdateDate': 1468164899724,
87 'esId': '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.test1',
88 'artifactLabel': 'test1',
89 'artifactCreator': 'cs0008',
92 'artifactDisplayName': 'test1',
94 'artifactGroupType': 'INFORMATIONAL',
96 'artifactVersion': '1',
97 'artifactUUID': '28d4cb95-bb46-4666-b858-e333671e6444',
98 'payloadUpdateDate': 1468164900232
101 'uniqueId': '0280b577-2c7b-426e-b7a2-f0dc16508c37.kukuriku',
102 'artifactType': 'PUPPET',
103 'artifactName': 'fuel.JPG',
104 'artifactChecksum': 'OWEyYTVjMWFiNWQ4ZDIwZDUxYTE3Y2EzZmI3YTYyMjA=',
105 'attUidLastUpdater': 'cs0008',
106 'updaterFullName': 'Carlos Santana',
107 'creationDate': 1467877631512,
108 'lastUpdateDate': 1467877631512,
109 'esId': '0280b577-2c7b-426e-b7a2-f0dc16508c37.kukuriku',
110 'artifactLabel': 'kukuriku',
111 'artifactCreator': 'cs0008',
112 'description': 'asdfasdf',
114 'artifactDisplayName': 'kukuriku',
116 'artifactGroupType': 'INFORMATIONAL',
118 'artifactVersion': '1',
119 'artifactUUID': 'c1e98336-03f4-4b2a-b6a5-08eca44fe3c4',
120 'payloadUpdateDate': 1467877632722
123 'uniqueId': '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.test3',
124 'artifactType': 'NETWORK_CALL_FLOW',
125 'artifactName': 'test3',
126 'artifactChecksum': 'ZmJkZGU1M2M2ZWUxZTdmNGU5NTNiNTdiYTAzMmM1YzU=',
127 'attUidLastUpdater': 'cs0008',
128 'updaterFullName': 'Carlos Santana',
129 'creationDate': 1468165068570,
130 'lastUpdateDate': 1468165128827,
131 'esId': '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.test3',
132 'artifactLabel': 'test3',
133 'artifactCreator': 'cs0008',
134 'description': '333',
136 'artifactDisplayName': 'test3',
138 'artifactGroupType': 'INFORMATIONAL',
140 'artifactVersion': '2',
141 'artifactUUID': '0988027c-d19c-43db-8315-2c68fc773775',
142 'payloadUpdateDate': 1468165129335
146 const artifactsArray = Object.keys(artifacts).map(artifact => artifact);
148 deepFreeze(artifacts);
150 deepFreeze(store.getState());
154 diagramType: enums.WORKFLOW,
158 FlowsActions.fetchFlowArtifacts(store.dispatch, actionData);
161 let state = store.getState();
162 expect(state.flows.isDisplayModal).toBe(false);
163 expect(state.flows.isModalInEditMode).toBe(false);
164 expect(state.flows.flowList.length).toEqual(artifactsArray.length);
165 expect(state.flows.flowParticipants).toEqual(actionData.participants);
166 expect(state.flows.serviceID).toBe(actionData.serviceID);
167 expect(state.flows.diagramType).toBe(actionData.diagramType);
174 it('Add New Flow', done => {
176 deepFreeze(store.getState());
178 const flowCreateData = deepFreeze({
179 artifactName: 'zizizi',
180 artifactType: 'WORKFLOW',
181 description: 'aslkjdfl asfdasdf',
182 serviceID: '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b',
186 let expectedDataToBeSentInTheRequest = {
187 artifactGroupType: 'INFORMATIONAL',
188 artifactLabel: 'zizizi',
189 artifactName: 'zizizi',
190 artifactType: 'WORKFLOW',
191 description: 'aslkjdfl asfdasdf',
192 payloadData: 'eyJWRVJTSU9OIjp7Im1ham9yIjoxLCJtaW5vciI6MH0sImRlc2NyaXB0aW9uIjoiYXNsa2pkZmwgYXNmZGFzZGYifQ=='
194 mockRest.addHandler('create', ({data, baseUrl, options}) => {
195 expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowCreateData.serviceID}/artifacts/`);
196 expect(data.artifactLabel).toBe(expectedDataToBeSentInTheRequest.artifactLabel);
197 expect(data.artifactName).toBe(expectedDataToBeSentInTheRequest.artifactName);
198 expect(data.artifactType).toBe(expectedDataToBeSentInTheRequest.artifactType);
199 expect(data.description).toBe(expectedDataToBeSentInTheRequest.description);
200 expect(data.payloadData).toBe(expectedDataToBeSentInTheRequest.payloadData);
201 expect(options.md5).toBe(true);
203 artifactChecksum: 'NjBmYjc4NGM5MWIwNmNkMDhmMThhMDAwYmQxYjBiZTU=',
204 artifactCreator: 'cs0008',
205 artifactDisplayName: 'zizizi',
206 artifactGroupType: 'INFORMATIONAL',
207 artifactLabel: 'zizizi',
208 artifactName: 'zizizi',
209 artifactType: 'WORKFLOW',
210 artifactUUID: '0295a7cc-8c02-4105-9d7e-c30ce67ecd07',
211 artifactVersion: '1',
212 attUidLastUpdater: 'cs0008',
213 creationDate: 1470144601623,
214 description: 'aslkjdfl asfdasdf',
215 esId: '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
216 lastUpdateDate: 1470144601623,
218 payloadUpdateDate: 1470144602131,
221 uniqueId: '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
222 updaterFullName: 'Carlos Santana',
226 FlowsActions.createOrUpdateFlow(store.dispatch, {flow: flowCreateData}, NEW_FLOW);
229 assertFlowDataAfterCreateFetchAndUpdate(flowCreateData);
234 it('Fetch Flow', done => {
236 deepFreeze(store.getState());
238 const flowFetchData = {
239 artifactName: 'zizizi',
240 artifactType: 'WORKFLOW',
241 description: 'aslkjdfl asfdasdf',
242 serviceID: '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b',
243 uniqueId: '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
247 mockRest.addHandler('fetch', ({baseUrl}) => {
248 //sdc1/feProxy/rest/v1/catalog/services/338d75f0-aec8-4eb4-89c9-8733fcd9bf3b/artifacts/338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi
249 expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowFetchData.serviceID}/artifacts/${flowFetchData.uniqueId}`);
251 artifactName: 'zizizi',
252 base64Contents: 'eyJWRVJTSU9OIjp7Im1ham9yIjoxLCJtaW5vciI6MH0sImRlc2NyaXB0aW9uIjoiYXNsa2pkZmwgYXNmZGFzZGYifQ=='
256 FlowsActions.fetchArtifact(store.dispatch, {flow: flowFetchData});
259 assertFlowDataAfterCreateFetchAndUpdate(flowFetchData);
264 it('Update Existing Flow', done => {
266 deepFreeze(store.getState());
268 const flowUpdateData = {
269 'artifactType': 'WORKFLOW',
281 'name': 'Infrastructure'
316 'serviceID': '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b',
317 'artifactDisplayName': 'zizizi',
318 'artifactGroupType': 'INFORMATIONAL',
319 'uniqueId': '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
320 'artifactName': 'zizizi',
321 'artifactLabel': 'zizizi',
322 'artifactUUID': '0295a7cc-8c02-4105-9d7e-c30ce67ecd07',
323 'artifactVersion': '1',
324 'creationDate': 1470144601623,
325 'lastUpdateDate': 1470144601623,
326 'description': 'aslkjdfl asfdasdf',
329 'esId': '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
330 'artifactChecksum': 'NjBmYjc4NGM5MWIwNmNkMDhmMThhMDAwYmQxYjBiZTU=',
331 'heatParameters': [],
332 'sequenceDiagramModel': {
335 'id': '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
354 'name': 'Infrastructure',
410 'id': '9377-5036-c011-cb95-3a8b-82c6-bbb5-bc84',
411 'name': '[Unnamed Message]',
420 'id': '64c4-4fd1-b1da-4355-a060-6e48-ee47-c85c',
421 'name': '[Unnamed Message]',
433 mockRest.addHandler('create', ({baseUrl}) => {
434 expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowUpdateData.serviceID}/artifacts/${flowUpdateData.uniqueId}`);
437 artifactChecksum: 'MmE5MWJmN2ZlN2FhM2JhMzA0NGQ1ODMyOWFhNWI0NDA=',
438 artifactCreator: 'cs0008',
439 artifactDisplayName: 'zizizi',
440 artifactGroupType: 'INFORMATIONAL',
441 artifactLabel: 'zizizi',
442 artifactName: 'zizizi',
443 artifactType: 'WORKFLOW',
444 artifactUUID: '3319335b-969e-4d72-b5a2-409645de6d64',
445 artifactVersion: '3',
446 attUidLastUpdater: 'cs0008',
447 creationDate: 1470144601623,
448 description: 'aslkjdfl asfdasdf',
449 esId: '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
450 lastUpdateDate: 1470208425904,
452 payloadUpdateDate: 1470208426424,
455 uniqueId: '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
456 updaterFullName: 'Carlos Santana'
460 FlowsActions.createOrUpdateFlow(store.dispatch, {flow: flowUpdateData}, !NEW_FLOW);
463 assertFlowDataAfterCreateFetchAndUpdate(flowUpdateData);
468 it('Delete Flow', done => {
470 deepFreeze(store.getState());
472 const flowDeleteData = deepFreeze({
473 artifactName: 'zizizi',
474 artifactType: 'WORKFLOW',
475 description: 'aslkjdfl asfdasdf',
476 serviceID: '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b',
477 uniqueId: '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
481 mockRest.addHandler('destroy', ({baseUrl}) => {
482 expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowDeleteData.serviceID}/artifacts/${flowDeleteData.uniqueId}`);
486 FlowsActions.deleteFlow(store.dispatch, {flow: flowDeleteData});
489 let {flowList} = store.getState().flows;
490 let index = flowList.findIndex(flow => flow.uniqueId === flowDeleteData.uniqueId);
491 expect(index).toBe(-1);