Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 7 | * |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 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. |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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'; |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 21 | import { enums } from 'sdc-app/flows/FlowsConstants.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 22 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | import { |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 24 | FlowCreateFactory, |
| 25 | FlowPostRequestFactory, |
| 26 | FlowPostResponseFactory, |
| 27 | FlowFetchRequestFactory, |
| 28 | FlowFetchResponseFactory, |
| 29 | FlowDeleteRequestFactory, |
| 30 | FlowUpdateRequestFactory |
| 31 | } from 'test-utils/factories/flows/FlowsFactories.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 32 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 33 | import { buildFromExistingObject } from 'test-utils/Util.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 34 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 35 | const NEW_FLOW = true; |
| 36 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 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); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 44 | }; |
| 45 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 46 | describe('Workflows and Management Flows Module Tests:', function() { |
| 47 | it('empty artifact should open flow creation modal', () => { |
| 48 | const artifacts = {}; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 49 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 50 | deepFreeze(store.getState()); |
| 51 | deepFreeze(artifacts); |
| 52 | FlowsActions.fetchFlowArtifacts(store.dispatch, { |
| 53 | artifacts, |
| 54 | diagramType: enums.WORKFLOW, |
| 55 | participants: [], |
| 56 | serviceID: '1234' |
| 57 | }); |
| 58 | let state = store.getState(); |
| 59 | expect(state.modal).toBeDefined(); |
| 60 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 61 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 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(); |
| 67 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 68 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 69 | it('Get Flows List from loaded artifact', () => { |
| 70 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 71 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 72 | const artifacts = { |
| 73 | test1: FlowPostResponseFactory.build({ artifactName: 'test1' }), |
| 74 | kukuriku: FlowPostResponseFactory.build({ |
| 75 | artifactType: 'PUPPET', |
| 76 | artifactName: 'kukuriku' |
| 77 | }), |
| 78 | test3: FlowPostResponseFactory.build({ artifactName: 'test3' }) |
| 79 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 80 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 81 | const artifactsArray = Object.keys(artifacts).map(artifact => artifact); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 82 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 83 | deepFreeze(artifacts); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 84 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 85 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 86 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 87 | let actionData = { |
| 88 | artifacts, |
| 89 | diagramType: enums.WORKFLOW, |
| 90 | participants: [], |
| 91 | serviceID: '1234' |
| 92 | }; |
| 93 | FlowsActions.fetchFlowArtifacts(store.dispatch, actionData); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 94 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 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); |
| 100 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 101 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 102 | it('Add New Flow', () => { |
| 103 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 104 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 105 | const flowCreateData = FlowCreateFactory.build(); |
| 106 | let expectedDataToBeSentInTheRequest = buildFromExistingObject( |
| 107 | FlowPostRequestFactory, |
| 108 | flowCreateData |
| 109 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 110 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 111 | mockRest.addHandler('post', ({ data, baseUrl, options }) => { |
| 112 | expect(baseUrl).toBe( |
| 113 | `/sdc1/feProxy/rest/v1/catalog/services/${ |
| 114 | flowCreateData.serviceID |
| 115 | }/artifacts/` |
| 116 | ); |
| 117 | expect(data.artifactLabel).toBe( |
| 118 | expectedDataToBeSentInTheRequest.artifactLabel |
| 119 | ); |
| 120 | expect(data.artifactName).toBe( |
| 121 | expectedDataToBeSentInTheRequest.artifactName |
| 122 | ); |
| 123 | expect(data.artifactType).toBe( |
| 124 | expectedDataToBeSentInTheRequest.artifactType |
| 125 | ); |
| 126 | expect(data.description).toBe( |
| 127 | expectedDataToBeSentInTheRequest.description |
| 128 | ); |
| 129 | expect(data.payloadData).toBe( |
| 130 | expectedDataToBeSentInTheRequest.payloadData |
| 131 | ); |
| 132 | expect(options.md5).toBe(true); |
| 133 | return buildFromExistingObject( |
| 134 | FlowPostResponseFactory, |
| 135 | expectedDataToBeSentInTheRequest |
| 136 | ); |
| 137 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 138 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 139 | return FlowsActions.createOrUpdateFlow( |
| 140 | store.dispatch, |
| 141 | { flow: flowCreateData }, |
| 142 | NEW_FLOW |
| 143 | ).then(() => { |
| 144 | assertFlowDataAfterCreateFetchAndUpdate(flowCreateData); |
| 145 | }); |
| 146 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 147 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 148 | it('Fetch Flow', () => { |
| 149 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 150 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 151 | const flowFetchData = FlowFetchRequestFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 152 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 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}` |
| 159 | ); |
| 160 | return buildFromExistingObject( |
| 161 | FlowFetchResponseFactory, |
| 162 | flowFetchData |
| 163 | ); |
| 164 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 165 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 166 | return FlowsActions.fetchArtifact(store.dispatch, { |
| 167 | flow: flowFetchData |
| 168 | }).then(() => { |
| 169 | assertFlowDataAfterCreateFetchAndUpdate(flowFetchData); |
| 170 | }); |
| 171 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 172 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 173 | it('Update Existing Flow', () => { |
| 174 | deepFreeze(store.getState()); |
| 175 | const flowUpdateData = FlowUpdateRequestFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 176 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 177 | mockRest.addHandler('post', ({ baseUrl }) => { |
| 178 | expect(baseUrl).toBe( |
| 179 | `/sdc1/feProxy/rest/v1/catalog/services/${ |
| 180 | flowUpdateData.serviceID |
| 181 | }/artifacts/${flowUpdateData.uniqueId}` |
| 182 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 183 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 184 | return buildFromExistingObject( |
| 185 | FlowPostResponseFactory, |
| 186 | flowUpdateData |
| 187 | ); |
| 188 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 189 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 190 | return FlowsActions.createOrUpdateFlow( |
| 191 | store.dispatch, |
| 192 | { flow: flowUpdateData }, |
| 193 | !NEW_FLOW |
| 194 | ).then(() => { |
| 195 | assertFlowDataAfterCreateFetchAndUpdate(flowUpdateData); |
| 196 | }); |
| 197 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 198 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 199 | it('Delete Flow', () => { |
| 200 | deepFreeze(store.getState()); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 201 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 202 | const flowDeleteData = FlowDeleteRequestFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 203 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 204 | mockRest.addHandler('destroy', ({ baseUrl }) => { |
| 205 | expect(baseUrl).toBe( |
| 206 | `/sdc1/feProxy/rest/v1/catalog/services/${ |
| 207 | flowDeleteData.serviceID |
| 208 | }/artifacts/${flowDeleteData.uniqueId}` |
| 209 | ); |
| 210 | return {}; |
| 211 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 212 | |
Einav Weiss Keidar | 1801b24 | 2018-08-13 16:19:46 +0300 | [diff] [blame] | 213 | return FlowsActions.deleteFlow(store.dispatch, { |
| 214 | flow: flowDeleteData |
| 215 | }).then(() => { |
| 216 | let { flowList } = store.getState().flows; |
| 217 | let index = flowList.findIndex( |
| 218 | flow => flow.uniqueId === flowDeleteData.uniqueId |
| 219 | ); |
| 220 | expect(index).toBe(-1); |
| 221 | }); |
| 222 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 223 | }); |