244a66dea3198d1e90d4444d63058babbff96ad4
[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
51         /**
52          * expecting the error message to return as undefined
53          * from validateNameField method
54          */
55         expect(gen.next().value).toEqual(undefined);
56         expect(gen.next().value).toEqual(
57             call(newWorkflowApi.createNewWorkflow, action.payload)
58         );
59         const history = undefined,
60             workflowId = undefined;
61         expect(gen.next(action.payload).value).toEqual(
62             put(submitVersionAction({ history, workflowId, ...NEW_VERSION }))
63         );
64         expect(gen.next().value).toEqual(
65             put(setWorkflowAction({ ...action.payload, id: undefined }))
66         );
67         //handling errors
68         expect(gen.throw({ error: 'error' }).value).toEqual(
69             put(clearWorkflowAction)
70         );
71         expect(gen.next().value).toEqual(
72             put(genericNetworkErrorAction({ error: 'error' }))
73         );
74         expect(gen.next().done).toBe(true);
75     });
76 });