Commit 2a928a77 authored by Mike Greiling's avatar Mike Greiling

Merge branch '13076-editing-custom-stage-with-default-name-should-fail' into 'master'

Check for 422 error when editing stage

See merge request gitlab-org/gitlab!21891
parents 8c3ea04a c5aeddee
......@@ -259,9 +259,23 @@ export const receiveUpdateStageSuccess = ({ commit, dispatch }, updatedData) =>
dispatch('setSelectedStage', updatedData);
};
export const receiveUpdateStageError = ({ commit }) => {
export const receiveUpdateStageError = (
{ commit },
{ error: { response: { status = 400, data: errorData } = {} } = {}, data },
) => {
commit(types.RECEIVE_UPDATE_STAGE_RESPONSE);
createFlash(__('There was a problem saving your custom stage, please try again'));
const ERROR_NAME_RESERVED = 'is reserved';
let message = __('There was a problem saving your custom stage, please try again');
if (status && status === httpStatus.UNPROCESSABLE_ENTITY) {
const { errors } = errorData;
const { name } = data;
if (errors.name && errors.name[0] === ERROR_NAME_RESERVED) {
message = __(`'${name}' stage already exists`);
}
}
createFlash(__(message));
};
export const updateStage = ({ dispatch, state }, { id, ...rest }) => {
......@@ -273,7 +287,7 @@ export const updateStage = ({ dispatch, state }, { id, ...rest }) => {
return Api.cycleAnalyticsUpdateStage(id, fullPath, { ...rest })
.then(({ data }) => dispatch('receiveUpdateStageSuccess', data))
.catch(error => dispatch('receiveUpdateStageError', error));
.catch(error => dispatch('receiveUpdateStageError', { error, data: { id, ...rest } }));
};
export const requestRemoveStage = ({ commit }) => commit(types.REQUEST_REMOVE_STAGE);
......
......@@ -399,6 +399,14 @@ describe 'Group Cycle Analytics', :js do
expect(page.find(stage_save_button)[:disabled]).to eq "true"
end
it 'with a default name' do
name = 'issue'
fill_in name_field, with: name
page.find(stage_save_button).click
expect(page.find('.flash-alert')).to have_text("'#{name}' stage already exists")
end
end
end
......
......@@ -562,25 +562,51 @@ describe('Cycle analytics actions', () => {
});
it('dispatches receiveUpdateStageError', done => {
const data = {
id: stageId,
...payload,
};
testAction(
actions.updateStage,
{
id: stageId,
...payload,
},
data,
state,
[],
[
{ type: 'requestUpdateStage' },
{
type: 'receiveUpdateStageError',
payload: error,
payload: { error, data },
},
],
done,
);
});
it('flashes an error if the stage name already exists', done => {
actions.receiveUpdateStageError(
{
commit: () => {},
state,
},
{
error: {
response: {
status: 422,
data: {
errors: { name: ['is reserved'] },
},
},
},
data: {
name: stageId,
},
},
);
shouldFlashAMessage(`'${stageId}' stage already exists`);
done();
});
it('flashes an error message', done => {
actions.receiveUpdateStageError(
{
......
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