Commit 95c795de authored by Paul Slaughter's avatar Paul Slaughter Committed by Phil Hughes

Resolve "Bug - Web Based IDE - The "Merge" Requests Selection displays Merge...

Resolve "Bug - Web Based IDE - The "Merge" Requests Selection displays Merge Requests from other projects"
parent 6fd5ba3b
...@@ -10,10 +10,10 @@ const Api = { ...@@ -10,10 +10,10 @@ const Api = {
projectsPath: '/api/:version/projects.json', projectsPath: '/api/:version/projects.json',
projectPath: '/api/:version/projects/:id', projectPath: '/api/:version/projects/:id',
projectLabelsPath: '/:namespace_path/:project_path/labels', projectLabelsPath: '/:namespace_path/:project_path/labels',
mergeRequestPath: '/api/:version/projects/:id/merge_requests/:mrid', projectMergeRequestPath: '/api/:version/projects/:id/merge_requests/:mrid',
projectMergeRequestChangesPath: '/api/:version/projects/:id/merge_requests/:mrid/changes',
projectMergeRequestVersionsPath: '/api/:version/projects/:id/merge_requests/:mrid/versions',
mergeRequestsPath: '/api/:version/merge_requests', mergeRequestsPath: '/api/:version/merge_requests',
mergeRequestChangesPath: '/api/:version/projects/:id/merge_requests/:mrid/changes',
mergeRequestVersionsPath: '/api/:version/projects/:id/merge_requests/:mrid/versions',
groupLabelsPath: '/groups/:namespace_path/-/labels', groupLabelsPath: '/groups/:namespace_path/-/labels',
issuableTemplatePath: '/:namespace_path/:project_path/templates/:type/:key', issuableTemplatePath: '/:namespace_path/:project_path/templates/:type/:key',
projectTemplatePath: '/api/:version/projects/:id/templates/:type/:key', projectTemplatePath: '/api/:version/projects/:id/templates/:type/:key',
...@@ -99,36 +99,36 @@ const Api = { ...@@ -99,36 +99,36 @@ const Api = {
}, },
// Return Merge Request for project // Return Merge Request for project
mergeRequest(projectPath, mergeRequestId, params = {}) { projectMergeRequest(projectPath, mergeRequestId, params = {}) {
const url = Api.buildUrl(Api.mergeRequestPath) const url = Api.buildUrl(Api.projectMergeRequestPath)
.replace(':id', encodeURIComponent(projectPath)) .replace(':id', encodeURIComponent(projectPath))
.replace(':mrid', mergeRequestId); .replace(':mrid', mergeRequestId);
return axios.get(url, { params }); return axios.get(url, { params });
}, },
mergeRequests(params = {}) { projectMergeRequestChanges(projectPath, mergeRequestId) {
const url = Api.buildUrl(Api.mergeRequestsPath); const url = Api.buildUrl(Api.projectMergeRequestChangesPath)
return axios.get(url, { params });
},
mergeRequestChanges(projectPath, mergeRequestId) {
const url = Api.buildUrl(Api.mergeRequestChangesPath)
.replace(':id', encodeURIComponent(projectPath)) .replace(':id', encodeURIComponent(projectPath))
.replace(':mrid', mergeRequestId); .replace(':mrid', mergeRequestId);
return axios.get(url); return axios.get(url);
}, },
mergeRequestVersions(projectPath, mergeRequestId) { projectMergeRequestVersions(projectPath, mergeRequestId) {
const url = Api.buildUrl(Api.mergeRequestVersionsPath) const url = Api.buildUrl(Api.projectMergeRequestVersionsPath)
.replace(':id', encodeURIComponent(projectPath)) .replace(':id', encodeURIComponent(projectPath))
.replace(':mrid', mergeRequestId); .replace(':mrid', mergeRequestId);
return axios.get(url); return axios.get(url);
}, },
mergeRequests(params = {}) {
const url = Api.buildUrl(Api.mergeRequestsPath);
return axios.get(url, { params });
},
newLabel(namespacePath, projectPath, data, callback) { newLabel(namespacePath, projectPath, data, callback) {
let url; let url;
......
...@@ -41,13 +41,13 @@ export default { ...@@ -41,13 +41,13 @@ export default {
return Api.project(`${namespace}/${project}`); return Api.project(`${namespace}/${project}`);
}, },
getProjectMergeRequestData(projectId, mergeRequestId, params = {}) { getProjectMergeRequestData(projectId, mergeRequestId, params = {}) {
return Api.mergeRequest(projectId, mergeRequestId, params); return Api.projectMergeRequest(projectId, mergeRequestId, params);
}, },
getProjectMergeRequestChanges(projectId, mergeRequestId) { getProjectMergeRequestChanges(projectId, mergeRequestId) {
return Api.mergeRequestChanges(projectId, mergeRequestId); return Api.projectMergeRequestChanges(projectId, mergeRequestId);
}, },
getProjectMergeRequestVersions(projectId, mergeRequestId) { getProjectMergeRequestVersions(projectId, mergeRequestId) {
return Api.mergeRequestVersions(projectId, mergeRequestId); return Api.projectMergeRequestVersions(projectId, mergeRequestId);
}, },
getBranchData(projectId, currentBranchId) { getBranchData(projectId, currentBranchId) {
return Api.branchSingle(projectId, currentBranchId); return Api.branchSingle(projectId, currentBranchId);
......
...@@ -23,13 +23,19 @@ export const receiveMergeRequestsError = ({ commit, dispatch }, { type, search } ...@@ -23,13 +23,19 @@ export const receiveMergeRequestsError = ({ commit, dispatch }, { type, search }
export const receiveMergeRequestsSuccess = ({ commit }, data) => export const receiveMergeRequestsSuccess = ({ commit }, data) =>
commit(types.RECEIVE_MERGE_REQUESTS_SUCCESS, data); commit(types.RECEIVE_MERGE_REQUESTS_SUCCESS, data);
export const fetchMergeRequests = ({ dispatch, state: { state } }, { type, search = '' }) => { export const fetchMergeRequests = (
{ dispatch, state: { state }, rootState: { currentProjectId } },
{ type, search = '' },
) => {
dispatch('requestMergeRequests'); dispatch('requestMergeRequests');
dispatch('resetMergeRequests'); dispatch('resetMergeRequests');
const scope = type ? scopes[type] : 'all'; const scope = type && scopes[type];
const request = scope
? Api.mergeRequests({ scope, state, search })
: Api.projectMergeRequest(currentProjectId, '', { state, search });
return Api.mergeRequests({ scope, state, search }) return request
.then(({ data }) => dispatch('receiveMergeRequestsSuccess', data)) .then(({ data }) => dispatch('receiveMergeRequestsSuccess', data))
.catch(() => dispatch('receiveMergeRequestsError', { type, search })); .catch(() => dispatch('receiveMergeRequestsError', { type, search }));
}; };
......
---
title: Scope default MR search in WebIDE dropdown to current project
merge_request: 23400
author:
type: changed
...@@ -123,7 +123,7 @@ describe('Api', () => { ...@@ -123,7 +123,7 @@ describe('Api', () => {
}); });
}); });
describe('mergerequest', () => { describe('projectMergeRequest', () => {
it('fetches a merge request', done => { it('fetches a merge request', done => {
const projectPath = 'abc'; const projectPath = 'abc';
const mergeRequestId = '123456'; const mergeRequestId = '123456';
...@@ -132,7 +132,7 @@ describe('Api', () => { ...@@ -132,7 +132,7 @@ describe('Api', () => {
title: 'test', title: 'test',
}); });
Api.mergeRequest(projectPath, mergeRequestId) Api.projectMergeRequest(projectPath, mergeRequestId)
.then(({ data }) => { .then(({ data }) => {
expect(data.title).toBe('test'); expect(data.title).toBe('test');
}) })
...@@ -141,7 +141,7 @@ describe('Api', () => { ...@@ -141,7 +141,7 @@ describe('Api', () => {
}); });
}); });
describe('mergerequest changes', () => { describe('projectMergeRequestChanges', () => {
it('fetches the changes of a merge request', done => { it('fetches the changes of a merge request', done => {
const projectPath = 'abc'; const projectPath = 'abc';
const mergeRequestId = '123456'; const mergeRequestId = '123456';
...@@ -150,7 +150,7 @@ describe('Api', () => { ...@@ -150,7 +150,7 @@ describe('Api', () => {
title: 'test', title: 'test',
}); });
Api.mergeRequestChanges(projectPath, mergeRequestId) Api.projectMergeRequestChanges(projectPath, mergeRequestId)
.then(({ data }) => { .then(({ data }) => {
expect(data.title).toBe('test'); expect(data.title).toBe('test');
}) })
...@@ -159,7 +159,7 @@ describe('Api', () => { ...@@ -159,7 +159,7 @@ describe('Api', () => {
}); });
}); });
describe('mergerequest versions', () => { describe('projectMergeRequestVersions', () => {
it('fetches the versions of a merge request', done => { it('fetches the versions of a merge request', done => {
const projectPath = 'abc'; const projectPath = 'abc';
const mergeRequestId = '123456'; const mergeRequestId = '123456';
...@@ -170,7 +170,7 @@ describe('Api', () => { ...@@ -170,7 +170,7 @@ describe('Api', () => {
}, },
]); ]);
Api.mergeRequestVersions(projectPath, mergeRequestId) Api.projectMergeRequestVersions(projectPath, mergeRequestId)
.then(({ data }) => { .then(({ data }) => {
expect(data.length).toBe(1); expect(data.length).toBe(1);
expect(data[0].id).toBe(123); expect(data[0].id).toBe(123);
......
...@@ -14,10 +14,14 @@ import testAction from '../../../../helpers/vuex_action_helper'; ...@@ -14,10 +14,14 @@ import testAction from '../../../../helpers/vuex_action_helper';
describe('IDE merge requests actions', () => { describe('IDE merge requests actions', () => {
let mockedState; let mockedState;
let mockedRootState;
let mock; let mock;
beforeEach(() => { beforeEach(() => {
mockedState = state(); mockedState = state();
mockedRootState = {
currentProjectId: 7,
};
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
}); });
...@@ -86,13 +90,16 @@ describe('IDE merge requests actions', () => { ...@@ -86,13 +90,16 @@ describe('IDE merge requests actions', () => {
describe('success', () => { describe('success', () => {
beforeEach(() => { beforeEach(() => {
mock.onGet(/\/api\/v4\/merge_requests(.*)$/).replyOnce(200, mergeRequests); mock.onGet(/\/api\/v4\/merge_requests\/?/).replyOnce(200, mergeRequests);
}); });
it('calls API with params', () => { it('calls API with params', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough(); const apiSpy = spyOn(axios, 'get').and.callThrough();
fetchMergeRequests({ dispatch() {}, state: mockedState }, { type: 'created' }); fetchMergeRequests(
{ dispatch() {}, state: mockedState, rootState: mockedRootState },
{ type: 'created' },
);
expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), { expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), {
params: { params: {
...@@ -107,7 +114,7 @@ describe('IDE merge requests actions', () => { ...@@ -107,7 +114,7 @@ describe('IDE merge requests actions', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough(); const apiSpy = spyOn(axios, 'get').and.callThrough();
fetchMergeRequests( fetchMergeRequests(
{ dispatch() {}, state: mockedState }, { dispatch() {}, state: mockedState, rootState: mockedRootState },
{ type: 'created', search: 'testing search' }, { type: 'created', search: 'testing search' },
); );
...@@ -139,6 +146,49 @@ describe('IDE merge requests actions', () => { ...@@ -139,6 +146,49 @@ describe('IDE merge requests actions', () => {
}); });
}); });
describe('success without type', () => {
beforeEach(() => {
mock.onGet(/\/api\/v4\/projects\/.+\/merge_requests\/?$/).replyOnce(200, mergeRequests);
});
it('calls API with project', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough();
fetchMergeRequests(
{ dispatch() {}, state: mockedState, rootState: mockedRootState },
{ type: null, search: 'testing search' },
);
expect(apiSpy).toHaveBeenCalledWith(
jasmine.stringMatching(`projects/${mockedRootState.currentProjectId}/merge_requests`),
{
params: {
state: 'opened',
search: 'testing search',
},
},
);
});
it('dispatches success with received data', done => {
testAction(
fetchMergeRequests,
{ type: null },
{ ...mockedState, ...mockedRootState },
[],
[
{ type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' },
{
type: 'receiveMergeRequestsSuccess',
payload: mergeRequests,
},
],
done,
);
});
});
describe('error', () => { describe('error', () => {
beforeEach(() => { beforeEach(() => {
mock.onGet(/\/api\/v4\/merge_requests(.*)$/).replyOnce(500); mock.onGet(/\/api\/v4\/merge_requests(.*)$/).replyOnce(500);
......
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