blob: 6e02e54816a85658bbf11ea57bdf3d4d00064f0f [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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,
AviZi280f8012017-06-09 02:39:56 +030012 * 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.
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';
21import {enums} from 'sdc-app/flows/FlowsConstants.js';
22
AviZi280f8012017-06-09 02:39:56 +030023import {
24 FlowCreateFactory,
25 FlowPostRequestFactory,
26 FlowPostResponseFactory,
27 FlowFetchRequestFactory,
28 FlowFetchResponseFactory,
29 FlowDeleteRequestFactory,
30 FlowUpdateRequestFactory } from 'test-utils/factories/flows/FlowsFactories.js';
31
32import {buildFromExistingObject} from 'test-utils/Util.js';
33
Michael Landoefa037d2017-02-19 12:57:33 +020034const NEW_FLOW = true;
35
36let 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);
AviZi280f8012017-06-09 02:39:56 +030042 expect(index).not.toBe(-1);
Michael Landoefa037d2017-02-19 12:57:33 +020043};
44
45describe('Workflows and Management Flows Module Tests:', function () {
46
47
AviZi280f8012017-06-09 02:39:56 +030048 it('empty artifact should open flow creation modal', () => {
Michael Landoefa037d2017-02-19 12:57:33 +020049
50 const artifacts = {};
51
52 deepFreeze(store.getState());
53 deepFreeze(artifacts);
54 FlowsActions.fetchFlowArtifacts(store.dispatch, {
55 artifacts,
56 diagramType: enums.WORKFLOW,
57 participants: [],
58 serviceID: '1234'
59 });
AviZi280f8012017-06-09 02:39:56 +030060 let state = store.getState();
61 expect(state.flows.isDisplayModal).toBe(true);
62 expect(state.flows.isModalInEditMode).toBe(false);
Michael Landoefa037d2017-02-19 12:57:33 +020063 });
64
AviZi280f8012017-06-09 02:39:56 +030065 it('Close flow details editor modal', () => {
Michael Landoefa037d2017-02-19 12:57:33 +020066 deepFreeze(store.getState());
67 FlowsActions.closeFlowDetailsEditor(store.dispatch);
AviZi280f8012017-06-09 02:39:56 +030068 let state = store.getState();
69 expect(state.flows.isDisplayModal).toBe(false);
70 expect(state.flows.isModalInEditMode).toBe(false);
Michael Landoefa037d2017-02-19 12:57:33 +020071 });
72
AviZi280f8012017-06-09 02:39:56 +030073 it('Get Flows List from loaded artifact', () => {
Michael Landoefa037d2017-02-19 12:57:33 +020074
75 deepFreeze(store.getState());
76
77 const artifacts = {
AviZi280f8012017-06-09 02:39:56 +030078 'test1': FlowPostResponseFactory.build({artifactName: 'test1'}),
79 'kukuriku': FlowPostResponseFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +020080 'artifactType': 'PUPPET',
AviZi280f8012017-06-09 02:39:56 +030081 'artifactName': 'kukuriku',
82 }),
83 'test3': FlowPostResponseFactory.build({artifactName: 'test3'})
Michael Landoefa037d2017-02-19 12:57:33 +020084 };
85
86 const artifactsArray = Object.keys(artifacts).map(artifact => artifact);
87
88 deepFreeze(artifacts);
89
90 deepFreeze(store.getState());
91
92 let actionData = {
93 artifacts,
94 diagramType: enums.WORKFLOW,
95 participants: [],
96 serviceID: '1234'
97 };
98 FlowsActions.fetchFlowArtifacts(store.dispatch, actionData);
99
AviZi280f8012017-06-09 02:39:56 +0300100 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);
Michael Landoefa037d2017-02-19 12:57:33 +0200107
108 });
109
110
AviZi280f8012017-06-09 02:39:56 +0300111 it('Add New Flow', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200112
113 deepFreeze(store.getState());
114
AviZi280f8012017-06-09 02:39:56 +0300115 const flowCreateData = FlowCreateFactory.build();
116 let expectedDataToBeSentInTheRequest = buildFromExistingObject(FlowPostRequestFactory, flowCreateData);
Michael Landoefa037d2017-02-19 12:57:33 +0200117
AviZi280f8012017-06-09 02:39:56 +0300118 mockRest.addHandler('post', ({data, baseUrl, options}) => {
Michael Landoefa037d2017-02-19 12:57:33 +0200119 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);
AviZi280f8012017-06-09 02:39:56 +0300126 return buildFromExistingObject(FlowPostResponseFactory, expectedDataToBeSentInTheRequest);
Michael Landoefa037d2017-02-19 12:57:33 +0200127 });
128
AviZi280f8012017-06-09 02:39:56 +0300129 return FlowsActions.createOrUpdateFlow(store.dispatch, {flow: flowCreateData}, NEW_FLOW).then(() => {
Michael Landoefa037d2017-02-19 12:57:33 +0200130 assertFlowDataAfterCreateFetchAndUpdate(flowCreateData);
AviZi280f8012017-06-09 02:39:56 +0300131 });
132
133
Michael Landoefa037d2017-02-19 12:57:33 +0200134 });
135
AviZi280f8012017-06-09 02:39:56 +0300136 it('Fetch Flow', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200137
138 deepFreeze(store.getState());
139
AviZi280f8012017-06-09 02:39:56 +0300140 const flowFetchData = FlowFetchRequestFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200141
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}`);
AviZi280f8012017-06-09 02:39:56 +0300145 return buildFromExistingObject(FlowFetchResponseFactory, flowFetchData);
Michael Landoefa037d2017-02-19 12:57:33 +0200146 });
147
AviZi280f8012017-06-09 02:39:56 +0300148 return FlowsActions.fetchArtifact(store.dispatch, {flow: flowFetchData}).then(() => {
Michael Landoefa037d2017-02-19 12:57:33 +0200149 assertFlowDataAfterCreateFetchAndUpdate(flowFetchData);
AviZi280f8012017-06-09 02:39:56 +0300150 });
Michael Landoefa037d2017-02-19 12:57:33 +0200151 });
152
AviZi280f8012017-06-09 02:39:56 +0300153 it('Update Existing Flow', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200154
155 deepFreeze(store.getState());
AviZi280f8012017-06-09 02:39:56 +0300156 const flowUpdateData = FlowUpdateRequestFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200157
AviZi280f8012017-06-09 02:39:56 +0300158 mockRest.addHandler('post', ({baseUrl}) => {
Michael Landoefa037d2017-02-19 12:57:33 +0200159 expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowUpdateData.serviceID}/artifacts/${flowUpdateData.uniqueId}`);
160
AviZi280f8012017-06-09 02:39:56 +0300161 return buildFromExistingObject(FlowPostResponseFactory, flowUpdateData);
Michael Landoefa037d2017-02-19 12:57:33 +0200162 });
163
AviZi280f8012017-06-09 02:39:56 +0300164 return FlowsActions.createOrUpdateFlow(store.dispatch, {flow: flowUpdateData}, !NEW_FLOW).then(() => {
Michael Landoefa037d2017-02-19 12:57:33 +0200165 assertFlowDataAfterCreateFetchAndUpdate(flowUpdateData);
AviZi280f8012017-06-09 02:39:56 +0300166 });
167
Michael Landoefa037d2017-02-19 12:57:33 +0200168 });
169
AviZi280f8012017-06-09 02:39:56 +0300170 it('Delete Flow', () => {
Michael Landoefa037d2017-02-19 12:57:33 +0200171
172 deepFreeze(store.getState());
173
AviZi280f8012017-06-09 02:39:56 +0300174 const flowDeleteData = FlowDeleteRequestFactory.build();
Michael Landoefa037d2017-02-19 12:57:33 +0200175
176 mockRest.addHandler('destroy', ({baseUrl}) => {
177 expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowDeleteData.serviceID}/artifacts/${flowDeleteData.uniqueId}`);
178 return {};
179 });
180
AviZi280f8012017-06-09 02:39:56 +0300181 return FlowsActions.deleteFlow(store.dispatch, {flow: flowDeleteData}).then(() => {
Michael Landoefa037d2017-02-19 12:57:33 +0200182 let {flowList} = store.getState().flows;
183 let index = flowList.findIndex(flow => flow.uniqueId === flowDeleteData.uniqueId);
184 expect(index).toBe(-1);
AviZi280f8012017-06-09 02:39:56 +0300185 });
Michael Landoefa037d2017-02-19 12:57:33 +0200186 });
Michael Landoefa037d2017-02-19 12:57:33 +0200187});