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

mutations_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: 633cea595d1dffddfbf9117ad0d6cd66f2d3d0cc (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
153
154
155
156
157
158
159
160
161
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_INSTANCE_TYPE,
  SET_NODE_COUNT,
  SET_GITLAB_MANAGED_CLUSTER,
  REQUEST_CREATE_ROLE,
  CREATE_ROLE_SUCCESS,
  CREATE_ROLE_ERROR,
  REQUEST_CREATE_CLUSTER,
  CREATE_CLUSTER_ERROR,
} from '~/create_cluster/eks_cluster/store/mutation_types';
import createState from '~/create_cluster/eks_cluster/store/state';
import mutations from '~/create_cluster/eks_cluster/store/mutations';

describe('Create EKS cluster store mutations', () => {
  let clusterName;
  let environmentScope;
  let kubernetesVersion;
  let state;
  let region;
  let vpc;
  let subnet;
  let role;
  let keyPair;
  let securityGroup;
  let instanceType;
  let nodeCount;
  let gitlabManagedCluster;

  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' };
    securityGroup = { name: 'default group' };
    instanceType = 'small-1';
    nodeCount = '5';
    gitlabManagedCluster = false;

    state = createState();
  });

  it.each`
    mutation                      | mutatedProperty            | payload                     | expectedValue           | expectedValueDescription
    ${SET_CLUSTER_NAME}           | ${'clusterName'}           | ${{ clusterName }}          | ${clusterName}          | ${'cluster name'}
    ${SET_ENVIRONMENT_SCOPE}      | ${'environmentScope'}      | ${{ environmentScope }}     | ${environmentScope}     | ${'environment scope'}
    ${SET_KUBERNETES_VERSION}     | ${'kubernetesVersion'}     | ${{ kubernetesVersion }}    | ${kubernetesVersion}    | ${'kubernetes version'}
    ${SET_ROLE}                   | ${'selectedRole'}          | ${{ role }}                 | ${role}                 | ${'selected role payload'}
    ${SET_REGION}                 | ${'selectedRegion'}        | ${{ region }}               | ${region}               | ${'selected region payload'}
    ${SET_KEY_PAIR}               | ${'selectedKeyPair'}       | ${{ keyPair }}              | ${keyPair}              | ${'selected key pair payload'}
    ${SET_VPC}                    | ${'selectedVpc'}           | ${{ vpc }}                  | ${vpc}                  | ${'selected vpc payload'}
    ${SET_SUBNET}                 | ${'selectedSubnet'}        | ${{ subnet }}               | ${subnet}               | ${'selected subnet payload'}
    ${SET_SECURITY_GROUP}         | ${'selectedSecurityGroup'} | ${{ securityGroup }}        | ${securityGroup}        | ${'selected security group payload'}
    ${SET_INSTANCE_TYPE}          | ${'selectedInstanceType'}  | ${{ instanceType }}         | ${instanceType}         | ${'selected instance type payload'}
    ${SET_NODE_COUNT}             | ${'nodeCount'}             | ${{ nodeCount }}            | ${nodeCount}            | ${'node count payload'}
    ${SET_GITLAB_MANAGED_CLUSTER} | ${'gitlabManagedCluster'}  | ${{ gitlabManagedCluster }} | ${gitlabManagedCluster} | ${'gitlab managed cluster'}
  `(`$mutation sets $mutatedProperty to $expectedValueDescription`, (data) => {
    const { mutation, mutatedProperty, payload, expectedValue } = data;

    mutations[mutation](state, payload);
    expect(state[mutatedProperty]).toBe(expectedValue);
  });

  describe(`mutation ${REQUEST_CREATE_ROLE}`, () => {
    beforeEach(() => {
      mutations[REQUEST_CREATE_ROLE](state);
    });

    it('sets isCreatingRole to true', () => {
      expect(state.isCreatingRole).toBe(true);
    });

    it('sets createRoleError to null', () => {
      expect(state.createRoleError).toBe(null);
    });

    it('sets hasCredentials to false', () => {
      expect(state.hasCredentials).toBe(false);
    });
  });

  describe(`mutation ${CREATE_ROLE_SUCCESS}`, () => {
    beforeEach(() => {
      mutations[CREATE_ROLE_SUCCESS](state);
    });

    it('sets isCreatingRole to false', () => {
      expect(state.isCreatingRole).toBe(false);
    });

    it('sets createRoleError to null', () => {
      expect(state.createRoleError).toBe(null);
    });

    it('sets hasCredentials to false', () => {
      expect(state.hasCredentials).toBe(true);
    });
  });

  describe(`mutation ${CREATE_ROLE_ERROR}`, () => {
    const error = new Error();

    beforeEach(() => {
      mutations[CREATE_ROLE_ERROR](state, { error });
    });

    it('sets isCreatingRole to false', () => {
      expect(state.isCreatingRole).toBe(false);
    });

    it('sets createRoleError to the error object', () => {
      expect(state.createRoleError).toBe(error);
    });

    it('sets hasCredentials to false', () => {
      expect(state.hasCredentials).toBe(false);
    });
  });

  describe(`mutation ${REQUEST_CREATE_CLUSTER}`, () => {
    beforeEach(() => {
      mutations[REQUEST_CREATE_CLUSTER](state);
    });

    it('sets isCreatingCluster to true', () => {
      expect(state.isCreatingCluster).toBe(true);
    });

    it('sets createClusterError to null', () => {
      expect(state.createClusterError).toBe(null);
    });
  });

  describe(`mutation ${CREATE_CLUSTER_ERROR}`, () => {
    const error = new Error();

    beforeEach(() => {
      mutations[CREATE_CLUSTER_ERROR](state, { error });
    });

    it('sets isCreatingRole to false', () => {
      expect(state.isCreatingCluster).toBe(false);
    });

    it('sets createRoleError to the error object', () => {
      expect(state.createClusterError).toBe(error);
    });
  });
});