diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-18 21:09:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-18 21:09:07 +0300 |
commit | 6b8d671de726534a03c18e025a586e1bc9c04a4f (patch) | |
tree | f6a9168160b0d435641a1767b2e68487ec75ae46 /spec | |
parent | 163a7046ac76eb4109184e82ce0af911633e6626 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/ci_variable_list/services/mock_data.js | 90 | ||||
-rw-r--r-- | spec/frontend/ci_variable_list/store/actions_spec.js | 279 | ||||
-rw-r--r-- | spec/frontend/ci_variable_list/store/mutations_spec.js | 64 | ||||
-rw-r--r-- | spec/frontend/ci_variable_list/store/utils_spec.js | 47 | ||||
-rw-r--r-- | spec/lib/quality/kubernetes_client_spec.rb | 6 |
5 files changed, 483 insertions, 3 deletions
diff --git a/spec/frontend/ci_variable_list/services/mock_data.js b/spec/frontend/ci_variable_list/services/mock_data.js new file mode 100644 index 00000000000..89473b57af9 --- /dev/null +++ b/spec/frontend/ci_variable_list/services/mock_data.js @@ -0,0 +1,90 @@ +export default { + mockVariables: [ + { + environment_scope: 'All environments', + id: 113, + key: 'test_var', + masked: false, + protected: false, + value: 'test_val', + variable_type: 'Variable', + }, + { + environment_scope: 'All environments', + id: 114, + key: 'test_var_2', + masked: false, + protected: false, + value: 'test_val_2', + variable_type: 'Variable', + }, + { + environment_scope: 'All environments', + id: 115, + key: 'test_var_3', + masked: false, + protected: false, + value: 'test_val_3', + variable_type: 'Variable', + }, + ], + + mockVariablesApi: [ + { + environment_scope: '*', + id: 113, + key: 'test_var', + masked: false, + protected: false, + value: 'test_val', + variable_type: 'env_var', + }, + { + environment_scope: '*', + id: 114, + key: 'test_var_2', + masked: false, + protected: false, + value: 'test_val_2', + variable_type: 'file', + }, + ], + + mockVariablesDisplay: [ + { + environment_scope: 'All environments', + id: 113, + key: 'test_var', + masked: false, + protected: false, + value: 'test_val', + variable_type: 'Variable', + }, + { + environment_scope: 'All environments', + id: 114, + key: 'test_var_2', + masked: false, + protected: false, + value: 'test_val_2', + variable_type: 'File', + }, + ], + + mockEnvironments: [ + { + id: 28, + name: 'staging', + slug: 'staging', + external_url: 'https://staging.example.com', + state: 'available', + }, + { + id: 29, + name: 'production', + slug: 'production', + external_url: 'https://production.example.com', + state: 'available', + }, + ], +}; diff --git a/spec/frontend/ci_variable_list/store/actions_spec.js b/spec/frontend/ci_variable_list/store/actions_spec.js new file mode 100644 index 00000000000..84455612f0c --- /dev/null +++ b/spec/frontend/ci_variable_list/store/actions_spec.js @@ -0,0 +1,279 @@ +import Api from '~/api'; +import MockAdapter from 'axios-mock-adapter'; +import testAction from 'helpers/vuex_action_helper'; +import axios from '~/lib/utils/axios_utils'; +import createFlash from '~/flash'; +import getInitialState from '~/ci_variable_list/store/state'; +import * as actions from '~/ci_variable_list/store/actions'; +import * as types from '~/ci_variable_list/store/mutation_types'; +import mockData from '../services/mock_data'; +import { prepareDataForDisplay, prepareEnvironments } from '~/ci_variable_list/store/utils'; + +jest.mock('~/api.js'); +jest.mock('~/flash.js'); + +describe('CI variable list store actions', () => { + let mock; + let state; + const mockVariable = { + environment_scope: '*', + id: 63, + key: 'test_var', + masked: false, + protected: false, + value: 'test_val', + variable_type: 'env_var', + _destory: true, + }; + const payloadError = new Error('Request failed with status code 500'); + + beforeEach(() => { + mock = new MockAdapter(axios); + state = getInitialState(); + state.endpoint = '/variables'; + }); + + afterEach(() => { + mock.restore(); + }); + + describe('toggleValues', () => { + const valuesHidden = false; + it('commits TOGGLE_VALUES mutation', () => { + testAction(actions.toggleValues, valuesHidden, {}, [ + { + type: types.TOGGLE_VALUES, + payload: valuesHidden, + }, + ]); + }); + }); + + describe('clearModal', () => { + it('commits CLEAR_MODAL mutation', () => { + testAction(actions.clearModal, {}, {}, [ + { + type: types.CLEAR_MODAL, + }, + ]); + }); + }); + + describe('resetEditing', () => { + it('commits RESET_EDITING mutation', () => { + testAction( + actions.resetEditing, + {}, + {}, + [ + { + type: types.RESET_EDITING, + }, + ], + [{ type: 'fetchVariables' }], + ); + }); + }); + + describe('deleteVariable', () => { + it('dispatch correct actions on successful deleted variable', done => { + mock.onPatch(state.endpoint).reply(200); + + testAction( + actions.deleteVariable, + mockVariable, + state, + [], + [ + { type: 'requestDeleteVariable' }, + { type: 'receiveDeleteVariableSuccess' }, + { type: 'fetchVariables' }, + ], + () => { + done(); + }, + ); + }); + + it('should show flash error and set error in state on delete failure', done => { + mock.onPatch(state.endpoint).reply(500, ''); + + testAction( + actions.deleteVariable, + mockVariable, + state, + [], + [ + { type: 'requestDeleteVariable' }, + { + type: 'receiveDeleteVariableError', + payload: payloadError, + }, + ], + () => { + expect(createFlash).toHaveBeenCalled(); + done(); + }, + ); + }); + }); + + describe('updateVariable', () => { + it('dispatch correct actions on successful updated variable', done => { + mock.onPatch(state.endpoint).reply(200); + + testAction( + actions.updateVariable, + mockVariable, + state, + [], + [ + { type: 'requestUpdateVariable' }, + { type: 'receiveUpdateVariableSuccess' }, + { type: 'fetchVariables' }, + ], + () => { + done(); + }, + ); + }); + + it('should show flash error and set error in state on update failure', done => { + mock.onPatch(state.endpoint).reply(500, ''); + + testAction( + actions.updateVariable, + mockVariable, + state, + [], + [ + { type: 'requestUpdateVariable' }, + { + type: 'receiveUpdateVariableError', + payload: payloadError, + }, + ], + () => { + expect(createFlash).toHaveBeenCalled(); + done(); + }, + ); + }); + }); + + describe('addVariable', () => { + it('dispatch correct actions on successful added variable', done => { + mock.onPatch(state.endpoint).reply(200); + + testAction( + actions.addVariable, + {}, + state, + [], + [ + { type: 'requestAddVariable' }, + { type: 'receiveAddVariableSuccess' }, + { type: 'fetchVariables' }, + ], + () => { + done(); + }, + ); + }); + + it('should show flash error and set error in state on add failure', done => { + mock.onPatch(state.endpoint).reply(500, ''); + + testAction( + actions.addVariable, + {}, + state, + [], + [ + { type: 'requestAddVariable' }, + { + type: 'receiveAddVariableError', + payload: payloadError, + }, + ], + () => { + expect(createFlash).toHaveBeenCalled(); + done(); + }, + ); + }); + }); + + describe('fetchVariables', () => { + it('dispatch correct actions on fetchVariables', done => { + mock.onGet(state.endpoint).reply(200, { variables: mockData.mockVariables }); + + testAction( + actions.fetchVariables, + {}, + state, + [], + [ + { type: 'requestVariables' }, + { + type: 'receiveVariablesSuccess', + payload: prepareDataForDisplay(mockData.mockVariables), + }, + ], + () => { + done(); + }, + ); + }); + + it('should show flash error and set error in state on fetch variables failure', done => { + mock.onGet(state.endpoint).reply(500); + + testAction(actions.fetchVariables, {}, state, [], [{ type: 'requestVariables' }], () => { + expect(createFlash).toHaveBeenCalledWith('There was an error fetching the variables.'); + done(); + }); + }); + }); + + describe('fetchEnvironments', () => { + it('dispatch correct actions on fetchEnvironments', done => { + Api.environments = jest.fn().mockResolvedValue({ data: mockData.mockEnvironments }); + + testAction( + actions.fetchEnvironments, + {}, + state, + [], + [ + { type: 'requestEnvironments' }, + { + type: 'receiveEnvironmentsSuccess', + payload: prepareEnvironments(mockData.mockEnvironments), + }, + ], + () => { + done(); + }, + ); + }); + + it('should show flash error and set error in state on fetch environments failure', done => { + Api.environments = jest.fn().mockRejectedValue(); + + testAction( + actions.fetchEnvironments, + {}, + state, + [], + [{ type: 'requestEnvironments' }], + () => { + expect(createFlash).toHaveBeenCalledWith( + 'There was an error fetching the environments information.', + ); + done(); + }, + ); + }); + }); +}); diff --git a/spec/frontend/ci_variable_list/store/mutations_spec.js b/spec/frontend/ci_variable_list/store/mutations_spec.js new file mode 100644 index 00000000000..1bb34e88cf5 --- /dev/null +++ b/spec/frontend/ci_variable_list/store/mutations_spec.js @@ -0,0 +1,64 @@ +import state from '~/ci_variable_list/store/state'; +import mutations from '~/ci_variable_list/store/mutations'; +import * as types from '~/ci_variable_list/store/mutation_types'; + +describe('CI variable list mutations', () => { + let stateCopy; + + beforeEach(() => { + stateCopy = state(); + }); + + describe('TOGGLE_VALUES', () => { + it('should toggle state', () => { + const valuesHidden = false; + + mutations[types.TOGGLE_VALUES](stateCopy, valuesHidden); + + expect(stateCopy.valuesHidden).toEqual(valuesHidden); + }); + }); + + describe('VARIABLE_BEING_EDITED', () => { + it('should set variable that is being edited', () => { + const variableBeingEdited = { + environment_scope: '*', + id: 63, + key: 'test_var', + masked: false, + protected: false, + value: 'test_val', + variable_type: 'env_var', + }; + + mutations[types.VARIABLE_BEING_EDITED](stateCopy, variableBeingEdited); + + expect(stateCopy.variableBeingEdited).toEqual(variableBeingEdited); + }); + }); + + describe('RESET_EDITING', () => { + it('should reset variableBeingEdited to null', () => { + mutations[types.RESET_EDITING](stateCopy); + + expect(stateCopy.variableBeingEdited).toEqual(null); + }); + }); + + describe('CLEAR_MODAL', () => { + it('should clear modal state ', () => { + const modalState = { + variable_type: 'Variable', + key: '', + secret_value: '', + protected: false, + masked: false, + environment_scope: 'All environments', + }; + + mutations[types.CLEAR_MODAL](stateCopy); + + expect(stateCopy.variable).toEqual(modalState); + }); + }); +}); diff --git a/spec/frontend/ci_variable_list/store/utils_spec.js b/spec/frontend/ci_variable_list/store/utils_spec.js new file mode 100644 index 00000000000..9d5dd6b4f29 --- /dev/null +++ b/spec/frontend/ci_variable_list/store/utils_spec.js @@ -0,0 +1,47 @@ +import { + prepareDataForDisplay, + prepareEnvironments, + prepareDataForApi, +} from '~/ci_variable_list/store/utils'; +import mockData from '../services/mock_data'; + +describe('CI variables store utils', () => { + it('prepares ci variables for display', () => { + expect(prepareDataForDisplay(mockData.mockVariablesApi)).toStrictEqual( + mockData.mockVariablesDisplay, + ); + }); + + it('prepares single ci variable for api', () => { + expect(prepareDataForApi(mockData.mockVariablesDisplay[0])).toStrictEqual({ + environment_scope: '*', + id: 113, + key: 'test_var', + masked: false, + protected: false, + value: 'test_val', + variable_type: 'env_var', + }); + + expect(prepareDataForApi(mockData.mockVariablesDisplay[1])).toStrictEqual({ + environment_scope: '*', + id: 114, + key: 'test_var_2', + masked: false, + protected: false, + value: 'test_val_2', + variable_type: 'file', + }); + }); + + it('prepares single ci variable for delete', () => { + expect(prepareDataForApi(mockData.mockVariablesDisplay[0], true)).toHaveProperty( + '_destroy', + true, + ); + }); + + it('prepares environments for display', () => { + expect(prepareEnvironments(mockData.mockEnvironments)).toStrictEqual(['staging', 'production']); + }); +}); diff --git a/spec/lib/quality/kubernetes_client_spec.rb b/spec/lib/quality/kubernetes_client_spec.rb index 3a362dfccbf..1cfee5200f3 100644 --- a/spec/lib/quality/kubernetes_client_spec.rb +++ b/spec/lib/quality/kubernetes_client_spec.rb @@ -38,7 +38,7 @@ RSpec.describe Quality::KubernetesClient do .and_return(Gitlab::Popen::Result.new([], '', '', double(success?: true))) expect(Gitlab::Popen).to receive(:popen_with_detail) - .with([%(kubectl delete --namespace "#{namespace}" #{pod_for_release})]) + .with([%(kubectl delete --namespace "#{namespace}" --ignore-not-found #{pod_for_release})]) .and_return(Gitlab::Popen::Result.new([], '', '', double(success?: true))) # We're not verifying the output here, just silencing it @@ -64,7 +64,7 @@ RSpec.describe Quality::KubernetesClient do .and_return(Gitlab::Popen::Result.new([], '', '', double(success?: true))) expect(Gitlab::Popen).to receive(:popen_with_detail) - .with([%(kubectl delete --namespace "#{namespace}" #{pod_for_release})]) + .with([%(kubectl delete --namespace "#{namespace}" --ignore-not-found #{pod_for_release})]) .and_return(Gitlab::Popen::Result.new([], '', '', double(success?: true))) # We're not verifying the output here, just silencing it @@ -89,7 +89,7 @@ RSpec.describe Quality::KubernetesClient do .and_return(Gitlab::Popen::Result.new([], '', '', double(success?: true))) expect(Gitlab::Popen).to receive(:popen_with_detail) - .with([%(kubectl delete --namespace "#{namespace}" #{pod_for_release})]) + .with([%(kubectl delete --namespace "#{namespace}" --ignore-not-found #{pod_for_release})]) .and_return(Gitlab::Popen::Result.new([], '', '', double(success?: true))) # We're not verifying the output here, just silencing it |