Commit 0d37b30c authored by Scott Stern's avatar Scott Stern Committed by Andrew Fontaine

Add update issue by id mutation

parent 5bdbf365
......@@ -27,3 +27,4 @@ export const RECEIVE_UPDATE_ISSUE_ERROR = 'RECEIVE_UPDATE_ISSUE_ERROR';
export const SET_CURRENT_PAGE = 'SET_CURRENT_PAGE';
export const TOGGLE_EMPTY_STATE = 'TOGGLE_EMPTY_STATE';
export const SET_ACTIVE_ID = 'SET_ACTIVE_ID';
export const UPDATE_ISSUE_BY_ID = 'UPDATE_ISSUE_BY_ID';
......@@ -81,6 +81,15 @@ export default {
state.isLoadingIssues = false;
},
[mutationTypes.UPDATE_ISSUE_BY_ID]: (state, { issueId, prop, value }) => {
if (!state.issues[issueId]) {
/* eslint-disable-next-line @gitlab/require-i18n-strings */
throw new Error('No issue found.');
}
Vue.set(state.issues[issueId], prop, value);
},
[mutationTypes.RECEIVE_ISSUES_FOR_ALL_LISTS_FAILURE]: state => {
state.error = __('An error occurred while fetching the board issues. Please reload the page.');
state.isLoadingIssues = false;
......
---
title: Add update issue by id in vuex for boards
merge_request: 41226
author:
type: added
......@@ -190,6 +190,48 @@ describe('Board Store Mutations', () => {
});
});
describe('UPDATE_ISSUE_BY_ID', () => {
const issueId = '1';
const prop = 'id';
const value = '2';
const issue = { [issueId]: { id: 1, title: 'Issue' } };
beforeEach(() => {
state = {
...state,
isLoadingIssues: true,
error: undefined,
issues: {
...issue,
},
};
});
describe('when the issue is in state', () => {
it('updates the property of the correct issue', () => {
mutations.UPDATE_ISSUE_BY_ID(state, {
issueId,
prop,
value,
});
expect(state.issues[issueId]).toEqual({ ...issue[issueId], id: '2' });
});
});
describe('when the issue is not in state', () => {
it('throws an error', () => {
expect(() => {
mutations.UPDATE_ISSUE_BY_ID(state, {
issueId: '3',
prop,
value,
});
}).toThrow(new Error('No issue found.'));
});
});
});
describe('RECEIVE_ADD_ISSUE_SUCCESS', () => {
expectNotImplemented(mutations.RECEIVE_ADD_ISSUE_SUCCESS);
});
......
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