Commit 232c82b5 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '221259-move-package-js-routes-to-core' into 'master'

Move package api js routes to core [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!36642
parents bdce3caa 695b95d0
...@@ -11,6 +11,9 @@ const Api = { ...@@ -11,6 +11,9 @@ const Api = {
groupMembersPath: '/api/:version/groups/:id/members', groupMembersPath: '/api/:version/groups/:id/members',
subgroupsPath: '/api/:version/groups/:id/subgroups', subgroupsPath: '/api/:version/groups/:id/subgroups',
namespacesPath: '/api/:version/namespaces.json', namespacesPath: '/api/:version/namespaces.json',
groupPackagesPath: '/api/:version/groups/:id/packages',
projectPackagesPath: '/api/:version/projects/:id/packages',
projectPackagePath: '/api/:version/projects/:id/packages/:package_id',
groupProjectsPath: '/api/:version/groups/:id/projects.json', groupProjectsPath: '/api/:version/groups/:id/projects.json',
projectsPath: '/api/:version/projects.json', projectsPath: '/api/:version/projects.json',
projectPath: '/api/:version/projects/:id', projectPath: '/api/:version/projects/:id',
...@@ -66,6 +69,32 @@ const Api = { ...@@ -66,6 +69,32 @@ const Api = {
}); });
}, },
groupPackages(id, options = {}) {
const url = Api.buildUrl(this.groupPackagesPath).replace(':id', id);
return axios.get(url, options);
},
projectPackages(id, options = {}) {
const url = Api.buildUrl(this.projectPackagesPath).replace(':id', id);
return axios.get(url, options);
},
buildProjectPackageUrl(projectId, packageId) {
return Api.buildUrl(this.projectPackagePath)
.replace(':id', projectId)
.replace(':package_id', packageId);
},
projectPackage(projectId, packageId) {
const url = this.buildProjectPackageUrl(projectId, packageId);
return axios.get(url);
},
deleteProjectPackage(projectId, packageId) {
const url = this.buildProjectPackageUrl(projectId, packageId);
return axios.delete(url);
},
groupMembers(id, options) { groupMembers(id, options) {
const url = Api.buildUrl(this.groupMembersPath).replace(':id', encodeURIComponent(id)); const url = Api.buildUrl(this.groupMembersPath).replace(':id', encodeURIComponent(id));
......
...@@ -10,9 +10,6 @@ export default { ...@@ -10,9 +10,6 @@ export default {
childEpicPath: '/api/:version/groups/:id/epics/:epic_iid/epics', childEpicPath: '/api/:version/groups/:id/epics/:epic_iid/epics',
groupEpicsPath: '/api/:version/groups/:id/epics', groupEpicsPath: '/api/:version/groups/:id/epics',
epicIssuePath: '/api/:version/groups/:id/epics/:epic_iid/issues/:issue_id', epicIssuePath: '/api/:version/groups/:id/epics/:epic_iid/issues/:issue_id',
groupPackagesPath: '/api/:version/groups/:id/packages',
projectPackagesPath: '/api/:version/projects/:id/packages',
projectPackagePath: '/api/:version/projects/:id/packages/:package_id',
cycleAnalyticsTasksByTypePath: '/groups/:id/-/analytics/type_of_work/tasks_by_type', cycleAnalyticsTasksByTypePath: '/groups/:id/-/analytics/type_of_work/tasks_by_type',
cycleAnalyticsTopLabelsPath: '/groups/:id/-/analytics/type_of_work/tasks_by_type/top_labels', cycleAnalyticsTopLabelsPath: '/groups/:id/-/analytics/type_of_work/tasks_by_type/top_labels',
cycleAnalyticsSummaryDataPath: '/groups/:id/-/analytics/value_stream_analytics/summary', cycleAnalyticsSummaryDataPath: '/groups/:id/-/analytics/value_stream_analytics/summary',
...@@ -113,32 +110,6 @@ export default { ...@@ -113,32 +110,6 @@ export default {
return axios.delete(url); return axios.delete(url);
}, },
groupPackages(id, options = {}) {
const url = Api.buildUrl(this.groupPackagesPath).replace(':id', id);
return axios.get(url, options);
},
projectPackages(id, options = {}) {
const url = Api.buildUrl(this.projectPackagesPath).replace(':id', id);
return axios.get(url, options);
},
buildProjectPackageUrl(projectId, packageId) {
return Api.buildUrl(this.projectPackagePath)
.replace(':id', projectId)
.replace(':package_id', packageId);
},
projectPackage(projectId, packageId) {
const url = this.buildProjectPackageUrl(projectId, packageId);
return axios.get(url);
},
deleteProjectPackage(projectId, packageId) {
const url = this.buildProjectPackageUrl(projectId, packageId);
return axios.delete(url);
},
cycleAnalyticsTasksByType(groupId, params = {}) { cycleAnalyticsTasksByType(groupId, params = {}) {
const url = Api.buildUrl(this.cycleAnalyticsTasksByTypePath).replace(':id', groupId); const url = Api.buildUrl(this.cycleAnalyticsTasksByTypePath).replace(':id', groupId);
......
...@@ -200,77 +200,6 @@ describe('Api', () => { ...@@ -200,77 +200,6 @@ describe('Api', () => {
}); });
}); });
describe('packages', () => {
const projectId = 'project_a';
const packageId = 'package_b';
const apiResponse = [{ id: 1, name: 'foo' }];
describe('groupPackages', () => {
const groupId = 'group_a';
it('fetch all group packages', () => {
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/packages`;
jest.spyOn(axios, 'get');
mock.onGet(expectedUrl).replyOnce(200, apiResponse);
return Api.groupPackages(groupId).then(({ data }) => {
expect(data).toEqual(apiResponse);
expect(axios.get).toHaveBeenCalledWith(expectedUrl, {});
});
});
});
describe('projectPackages', () => {
it('fetch all project packages', () => {
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/packages`;
jest.spyOn(axios, 'get');
mock.onGet(expectedUrl).replyOnce(200, apiResponse);
return Api.projectPackages(projectId).then(({ data }) => {
expect(data).toEqual(apiResponse);
expect(axios.get).toHaveBeenCalledWith(expectedUrl, {});
});
});
});
describe('buildProjectPackageUrl', () => {
it('returns the right url', () => {
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/packages/${packageId}`;
const url = Api.buildProjectPackageUrl(projectId, packageId);
expect(url).toEqual(expectedUrl);
});
});
describe('projectPackage', () => {
it('fetch package details', () => {
const expectedUrl = `foo`;
jest.spyOn(Api, 'buildProjectPackageUrl').mockReturnValue(expectedUrl);
jest.spyOn(axios, 'get');
mock.onGet(expectedUrl).replyOnce(200, apiResponse);
return Api.projectPackage(projectId, packageId).then(({ data }) => {
expect(data).toEqual(apiResponse);
expect(axios.get).toHaveBeenCalledWith(expectedUrl);
});
});
});
describe('deleteProjectPackage', () => {
it('delete a package', () => {
const expectedUrl = `foo`;
jest.spyOn(Api, 'buildProjectPackageUrl').mockReturnValue(expectedUrl);
jest.spyOn(axios, 'delete');
mock.onDelete(expectedUrl).replyOnce(200, true);
return Api.deleteProjectPackage(projectId, packageId).then(({ data }) => {
expect(data).toEqual(true);
expect(axios.delete).toHaveBeenCalledWith(expectedUrl);
});
});
});
});
describe('Cycle analytics', () => { describe('Cycle analytics', () => {
const groupId = 'counting-54321'; const groupId = 'counting-54321';
const createdBefore = '2019-11-18'; const createdBefore = '2019-11-18';
......
...@@ -46,6 +46,77 @@ describe('Api', () => { ...@@ -46,6 +46,77 @@ describe('Api', () => {
}); });
}); });
describe('packages', () => {
const projectId = 'project_a';
const packageId = 'package_b';
const apiResponse = [{ id: 1, name: 'foo' }];
describe('groupPackages', () => {
const groupId = 'group_a';
it('fetch all group packages', () => {
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/packages`;
jest.spyOn(axios, 'get');
mock.onGet(expectedUrl).replyOnce(200, apiResponse);
return Api.groupPackages(groupId).then(({ data }) => {
expect(data).toEqual(apiResponse);
expect(axios.get).toHaveBeenCalledWith(expectedUrl, {});
});
});
});
describe('projectPackages', () => {
it('fetch all project packages', () => {
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/packages`;
jest.spyOn(axios, 'get');
mock.onGet(expectedUrl).replyOnce(200, apiResponse);
return Api.projectPackages(projectId).then(({ data }) => {
expect(data).toEqual(apiResponse);
expect(axios.get).toHaveBeenCalledWith(expectedUrl, {});
});
});
});
describe('buildProjectPackageUrl', () => {
it('returns the right url', () => {
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/packages/${packageId}`;
const url = Api.buildProjectPackageUrl(projectId, packageId);
expect(url).toEqual(expectedUrl);
});
});
describe('projectPackage', () => {
it('fetch package details', () => {
const expectedUrl = `foo`;
jest.spyOn(Api, 'buildProjectPackageUrl').mockReturnValue(expectedUrl);
jest.spyOn(axios, 'get');
mock.onGet(expectedUrl).replyOnce(200, apiResponse);
return Api.projectPackage(projectId, packageId).then(({ data }) => {
expect(data).toEqual(apiResponse);
expect(axios.get).toHaveBeenCalledWith(expectedUrl);
});
});
});
describe('deleteProjectPackage', () => {
it('delete a package', () => {
const expectedUrl = `foo`;
jest.spyOn(Api, 'buildProjectPackageUrl').mockReturnValue(expectedUrl);
jest.spyOn(axios, 'delete');
mock.onDelete(expectedUrl).replyOnce(200, true);
return Api.deleteProjectPackage(projectId, packageId).then(({ data }) => {
expect(data).toEqual(true);
expect(axios.delete).toHaveBeenCalledWith(expectedUrl);
});
});
});
});
describe('group', () => { describe('group', () => {
it('fetches a group', done => { it('fetches a group', done => {
const groupId = '123456'; const groupId = '123456';
......
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