blob: 4c5ab786401a75faf7310d8eb9f659afd5454a26 [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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=========================================================
19 */
20
21import expect from 'expect';
22import deepFreeze from 'deep-freeze';
23import mockRest from 'test-utils/MockRest.js';
24import store from 'sdc-app/AppStore.js';
25import FlowsActions from 'sdc-app/flows/FlowsActions.js';
26import {enums} from 'sdc-app/flows/FlowsConstants.js';
27
28const NEW_FLOW = true;
29
30let 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);
37};
38
39describe('Workflows and Management Flows Module Tests:', function () {
40
41
42 it('empty artifact should open flow creation modal', done => {
43
44 const artifacts = {};
45
46 deepFreeze(store.getState());
47 deepFreeze(artifacts);
48 FlowsActions.fetchFlowArtifacts(store.dispatch, {
49 artifacts,
50 diagramType: enums.WORKFLOW,
51 participants: [],
52 serviceID: '1234'
53 });
54 setTimeout(() => {
55 let state = store.getState();
56 expect(state.flows.isDisplayModal).toBe(true);
57 expect(state.flows.isModalInEditMode).toBe(false);
58 done();
59 }, 50);
60 });
61
62 it('Close flow details editor modal', done => {
63 deepFreeze(store.getState());
64 FlowsActions.closeFlowDetailsEditor(store.dispatch);
65 setTimeout(() => {
66 let state = store.getState();
67 expect(state.flows.isDisplayModal).toBe(false);
68 expect(state.flows.isModalInEditMode).toBe(false);
69 done();
70 }, 50);
71 });
72
73 it('Get Flows List from loaded artifact', done => {
74
75 deepFreeze(store.getState());
76
77 const artifacts = {
78 'test1': {
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',
90 'description': 'www',
91 'mandatory': false,
92 'artifactDisplayName': 'test1',
93 'serviceApi': false,
94 'artifactGroupType': 'INFORMATIONAL',
95 'timeout': 0,
96 'artifactVersion': '1',
97 'artifactUUID': '28d4cb95-bb46-4666-b858-e333671e6444',
98 'payloadUpdateDate': 1468164900232
99 },
100 'kukuriku': {
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',
113 'mandatory': false,
114 'artifactDisplayName': 'kukuriku',
115 'serviceApi': false,
116 'artifactGroupType': 'INFORMATIONAL',
117 'timeout': 0,
118 'artifactVersion': '1',
119 'artifactUUID': 'c1e98336-03f4-4b2a-b6a5-08eca44fe3c4',
120 'payloadUpdateDate': 1467877632722
121 },
122 'test3': {
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',
135 'mandatory': false,
136 'artifactDisplayName': 'test3',
137 'serviceApi': false,
138 'artifactGroupType': 'INFORMATIONAL',
139 'timeout': 0,
140 'artifactVersion': '2',
141 'artifactUUID': '0988027c-d19c-43db-8315-2c68fc773775',
142 'payloadUpdateDate': 1468165129335
143 }
144 };
145
146 const artifactsArray = Object.keys(artifacts).map(artifact => artifact);
147
148 deepFreeze(artifacts);
149
150 deepFreeze(store.getState());
151
152 let actionData = {
153 artifacts,
154 diagramType: enums.WORKFLOW,
155 participants: [],
156 serviceID: '1234'
157 };
158 FlowsActions.fetchFlowArtifacts(store.dispatch, actionData);
159
160 setTimeout(() => {
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);
168 done();
169 }, 50);
170
171 });
172
173
174 it('Add New Flow', done => {
175
176 deepFreeze(store.getState());
177
178 const flowCreateData = deepFreeze({
179 artifactName: 'zizizi',
180 artifactType: 'WORKFLOW',
181 description: 'aslkjdfl asfdasdf',
182 serviceID: '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b',
183 });
184
185
186 let expectedDataToBeSentInTheRequest = {
187 artifactGroupType: 'INFORMATIONAL',
188 artifactLabel: 'zizizi',
189 artifactName: 'zizizi',
190 artifactType: 'WORKFLOW',
191 description: 'aslkjdfl asfdasdf',
192 payloadData: 'eyJWRVJTSU9OIjp7Im1ham9yIjoxLCJtaW5vciI6MH0sImRlc2NyaXB0aW9uIjoiYXNsa2pkZmwgYXNmZGFzZGYifQ=='
193 };
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);
202 return {
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,
217 mandatory: false,
218 payloadUpdateDate: 1470144602131,
219 serviceApi: false,
220 timeout: 0,
221 uniqueId: '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
222 updaterFullName: 'Carlos Santana',
223 };
224 });
225
226 FlowsActions.createOrUpdateFlow(store.dispatch, {flow: flowCreateData}, NEW_FLOW);
227
228 setTimeout(() => {
229 assertFlowDataAfterCreateFetchAndUpdate(flowCreateData);
230 done();
231 }, 50);
232 });
233
234 it('Fetch Flow', done => {
235
236 deepFreeze(store.getState());
237
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',
244 participants: []
245 };
246
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}`);
250 return {
251 artifactName: 'zizizi',
252 base64Contents: 'eyJWRVJTSU9OIjp7Im1ham9yIjoxLCJtaW5vciI6MH0sImRlc2NyaXB0aW9uIjoiYXNsa2pkZmwgYXNmZGFzZGYifQ=='
253 };
254 });
255
256 FlowsActions.fetchArtifact(store.dispatch, {flow: flowFetchData});
257
258 setTimeout(() => {
259 assertFlowDataAfterCreateFetchAndUpdate(flowFetchData);
260 done();
261 }, 50);
262 });
263
264 it('Update Existing Flow', done => {
265
266 deepFreeze(store.getState());
267
268 const flowUpdateData = {
269 'artifactType': 'WORKFLOW',
270 'participants': [
271 {
272 'id': '1',
273 'name': 'Customer'
274 },
275 {
276 'id': '2',
277 'name': 'CCD'
278 },
279 {
280 'id': '3',
281 'name': 'Infrastructure'
282 },
283 {
284 'id': '4',
285 'name': 'MSO'
286 },
287 {
288 'id': '5',
289 'name': 'SDN-C'
290 },
291 {
292 'id': '6',
293 'name': 'A&AI'
294 },
295 {
296 'id': '7',
297 'name': 'APP-C'
298 },
299 {
300 'id': '8',
301 'name': 'Cloud'
302 },
303 {
304 'id': '9',
305 'name': 'DCAE'
306 },
307 {
308 'id': '10',
309 'name': 'ALTS'
310 },
311 {
312 'id': '11',
313 'name': 'VF'
314 }
315 ],
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',
327 'mandatory': false,
328 'timeout': 0,
329 'esId': '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
330 'artifactChecksum': 'NjBmYjc4NGM5MWIwNmNkMDhmMThhMDAwYmQxYjBiZTU=',
331 'heatParameters': [],
332 'sequenceDiagramModel': {
333 'diagram': {
334 'metadata': {
335 'id': '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
336 'name': 'zizizi',
337 'ref': 'BLANK'
338 },
339 'lifelines': [
340 {
341 'id': '1',
342 'name': 'Customer',
343 'index': 1,
344 'x': 175
345 },
346 {
347 'id': '2',
348 'name': 'CCD',
349 'index': 2,
350 'x': 575
351 },
352 {
353 'id': '3',
354 'name': 'Infrastructure',
355 'index': 3,
356 'x': 975
357 },
358 {
359 'id': '4',
360 'name': 'MSO',
361 'index': 4,
362 'x': 1375
363 },
364 {
365 'id': '5',
366 'name': 'SDN-C',
367 'index': 5,
368 'x': 1775
369 },
370 {
371 'id': '6',
372 'name': 'A&AI',
373 'index': 6,
374 'x': 2175
375 },
376 {
377 'id': '7',
378 'name': 'APP-C',
379 'index': 7,
380 'x': 2575
381 },
382 {
383 'id': '8',
384 'name': 'Cloud',
385 'index': 8,
386 'x': 2975
387 },
388 {
389 'id': '9',
390 'name': 'DCAE',
391 'index': 9,
392 'x': 3375
393 },
394 {
395 'id': '10',
396 'name': 'ALTS',
397 'index': 10,
398 'x': 3775
399 },
400 {
401 'id': '11',
402 'name': 'VF',
403 'index': 11,
404 'x': 4175
405 }
406 ],
407 'steps': [
408 {
409 'message': {
410 'id': '9377-5036-c011-cb95-3a8b-82c6-bbb5-bc84',
411 'name': '[Unnamed Message]',
412 'type': 'request',
413 'from': '1',
414 'to': '2',
415 'index': 1
416 }
417 },
418 {
419 'message': {
420 'id': '64c4-4fd1-b1da-4355-a060-6e48-ee47-c85c',
421 'name': '[Unnamed Message]',
422 'type': 'request',
423 'from': '1',
424 'to': '2',
425 'index': 2
426 }
427 }
428 ]
429 }
430 }
431 };
432
433 mockRest.addHandler('create', ({baseUrl}) => {
434 expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowUpdateData.serviceID}/artifacts/${flowUpdateData.uniqueId}`);
435
436 return {
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,
451 mandatory: false,
452 payloadUpdateDate: 1470208426424,
453 serviceApi: false,
454 timeout: 0,
455 uniqueId: '338d75f0-aec8-4eb4-89c9-8733fcd9bf3b.zizizi',
456 updaterFullName: 'Carlos Santana'
457 };
458 });
459
460 FlowsActions.createOrUpdateFlow(store.dispatch, {flow: flowUpdateData}, !NEW_FLOW);
461
462 setTimeout(() => {
463 assertFlowDataAfterCreateFetchAndUpdate(flowUpdateData);
464 done();
465 }, 50);
466 });
467
468 it('Delete Flow', done => {
469
470 deepFreeze(store.getState());
471
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',
478 participants: []
479 });
480
481 mockRest.addHandler('destroy', ({baseUrl}) => {
482 expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowDeleteData.serviceID}/artifacts/${flowDeleteData.uniqueId}`);
483 return {};
484 });
485
486 FlowsActions.deleteFlow(store.dispatch, {flow: flowDeleteData});
487
488 setTimeout(() => {
489 let {flowList} = store.getState().flows;
490 let index = flowList.findIndex(flow => flow.uniqueId === flowDeleteData.uniqueId);
491 expect(index).toBe(-1);
492 done();
493 }, 50);
494 });
495
496});
497