Commit c8c7d605 authored by Mark Florian's avatar Mark Florian

Merge branch '229827-default-approval-rules' into 'master'

Resolve "Display security approval rules when creating a new project - Implement Action/Mutations for Security Configuration endpoint"

See merge request gitlab-org/gitlab!38658
parents adb328bd e5560c49
import axios from '~/lib/utils/axios_utils';
import * as Sentry from '@sentry/browser';
import * as types from './mutation_types';
export const setSecurityConfigurationEndpoint = ({ commit }, endpoint) =>
commit(types.SET_SECURITY_CONFIGURATION_ENDPOINT, endpoint);
export const fetchSecurityConfiguration = ({ commit, state }) => {
if (!state.securityConfigurationPath) {
return commit(types.RECEIVE_SECURITY_CONFIGURATION_ERROR);
}
commit(types.REQUEST_SECURITY_CONFIGURATION);
return axios({
method: 'GET',
url: state.securityConfigurationPath,
})
.then(response => {
const { data } = response;
commit(types.RECEIVE_SECURITY_CONFIGURATION_SUCCESS, data);
})
.catch(error => {
Sentry.captureException(error);
commit(types.RECEIVE_SECURITY_CONFIGURATION_ERROR);
});
};
import state from './state';
import mutations from './mutations';
import * as actions from './actions';
export default {
namespaced: true,
state,
mutations,
actions,
};
export const SET_SECURITY_CONFIGURATION_ENDPOINT = 'SET_SECURITY_CONFIGURATION_ENDPOINT';
export const REQUEST_SECURITY_CONFIGURATION = 'REQUEST_SECURITY_CONFIGURATION';
export const RECEIVE_SECURITY_CONFIGURATION_SUCCESS = 'RECEIVE_SECURITY_CONFIGURATION_SUCCESS';
export const RECEIVE_SECURITY_CONFIGURATION_ERROR = 'RECEIVE_SECURITY_CONFIGURATION_ERROR';
import * as types from './mutation_types';
export default {
[types.SET_SECURITY_CONFIGURATION_ENDPOINT](state, payload) {
state.securityConfigurationPath = payload;
},
[types.REQUEST_SECURITY_CONFIGURATION](state) {
state.isLoading = true;
state.errorLoading = false;
},
[types.RECEIVE_SECURITY_CONFIGURATION_SUCCESS](state, payload) {
state.isLoading = false;
state.errorLoading = false;
state.configuration = payload;
},
[types.RECEIVE_SECURITY_CONFIGURATION_ERROR](state) {
state.isLoading = false;
state.errorLoading = true;
},
};
export default () => ({
securityConfigurationPath: '',
isLoading: false,
errorLoading: false,
configuration: {},
});
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import { TEST_HOST } from 'spec/test_constants';
import testAction from 'helpers/vuex_action_helper';
import createState from 'ee/security_configuration/modules/configuration/state';
import * as types from 'ee/security_configuration/modules/configuration/mutation_types';
import * as actions from 'ee/security_configuration/modules/configuration/actions';
describe('security configuration module actions', () => {
let state;
beforeEach(() => {
state = createState();
});
describe('setSecurityConfigurationEndpoint', () => {
const securityConfigurationPath = 123;
it('should commit the SET_SECURITY_CONFIGURATION_ENDPOINT mutation', async () => {
await testAction(
actions.setSecurityConfigurationEndpoint,
securityConfigurationPath,
state,
[
{
type: types.SET_SECURITY_CONFIGURATION_ENDPOINT,
payload: securityConfigurationPath,
},
],
[],
);
});
});
describe('fetchSecurityConfiguration', () => {
let mock;
const configuration = {};
beforeEach(() => {
state.securityConfigurationPath = `${TEST_HOST}/-/security/configuration.json`;
mock = new MockAdapter(axios);
});
afterEach(() => {
mock.restore();
});
describe('on success', () => {
beforeEach(() => {
mock.onGet(state.securityConfigurationPath).replyOnce(200, configuration);
});
it('should commit the request and success mutations', async () => {
await testAction(
actions.fetchSecurityConfiguration,
{},
state,
[
{ type: types.REQUEST_SECURITY_CONFIGURATION },
{
type: types.RECEIVE_SECURITY_CONFIGURATION_SUCCESS,
payload: configuration,
},
],
[],
);
});
});
describe('without securityConfigurationPath set', () => {
beforeEach(() => {
mock.onGet(state.securityConfigurationPath).replyOnce(200, configuration);
});
it('should commit RECEIVE_SECURITY_CONFIGURATION_ERROR mutation', async () => {
state.securityConfigurationPath = '';
await testAction(
actions.fetchSecurityConfiguration,
{},
state,
[
{
type: types.RECEIVE_SECURITY_CONFIGURATION_ERROR,
},
],
[],
);
});
});
describe('with server error', () => {
beforeEach(() => {
mock.onGet(state.securityConfigurationPath).replyOnce(404);
});
it('should commit REQUEST_SECURITY_CONFIGURATION and RECEIVE_SECURITY_CONFIGURATION_ERRORmutation', async () => {
await testAction(
actions.fetchSecurityConfiguration,
{},
state,
[
{ type: types.REQUEST_SECURITY_CONFIGURATION },
{
type: types.RECEIVE_SECURITY_CONFIGURATION_ERROR,
},
],
[],
);
});
});
});
});
import * as types from 'ee/security_configuration/modules/configuration/mutation_types';
import mutations from 'ee/security_configuration/modules/configuration/mutations';
describe('security configuration module mutations', () => {
let state;
beforeEach(() => {
state = {};
});
describe('SET_SECURITY_CONFIGURATION_ENDPOINT', () => {
const securityConfigurationPath = 123;
it(`should set the securityConfigurationPath to ${securityConfigurationPath}`, () => {
mutations[types.SET_SECURITY_CONFIGURATION_ENDPOINT](state, securityConfigurationPath);
expect(state.securityConfigurationPath).toBe(securityConfigurationPath);
});
});
describe('REQUEST_SECURITY_CONFIGURATION', () => {
it('should set the isLoading to true', () => {
mutations[types.REQUEST_SECURITY_CONFIGURATION](state);
expect(state.isLoading).toBe(true);
expect(state.errorLoading).toBe(false);
});
});
describe('RECEIVE_SECURITY_CONFIGURATION_SUCCESS', () => {
it('should set the isLoading to false and configuration to the response object', () => {
const configuration = {};
mutations[types.RECEIVE_SECURITY_CONFIGURATION_SUCCESS](state, configuration);
expect(state.isLoading).toBe(false);
expect(state.errorLoading).toBe(false);
expect(state.configuration).toBe(configuration);
});
});
describe('RECEIVE_SECURITY_CONFIGURATION_ERROR', () => {
it('should set the isLoading to false', () => {
mutations[types.RECEIVE_SECURITY_CONFIGURATION_ERROR](state);
expect(state.isLoading).toBe(false);
expect(state.errorLoading).toBe(true);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment