Commit 7eda1e71 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'Remove-update-function-logic-from-issue.js' into 'master'

Remove update function logic from issue.js

See merge request gitlab-org/gitlab!21414
parents 4d2e90e0 9934d0f4
...@@ -99,31 +99,7 @@ class ListIssue { ...@@ -99,31 +99,7 @@ class ListIssue {
} }
update() { update() {
const data = { return boardsStore.updateIssue(this);
issue: {
milestone_id: this.milestone ? this.milestone.id : null,
due_date: this.dueDate,
assignee_ids: this.assignees.length > 0 ? this.assignees.map(u => u.id) : [0],
label_ids: this.labels.map(label => label.id),
},
};
if (!data.issue.label_ids.length) {
data.issue.label_ids = [''];
}
const projectPath = this.project ? this.project.path : '';
return axios.patch(`${this.path}.json`, data).then(({ data: body = {} } = {}) => {
/**
* Since post implementation of Scoped labels, server can reject
* same key-ed labels. To keep the UI and server Model consistent,
* we're just assigning labels that server echo's back to us when we
* PATCH the said object.
*/
if (body) {
this.labels = convertObjectPropsToCamelCase(body.labels, { deep: true });
}
});
} }
} }
......
...@@ -6,7 +6,11 @@ import { sortBy } from 'lodash'; ...@@ -6,7 +6,11 @@ import { sortBy } from 'lodash';
import Vue from 'vue'; import Vue from 'vue';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import BoardsStoreEE from 'ee_else_ce/boards/stores/boards_store_ee'; import BoardsStoreEE from 'ee_else_ce/boards/stores/boards_store_ee';
import { getUrlParamsArray, parseBoolean } from '~/lib/utils/common_utils'; import {
getUrlParamsArray,
parseBoolean,
convertObjectPropsToCamelCase,
} from '~/lib/utils/common_utils';
import { __ } from '~/locale'; import { __ } from '~/locale';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { mergeUrlParams } from '~/lib/utils/url_utility'; import { mergeUrlParams } from '~/lib/utils/url_utility';
...@@ -632,6 +636,28 @@ const boardsStore = { ...@@ -632,6 +636,28 @@ const boardsStore = {
issue.assignees = obj.assignees.map(a => new ListAssignee(a)); issue.assignees = obj.assignees.map(a => new ListAssignee(a));
} }
}, },
updateIssue(issue) {
const data = {
issue: {
milestone_id: issue.milestone ? issue.milestone.id : null,
due_date: issue.dueDate,
assignee_ids: issue.assignees.length > 0 ? issue.assignees.map(({ id }) => id) : [0],
label_ids: issue.labels.length > 0 ? issue.labels.map(({ id }) => id) : [''],
},
};
return axios.patch(`${issue.path}.json`, data).then(({ data: body = {} } = {}) => {
/**
* Since post implementation of Scoped labels, server can reject
* same key-ed labels. To keep the UI and server Model consistent,
* we're just assigning labels that server echo's back to us when we
* PATCH the said object.
*/
if (body) {
issue.labels = convertObjectPropsToCamelCase(body.labels, { deep: true });
}
});
},
}; };
BoardsStoreEE.initEESpecific(boardsStore); BoardsStoreEE.initEESpecific(boardsStore);
......
---
title: Moves updateIssue from issue model to board store
merge_request: 21414
author: nuwe1
type: other
...@@ -1040,5 +1040,66 @@ describe('boardsStore', () => { ...@@ -1040,5 +1040,66 @@ describe('boardsStore', () => {
}); });
}); });
}); });
describe('updateIssue', () => {
let issue;
let patchSpy;
beforeEach(() => {
issue = new ListIssue({
title: 'Testing',
id: 1,
iid: 1,
confidential: false,
labels: [
{
id: 1,
title: 'test',
color: 'red',
description: 'testing',
},
],
assignees: [
{
id: 1,
name: 'name',
username: 'username',
avatar_url: 'http://avatar_url',
},
],
real_path: 'path/to/issue',
});
patchSpy = jest.fn().mockReturnValue([200, { labels: [] }]);
axiosMock.onPatch(`path/to/issue.json`).reply(({ data }) => patchSpy(JSON.parse(data)));
});
it('passes assignee ids when there are assignees', () => {
boardsStore.updateIssue(issue);
return boardsStore.updateIssue(issue).then(() => {
expect(patchSpy).toHaveBeenCalledWith({
issue: {
milestone_id: null,
assignee_ids: [1],
label_ids: [1],
},
});
});
});
it('passes assignee ids of [0] when there are no assignees', () => {
issue.removeAllAssignees();
return boardsStore.updateIssue(issue).then(() => {
expect(patchSpy).toHaveBeenCalledWith({
issue: {
milestone_id: null,
assignee_ids: [0],
label_ids: [1],
},
});
});
});
});
}); });
}); });
/* global ListIssue */ /* global ListIssue */
import axios from '~/lib/utils/axios_utils';
import '~/boards/models/label'; import '~/boards/models/label';
import '~/boards/models/assignee'; import '~/boards/models/assignee';
import '~/boards/models/issue'; import '~/boards/models/issue';
...@@ -173,25 +172,12 @@ describe('Issue model', () => { ...@@ -173,25 +172,12 @@ describe('Issue model', () => {
}); });
describe('update', () => { describe('update', () => {
it('passes assignee ids when there are assignees', done => { it('passes update to boardsStore', () => {
jest.spyOn(axios, 'patch').mockImplementation((url, data) => { jest.spyOn(boardsStore, 'updateIssue').mockImplementation();
expect(data.issue.assignee_ids).toEqual([1]);
done();
return Promise.resolve();
});
issue.update('url');
});
it('passes assignee ids of [0] when there are no assignees', done => { issue.update();
jest.spyOn(axios, 'patch').mockImplementation((url, data) => {
expect(data.issue.assignee_ids).toEqual([0]);
done();
return Promise.resolve();
});
issue.removeAllAssignees(); expect(boardsStore.updateIssue).toHaveBeenCalledWith(issue);
issue.update('url');
}); });
}); });
}); });
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