c9782c1bed8e76468ef7e7f3e92bb0e1cc4ebf15
[sdc/sdc-workflow-designer.git] /
1 /*
2 * Copyright © 2018 European Support Limited
3 *
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
7
8  *      http://www.apache.org/licenses/LICENSE-2.0
9
10  * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
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.
15 */
16
17 import { call, takeEvery } from 'redux-saga/effects';
18 import {
19     watchWorkflow,
20     watchSubmitWorkflow
21 } from 'features/workflow/create/createWorkflowSaga';
22 import { put } from 'redux-saga/effects';
23 import newWorkflowApi from 'features/workflow/create/createWorkflowApi';
24 import { SUBMIT_WORKFLOW } from 'features/workflow/create/createWorkflowConstants';
25 import { submitVersionAction } from 'features/version/create/createVersionConstants';
26 import { NEW_VERSION } from 'features/workflow/create/createWorkflowConstants';
27 import {
28     setWorkflowAction,
29     clearWorkflowAction
30 } from 'features/workflow/workflowConstants';
31 import { genericNetworkErrorAction } from 'wfapp/appConstants';
32
33 describe('New workflow saga test', () => {
34     it('Create new workflow', () => {
35         const gen = watchWorkflow();
36         expect(gen.next().value).toEqual(
37             takeEvery(SUBMIT_WORKFLOW, watchSubmitWorkflow)
38         );
39         expect(gen.next().done).toEqual(true);
40     });
41
42     it('Submit new workflow', () => {
43         const action = {
44             payload: {
45                 name: 'workflow1',
46                 description: 'description'
47             }
48         };
49         const gen = watchSubmitWorkflow(action);
50         expect(gen.next().value).toEqual(
51             call(newWorkflowApi.createNewWorkflow, action.payload)
52         );
53         const history = undefined,
54             workflowId = undefined;
55         expect(gen.next(action.payload).value).toEqual(
56             put(submitVersionAction({ history, workflowId, ...NEW_VERSION }))
57         );
58         expect(gen.next().value).toEqual(
59             put(setWorkflowAction({ ...action.payload, id: undefined }))
60         );
61         //handling errors
62         expect(gen.throw({ error: 'error' }).value).toEqual(
63             put(clearWorkflowAction)
64         );
65         expect(gen.next().value).toEqual(
66             put(genericNetworkErrorAction({ error: 'error' }))
67         );
68         expect(gen.next().done).toBe(true);
69     });
70 });