Commit 9934d0f4 authored by Marvin Karegyeya's avatar Marvin Karegyeya Committed by Paul Slaughter

Remove update function logic from issue.js

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/21414
parent 191b9600
......@@ -99,31 +99,7 @@ class ListIssue {
}
update() {
const data = {
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 });
}
});
return boardsStore.updateIssue(this);
}
}
......
......@@ -6,7 +6,11 @@ import { sortBy } from 'lodash';
import Vue from 'vue';
import Cookies from 'js-cookie';
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 axios from '~/lib/utils/axios_utils';
import { mergeUrlParams } from '~/lib/utils/url_utility';
......@@ -632,6 +636,28 @@ const boardsStore = {
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);
......
---
title: Moves updateIssue from issue model to board store
merge_request: 21414
author: nuwe1
type: other
......@@ -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 */
import axios from '~/lib/utils/axios_utils';
import '~/boards/models/label';
import '~/boards/models/assignee';
import '~/boards/models/issue';
......@@ -173,25 +172,12 @@ describe('Issue model', () => {
});
describe('update', () => {
it('passes assignee ids when there are assignees', done => {
jest.spyOn(axios, 'patch').mockImplementation((url, data) => {
expect(data.issue.assignee_ids).toEqual([1]);
done();
return Promise.resolve();
});
issue.update('url');
});
it('passes update to boardsStore', () => {
jest.spyOn(boardsStore, 'updateIssue').mockImplementation();
it('passes assignee ids of [0] when there are no assignees', done => {
jest.spyOn(axios, 'patch').mockImplementation((url, data) => {
expect(data.issue.assignee_ids).toEqual([0]);
done();
return Promise.resolve();
});
issue.update();
issue.removeAllAssignees();
issue.update('url');
expect(boardsStore.updateIssue).toHaveBeenCalledWith(issue);
});
});
});
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