Welcome to mirror list, hosted at ThFree Co, Russian Federation.

actions_spec.js « store « eks_cluster « create_cluster « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 99c8cdba2966d453bcc680cc19d7ae9522fd8f8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import testAction from 'helpers/vuex_action_helper';

import createState from '~/create_cluster/eks_cluster/store/state';
import * as actions from '~/create_cluster/eks_cluster/store/actions';
import {
  SET_CLUSTER_NAME,
  SET_ENVIRONMENT_SCOPE,
  SET_KUBERNETES_VERSION,
  SET_REGION,
  SET_VPC,
  SET_KEY_PAIR,
  SET_SUBNET,
  SET_ROLE,
  SET_SECURITY_GROUP,
  SET_GITLAB_MANAGED_CLUSTER,
  REQUEST_CREATE_ROLE,
  CREATE_ROLE_SUCCESS,
  CREATE_ROLE_ERROR,
} from '~/create_cluster/eks_cluster/store/mutation_types';
import axios from '~/lib/utils/axios_utils';
import MockAdapter from 'axios-mock-adapter';

describe('EKS Cluster Store Actions', () => {
  let clusterName;
  let environmentScope;
  let kubernetesVersion;
  let region;
  let vpc;
  let subnet;
  let role;
  let keyPair;
  let securityGroup;
  let gitlabManagedCluster;
  let mock;
  let state;

  beforeEach(() => {
    clusterName = 'my cluster';
    environmentScope = 'production';
    kubernetesVersion = '11.1';
    region = { name: 'regions-1' };
    vpc = { name: 'vpc-1' };
    subnet = { name: 'subnet-1' };
    role = { name: 'role-1' };
    keyPair = { name: 'key-pair-1' };
    securityGroup = { name: 'default group' };
    gitlabManagedCluster = true;

    state = {
      ...createState(),
      createRolePath: '/clusters/roles/',
    };
  });

  beforeEach(() => {
    mock = new MockAdapter(axios);
  });

  afterEach(() => {
    mock.restore();
  });

  it.each`
    action                       | mutation                      | payload                  | payloadDescription
    ${'setClusterName'}          | ${SET_CLUSTER_NAME}           | ${{ clusterName }}       | ${'cluster name'}
    ${'setEnvironmentScope'}     | ${SET_ENVIRONMENT_SCOPE}      | ${{ environmentScope }}  | ${'environment scope'}
    ${'setKubernetesVersion'}    | ${SET_KUBERNETES_VERSION}     | ${{ kubernetesVersion }} | ${'kubernetes version'}
    ${'setRole'}                 | ${SET_ROLE}                   | ${{ role }}              | ${'role'}
    ${'setRegion'}               | ${SET_REGION}                 | ${{ region }}            | ${'region'}
    ${'setKeyPair'}              | ${SET_KEY_PAIR}               | ${{ keyPair }}           | ${'key pair'}
    ${'setVpc'}                  | ${SET_VPC}                    | ${{ vpc }}               | ${'vpc'}
    ${'setSubnet'}               | ${SET_SUBNET}                 | ${{ subnet }}            | ${'subnet'}
    ${'setSecurityGroup'}        | ${SET_SECURITY_GROUP}         | ${{ securityGroup }}     | ${'securityGroup'}
    ${'setGitlabManagedCluster'} | ${SET_GITLAB_MANAGED_CLUSTER} | ${gitlabManagedCluster}  | ${'gitlab managed cluster'}
  `(`$action commits $mutation with $payloadDescription payload`, data => {
    const { action, mutation, payload } = data;

    testAction(actions[action], payload, state, [{ type: mutation, payload }]);
  });

  describe('createRole', () => {
    const payload = {
      roleArn: 'role_arn',
      externalId: 'externalId',
    };

    describe('when request succeeds', () => {
      beforeEach(() => {
        mock
          .onPost(state.createRolePath, {
            role_arn: payload.roleArn,
            role_external_id: payload.externalId,
          })
          .reply(201);
      });

      it('dispatches createRoleSuccess action', () =>
        testAction(
          actions.createRole,
          payload,
          state,
          [],
          [{ type: 'requestCreateRole' }, { type: 'createRoleSuccess' }],
        ));
    });

    describe('when request fails', () => {
      let error;

      beforeEach(() => {
        error = new Error('Request failed with status code 400');
        mock
          .onPost(state.createRolePath, {
            role_arn: payload.roleArn,
            role_external_id: payload.externalId,
          })
          .reply(400, error);
      });

      it('dispatches createRoleError action', () =>
        testAction(
          actions.createRole,
          payload,
          state,
          [],
          [{ type: 'requestCreateRole' }, { type: 'createRoleError', payload: { error } }],
        ));
    });
  });

  describe('requestCreateRole', () => {
    it('commits requestCreaterole mutation', () => {
      testAction(actions.requestCreateRole, null, state, [{ type: REQUEST_CREATE_ROLE }]);
    });
  });

  describe('createRoleSuccess', () => {
    it('commits createRoleSuccess mutation', () => {
      testAction(actions.createRoleSuccess, null, state, [{ type: CREATE_ROLE_SUCCESS }]);
    });
  });

  describe('createRoleError', () => {
    it('commits createRoleError mutation', () => {
      const payload = {
        error: new Error(),
      };

      testAction(actions.createRoleError, payload, state, [{ type: CREATE_ROLE_ERROR, payload }]);
    });
  });
});