AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
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 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 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, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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. |
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'; |
| 21 | import {enums} from 'sdc-app/flows/FlowsConstants.js'; |
| 22 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | import { |
| 24 | FlowCreateFactory, |
| 25 | FlowPostRequestFactory, |
| 26 | FlowPostResponseFactory, |
| 27 | FlowFetchRequestFactory, |
| 28 | FlowFetchResponseFactory, |
| 29 | FlowDeleteRequestFactory, |
| 30 | FlowUpdateRequestFactory } from 'test-utils/factories/flows/FlowsFactories.js'; |
| 31 | |
| 32 | import {buildFromExistingObject} from 'test-utils/Util.js'; |
| 33 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 34 | const NEW_FLOW = true; |
| 35 | |
| 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); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 42 | expect(index).not.toBe(-1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | describe('Workflows and Management Flows Module Tests:', function () { |
| 46 | |
| 47 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 48 | it('empty artifact should open flow creation modal', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 49 | |
| 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 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 60 | let state = store.getState(); |
| 61 | expect(state.flows.isDisplayModal).toBe(true); |
| 62 | expect(state.flows.isModalInEditMode).toBe(false); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 63 | }); |
| 64 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 65 | it('Close flow details editor modal', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 66 | deepFreeze(store.getState()); |
| 67 | FlowsActions.closeFlowDetailsEditor(store.dispatch); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 68 | let state = store.getState(); |
| 69 | expect(state.flows.isDisplayModal).toBe(false); |
| 70 | expect(state.flows.isModalInEditMode).toBe(false); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 71 | }); |
| 72 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 73 | it('Get Flows List from loaded artifact', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 74 | |
| 75 | deepFreeze(store.getState()); |
| 76 | |
| 77 | const artifacts = { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 78 | 'test1': FlowPostResponseFactory.build({artifactName: 'test1'}), |
| 79 | 'kukuriku': FlowPostResponseFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 80 | 'artifactType': 'PUPPET', |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 81 | 'artifactName': 'kukuriku', |
| 82 | }), |
| 83 | 'test3': FlowPostResponseFactory.build({artifactName: 'test3'}) |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 84 | }; |
| 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 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 107 | |
| 108 | }); |
| 109 | |
| 110 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 111 | it('Add New Flow', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 112 | |
| 113 | deepFreeze(store.getState()); |
| 114 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 115 | const flowCreateData = FlowCreateFactory.build(); |
| 116 | let expectedDataToBeSentInTheRequest = buildFromExistingObject(FlowPostRequestFactory, flowCreateData); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 117 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 118 | mockRest.addHandler('post', ({data, baseUrl, options}) => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 126 | return buildFromExistingObject(FlowPostResponseFactory, expectedDataToBeSentInTheRequest); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 127 | }); |
| 128 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 129 | return FlowsActions.createOrUpdateFlow(store.dispatch, {flow: flowCreateData}, NEW_FLOW).then(() => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 130 | assertFlowDataAfterCreateFetchAndUpdate(flowCreateData); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 131 | }); |
| 132 | |
| 133 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 134 | }); |
| 135 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 136 | it('Fetch Flow', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 137 | |
| 138 | deepFreeze(store.getState()); |
| 139 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 140 | const flowFetchData = FlowFetchRequestFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 141 | |
| 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}`); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 145 | return buildFromExistingObject(FlowFetchResponseFactory, flowFetchData); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 146 | }); |
| 147 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 148 | return FlowsActions.fetchArtifact(store.dispatch, {flow: flowFetchData}).then(() => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 149 | assertFlowDataAfterCreateFetchAndUpdate(flowFetchData); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 150 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 151 | }); |
| 152 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 153 | it('Update Existing Flow', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 154 | |
| 155 | deepFreeze(store.getState()); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 156 | const flowUpdateData = FlowUpdateRequestFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 157 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 158 | mockRest.addHandler('post', ({baseUrl}) => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 159 | expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowUpdateData.serviceID}/artifacts/${flowUpdateData.uniqueId}`); |
| 160 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 161 | return buildFromExistingObject(FlowPostResponseFactory, flowUpdateData); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 162 | }); |
| 163 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 164 | return FlowsActions.createOrUpdateFlow(store.dispatch, {flow: flowUpdateData}, !NEW_FLOW).then(() => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 165 | assertFlowDataAfterCreateFetchAndUpdate(flowUpdateData); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 166 | }); |
| 167 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 168 | }); |
| 169 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 170 | it('Delete Flow', () => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 171 | |
| 172 | deepFreeze(store.getState()); |
| 173 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 174 | const flowDeleteData = FlowDeleteRequestFactory.build(); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 175 | |
| 176 | mockRest.addHandler('destroy', ({baseUrl}) => { |
| 177 | expect(baseUrl).toBe(`/sdc1/feProxy/rest/v1/catalog/services/${flowDeleteData.serviceID}/artifacts/${flowDeleteData.uniqueId}`); |
| 178 | return {}; |
| 179 | }); |
| 180 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 181 | return FlowsActions.deleteFlow(store.dispatch, {flow: flowDeleteData}).then(() => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 182 | let {flowList} = store.getState().flows; |
| 183 | let index = flowList.findIndex(flow => flow.uniqueId === flowDeleteData.uniqueId); |
| 184 | expect(index).toBe(-1); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 185 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 186 | }); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 187 | }); |