2018-01-25 11:40:31 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-05-19 17:22:46 -04:00
|
|
|
import Api from '~/api';
|
2020-07-23 02:09:19 -04:00
|
|
|
import httpStatus from '~/lib/utils/http_status';
|
2017-05-19 17:22:46 -04:00
|
|
|
|
|
|
|
describe('Api', () => {
|
|
|
|
const dummyApiVersion = 'v3000';
|
2019-04-24 13:30:46 -04:00
|
|
|
const dummyUrlRoot = '/gitlab';
|
2017-05-19 17:22:46 -04:00
|
|
|
const dummyGon = {
|
|
|
|
api_version: dummyApiVersion,
|
|
|
|
relative_url_root: dummyUrlRoot,
|
|
|
|
};
|
|
|
|
let originalGon;
|
2018-01-25 11:40:31 -05:00
|
|
|
let mock;
|
2017-05-19 17:22:46 -04:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-01-25 11:40:31 -05:00
|
|
|
mock = new MockAdapter(axios);
|
2017-05-19 17:22:46 -04:00
|
|
|
originalGon = window.gon;
|
2020-05-07 17:09:26 -04:00
|
|
|
window.gon = { ...dummyGon };
|
2017-05-19 17:22:46 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-01-25 11:40:31 -05:00
|
|
|
mock.restore();
|
2017-05-19 17:22:46 -04:00
|
|
|
window.gon = originalGon;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('buildUrl', () => {
|
|
|
|
it('adds URL root and fills in API version', () => {
|
|
|
|
const input = '/api/:version/foo/bar';
|
|
|
|
const expectedOutput = `${dummyUrlRoot}/api/${dummyApiVersion}/foo/bar`;
|
|
|
|
|
|
|
|
const builtUrl = Api.buildUrl(input);
|
|
|
|
|
|
|
|
expect(builtUrl).toEqual(expectedOutput);
|
|
|
|
});
|
2019-04-24 13:30:46 -04:00
|
|
|
|
|
|
|
[null, '', '/'].forEach(root => {
|
|
|
|
it(`works when relative_url_root is ${root}`, () => {
|
|
|
|
window.gon.relative_url_root = root;
|
|
|
|
const input = '/api/:version/foo/bar';
|
|
|
|
const expectedOutput = `/api/${dummyApiVersion}/foo/bar`;
|
|
|
|
|
|
|
|
const builtUrl = Api.buildUrl(input);
|
|
|
|
|
|
|
|
expect(builtUrl).toEqual(expectedOutput);
|
|
|
|
});
|
|
|
|
});
|
2017-05-19 17:22:46 -04:00
|
|
|
});
|
|
|
|
|
2020-07-16 05:09:28 -04:00
|
|
|
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');
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, apiResponse);
|
2020-07-16 05:09:28 -04:00
|
|
|
|
|
|
|
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');
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, apiResponse);
|
2020-07-16 05:09:28 -04:00
|
|
|
|
|
|
|
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');
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, apiResponse);
|
2020-07-16 05:09:28 -04:00
|
|
|
|
|
|
|
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');
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onDelete(expectedUrl).replyOnce(httpStatus.OK, true);
|
2020-07-16 05:09:28 -04:00
|
|
|
|
|
|
|
return Api.deleteProjectPackage(projectId, packageId).then(({ data }) => {
|
|
|
|
expect(data).toEqual(true);
|
|
|
|
expect(axios.delete).toHaveBeenCalledWith(expectedUrl);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-19 17:22:46 -04:00
|
|
|
describe('group', () => {
|
2018-03-26 08:18:24 -04:00
|
|
|
it('fetches a group', done => {
|
2017-05-19 17:22:46 -04:00
|
|
|
const groupId = '123456';
|
2018-01-30 05:52:38 -05:00
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, {
|
2018-01-25 11:40:31 -05:00
|
|
|
name: 'test',
|
2017-05-19 17:22:46 -04:00
|
|
|
});
|
|
|
|
|
2018-03-26 08:18:24 -04:00
|
|
|
Api.group(groupId, response => {
|
2018-01-25 11:40:31 -05:00
|
|
|
expect(response.name).toBe('test');
|
2017-05-19 17:22:46 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-01-16 16:57:50 -05:00
|
|
|
describe('groupMembers', () => {
|
|
|
|
it('fetches group members', done => {
|
|
|
|
const groupId = '54321';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/members`;
|
|
|
|
const expectedData = [{ id: 7 }];
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, expectedData);
|
2019-01-16 16:57:50 -05:00
|
|
|
|
|
|
|
Api.groupMembers(groupId)
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data).toEqual(expectedData);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-13 02:10:02 -04:00
|
|
|
describe('groupMilestones', () => {
|
|
|
|
it('fetches group milestones', done => {
|
|
|
|
const groupId = '16';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/milestones`;
|
|
|
|
const expectedData = [
|
|
|
|
{
|
|
|
|
id: 12,
|
|
|
|
iid: 3,
|
|
|
|
group_id: 16,
|
|
|
|
title: '10.0',
|
|
|
|
description: 'Version',
|
|
|
|
due_date: '2013-11-29',
|
|
|
|
start_date: '2013-11-10',
|
|
|
|
state: 'active',
|
|
|
|
updated_at: '2013-10-02T09:24:18Z',
|
|
|
|
created_at: '2013-10-02T09:24:18Z',
|
|
|
|
web_url: 'https://gitlab.com/groups/gitlab-org/-/milestones/42',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, expectedData);
|
|
|
|
|
|
|
|
Api.groupMilestones(groupId)
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data).toEqual(expectedData);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-19 17:22:46 -04:00
|
|
|
describe('groups', () => {
|
2018-03-26 08:18:24 -04:00
|
|
|
it('fetches groups', done => {
|
2017-05-19 17:22:46 -04:00
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups.json`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-03-26 08:18:24 -04:00
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
2017-05-19 17:22:46 -04:00
|
|
|
|
2018-03-26 08:18:24 -04:00
|
|
|
Api.groups(query, options, response => {
|
2018-01-25 11:40:31 -05:00
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
2017-05-19 17:22:46 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('namespaces', () => {
|
2018-03-26 08:18:24 -04:00
|
|
|
it('fetches namespaces', done => {
|
2017-05-19 17:22:46 -04:00
|
|
|
const query = 'dummy query';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/namespaces.json`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-03-26 08:18:24 -04:00
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
2017-05-19 17:22:46 -04:00
|
|
|
|
2018-03-26 08:18:24 -04:00
|
|
|
Api.namespaces(query, response => {
|
2018-01-25 11:40:31 -05:00
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
2017-05-19 17:22:46 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('projects', () => {
|
2018-03-26 08:18:24 -04:00
|
|
|
it('fetches projects with membership when logged in', done => {
|
2017-05-19 17:22:46 -04:00
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
2017-09-04 11:41:55 -04:00
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects.json`;
|
2017-08-22 11:10:49 -04:00
|
|
|
window.gon.current_user_id = 1;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-03-26 08:18:24 -04:00
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
2017-05-19 17:22:46 -04:00
|
|
|
|
2018-03-26 08:18:24 -04:00
|
|
|
Api.projects(query, options, response => {
|
2018-01-25 11:40:31 -05:00
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
2017-05-19 17:22:46 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-08-22 11:10:49 -04:00
|
|
|
|
2018-03-26 08:18:24 -04:00
|
|
|
it('fetches projects without membership when not logged in', done => {
|
2017-08-22 11:10:49 -04:00
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
2017-09-04 11:41:55 -04:00
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects.json`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-03-26 08:18:24 -04:00
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
2017-08-22 11:10:49 -04:00
|
|
|
|
2018-03-26 08:18:24 -04:00
|
|
|
Api.projects(query, options, response => {
|
2018-01-25 11:40:31 -05:00
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
2017-08-22 11:10:49 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-05-19 17:22:46 -04:00
|
|
|
});
|
|
|
|
|
2019-12-19 07:07:35 -05:00
|
|
|
describe('updateProject', () => {
|
|
|
|
it('update a project with the given payload', done => {
|
|
|
|
const projectPath = 'foo';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onPut(expectedUrl).reply(httpStatus.OK, { foo: 'bar' });
|
2019-12-19 07:07:35 -05:00
|
|
|
|
|
|
|
Api.updateProject(projectPath, { foo: 'bar' })
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.foo).toBe('bar');
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-08-14 05:55:40 -04:00
|
|
|
describe('projectUsers', () => {
|
|
|
|
it('fetches all users of a particular project', done => {
|
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
|
|
|
const projectPath = 'gitlab-org%2Fgitlab-ce';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/users`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2019-08-14 05:55:40 -04:00
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
Api.projectUsers('gitlab-org/gitlab-ce', query, options)
|
|
|
|
.then(response => {
|
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-01 11:33:18 -05:00
|
|
|
describe('projectMergeRequests', () => {
|
|
|
|
const projectPath = 'abc';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests`;
|
|
|
|
|
|
|
|
it('fetches all merge requests for a project', done => {
|
|
|
|
const mockData = [{ source_branch: 'foo' }, { source_branch: 'bar' }];
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, mockData);
|
2019-03-01 11:33:18 -05:00
|
|
|
Api.projectMergeRequests(projectPath)
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.length).toEqual(2);
|
|
|
|
expect(data[0].source_branch).toBe('foo');
|
|
|
|
expect(data[1].source_branch).toBe('bar');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('fetches merge requests filtered with passed params', done => {
|
|
|
|
const params = {
|
|
|
|
source_branch: 'bar',
|
|
|
|
};
|
|
|
|
const mockData = [{ source_branch: 'bar' }];
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl, { params }).reply(httpStatus.OK, mockData);
|
2019-03-01 11:33:18 -05:00
|
|
|
|
|
|
|
Api.projectMergeRequests(projectPath, params)
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.length).toEqual(1);
|
|
|
|
expect(data[0].source_branch).toBe('bar');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-28 10:09:38 -05:00
|
|
|
describe('projectMergeRequest', () => {
|
2018-03-26 08:18:24 -04:00
|
|
|
it('fetches a merge request', done => {
|
|
|
|
const projectPath = 'abc';
|
|
|
|
const mergeRequestId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, {
|
2018-03-26 08:18:24 -04:00
|
|
|
title: 'test',
|
|
|
|
});
|
|
|
|
|
2018-11-28 10:09:38 -05:00
|
|
|
Api.projectMergeRequest(projectPath, mergeRequestId)
|
2018-03-26 08:18:24 -04:00
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.title).toBe('test');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-28 10:09:38 -05:00
|
|
|
describe('projectMergeRequestChanges', () => {
|
2018-03-26 08:18:24 -04:00
|
|
|
it('fetches the changes of a merge request', done => {
|
|
|
|
const projectPath = 'abc';
|
|
|
|
const mergeRequestId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/changes`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, {
|
2018-03-26 08:18:24 -04:00
|
|
|
title: 'test',
|
|
|
|
});
|
|
|
|
|
2018-11-28 10:09:38 -05:00
|
|
|
Api.projectMergeRequestChanges(projectPath, mergeRequestId)
|
2018-03-26 08:18:24 -04:00
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.title).toBe('test');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-28 10:09:38 -05:00
|
|
|
describe('projectMergeRequestVersions', () => {
|
2018-03-26 08:18:24 -04:00
|
|
|
it('fetches the versions of a merge request', done => {
|
|
|
|
const projectPath = 'abc';
|
|
|
|
const mergeRequestId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/versions`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-03-26 08:18:24 -04:00
|
|
|
{
|
|
|
|
id: 123,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2018-11-28 10:09:38 -05:00
|
|
|
Api.projectMergeRequestVersions(projectPath, mergeRequestId)
|
2018-03-26 08:18:24 -04:00
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.length).toBe(1);
|
|
|
|
expect(data[0].id).toBe(123);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-05 02:22:00 -05:00
|
|
|
describe('projectRunners', () => {
|
|
|
|
it('fetches the runners of a project', done => {
|
|
|
|
const projectPath = 7;
|
|
|
|
const params = { scope: 'active' };
|
|
|
|
const mockData = [{ id: 4 }];
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/runners`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl, { params }).reply(httpStatus.OK, mockData);
|
2018-12-05 02:22:00 -05:00
|
|
|
|
|
|
|
Api.projectRunners(projectPath, { params })
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data).toEqual(mockData);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-21 11:10:03 -04:00
|
|
|
describe('projectMilestones', () => {
|
|
|
|
it('fetches project milestones', done => {
|
|
|
|
const projectId = 1;
|
|
|
|
const options = { state: 'active' };
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/1/milestones`;
|
|
|
|
mock.onGet(expectedUrl).reply(200, [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
title: 'milestone1',
|
|
|
|
state: 'active',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
Api.projectMilestones(projectId, options)
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.length).toBe(1);
|
|
|
|
expect(data[0].title).toBe('milestone1');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-19 05:08:58 -04:00
|
|
|
describe('addProjectIssueAsTodo', () => {
|
|
|
|
it('adds issue ID as a todo', () => {
|
|
|
|
const projectId = 1;
|
|
|
|
const issueIid = 11;
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/1/issues/11/todo`;
|
|
|
|
mock.onPost(expectedUrl).reply(200, {
|
|
|
|
id: 112,
|
|
|
|
project: {
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return Api.addProjectIssueAsTodo(projectId, issueIid).then(({ data }) => {
|
|
|
|
expect(data.id).toBe(112);
|
|
|
|
expect(data.project.id).toBe(projectId);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-05-19 17:22:46 -04:00
|
|
|
describe('newLabel', () => {
|
2018-03-26 08:18:24 -04:00
|
|
|
it('creates a new label', done => {
|
2017-05-19 17:22:46 -04:00
|
|
|
const namespace = 'some namespace';
|
|
|
|
const project = 'some project';
|
|
|
|
const labelData = { some: 'data' };
|
2019-05-30 05:59:03 -04:00
|
|
|
const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/-/labels`;
|
2017-05-19 17:22:46 -04:00
|
|
|
const expectedData = {
|
|
|
|
label: labelData,
|
|
|
|
};
|
2018-03-26 08:18:24 -04:00
|
|
|
mock.onPost(expectedUrl).reply(config => {
|
2018-01-25 11:40:31 -05:00
|
|
|
expect(config.data).toBe(JSON.stringify(expectedData));
|
|
|
|
|
2018-03-26 08:18:24 -04:00
|
|
|
return [
|
2020-07-23 02:09:19 -04:00
|
|
|
httpStatus.OK,
|
2018-03-26 08:18:24 -04:00
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
];
|
2017-05-19 17:22:46 -04:00
|
|
|
});
|
|
|
|
|
2018-03-26 08:18:24 -04:00
|
|
|
Api.newLabel(namespace, project, labelData, response => {
|
2018-01-25 11:40:31 -05:00
|
|
|
expect(response.name).toBe('test');
|
2017-05-19 17:22:46 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-02-19 14:06:16 -05:00
|
|
|
|
2018-03-26 08:18:24 -04:00
|
|
|
it('creates a group label', done => {
|
2018-02-19 14:06:16 -05:00
|
|
|
const namespace = 'group/subgroup';
|
|
|
|
const labelData = { some: 'data' };
|
2019-05-21 23:03:11 -04:00
|
|
|
const expectedUrl = Api.buildUrl(Api.groupLabelsPath).replace(':namespace_path', namespace);
|
2018-02-19 14:06:16 -05:00
|
|
|
const expectedData = {
|
|
|
|
label: labelData,
|
|
|
|
};
|
2018-03-26 08:18:24 -04:00
|
|
|
mock.onPost(expectedUrl).reply(config => {
|
2018-02-19 14:06:16 -05:00
|
|
|
expect(config.data).toBe(JSON.stringify(expectedData));
|
|
|
|
|
2018-03-26 08:18:24 -04:00
|
|
|
return [
|
2020-07-23 02:09:19 -04:00
|
|
|
httpStatus.OK,
|
2018-03-26 08:18:24 -04:00
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
];
|
2018-02-19 14:06:16 -05:00
|
|
|
});
|
|
|
|
|
2018-03-26 08:18:24 -04:00
|
|
|
Api.newLabel(namespace, undefined, labelData, response => {
|
2018-02-19 14:06:16 -05:00
|
|
|
expect(response.name).toBe('test');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-05-19 17:22:46 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('groupProjects', () => {
|
2018-03-26 08:18:24 -04:00
|
|
|
it('fetches group projects', done => {
|
2017-05-19 17:22:46 -04:00
|
|
|
const groupId = '123456';
|
|
|
|
const query = 'dummy query';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/projects.json`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-03-26 08:18:24 -04:00
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
2017-05-19 17:22:46 -04:00
|
|
|
|
2018-07-02 04:04:43 -04:00
|
|
|
Api.groupProjects(groupId, query, {}, response => {
|
2018-01-25 11:40:31 -05:00
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
2017-05-19 17:22:46 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-09 02:09:37 -04:00
|
|
|
describe('commit', () => {
|
|
|
|
const projectId = 'user/project';
|
|
|
|
const sha = 'abcd0123';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent(
|
|
|
|
projectId,
|
|
|
|
)}/repository/commits/${sha}`;
|
|
|
|
|
|
|
|
it('fetches a single commit', () => {
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, { id: sha });
|
2020-07-09 02:09:37 -04:00
|
|
|
|
|
|
|
return Api.commit(projectId, sha).then(({ data: commit }) => {
|
|
|
|
expect(commit.id).toBe(sha);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('fetches a single commit without stats', () => {
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl, { params: { stats: false } }).reply(httpStatus.OK, { id: sha });
|
2020-07-09 02:09:37 -04:00
|
|
|
|
|
|
|
return Api.commit(projectId, sha, { stats: false }).then(({ data: commit }) => {
|
|
|
|
expect(commit.id).toBe(sha);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-02 19:00:38 -04:00
|
|
|
describe('issueTemplate', () => {
|
|
|
|
it('fetches an issue template', done => {
|
|
|
|
const namespace = 'some namespace';
|
|
|
|
const project = 'some project';
|
|
|
|
const templateKey = ' template #%?.key ';
|
|
|
|
const templateType = 'template type';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}/${encodeURIComponent(
|
|
|
|
templateKey,
|
|
|
|
)}`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, 'test');
|
2017-05-19 17:22:46 -04:00
|
|
|
|
2018-10-02 19:00:38 -04:00
|
|
|
Api.issueTemplate(namespace, project, templateKey, templateType, (error, response) => {
|
2018-01-25 11:40:31 -05:00
|
|
|
expect(response).toBe('test');
|
2017-05-19 17:22:46 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-02 19:00:38 -04:00
|
|
|
describe('projectTemplates', () => {
|
|
|
|
it('fetches a list of templates', done => {
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses`;
|
2017-05-19 17:22:46 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, 'test');
|
2017-05-19 17:22:46 -04:00
|
|
|
|
2018-10-02 19:00:38 -04:00
|
|
|
Api.projectTemplates('gitlab-org/gitlab-ce', 'licenses', {}, response => {
|
2018-01-25 11:40:31 -05:00
|
|
|
expect(response).toBe('test');
|
2017-05-19 17:22:46 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-02 19:00:38 -04:00
|
|
|
describe('projectTemplate', () => {
|
|
|
|
it('fetches a single template', done => {
|
|
|
|
const data = { unused: 'option' };
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses/test%20license`;
|
2017-05-19 17:22:46 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, 'test');
|
2017-05-19 17:22:46 -04:00
|
|
|
|
2018-10-02 19:00:38 -04:00
|
|
|
Api.projectTemplate('gitlab-org/gitlab-ce', 'licenses', 'test license', data, response => {
|
2018-01-25 11:40:31 -05:00
|
|
|
expect(response).toBe('test');
|
2017-05-19 17:22:46 -04:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('users', () => {
|
2018-03-26 08:18:24 -04:00
|
|
|
it('fetches users', done => {
|
2017-05-19 17:22:46 -04:00
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users.json`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-03-26 08:18:24 -04:00
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
2017-05-19 17:22:46 -04:00
|
|
|
|
|
|
|
Api.users(query, options)
|
2018-01-25 11:40:31 -05:00
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.length).toBe(1);
|
|
|
|
expect(data[0].name).toBe('test');
|
2017-05-19 17:22:46 -04:00
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2018-05-25 06:08:53 -04:00
|
|
|
|
2018-12-07 22:12:23 -05:00
|
|
|
describe('user', () => {
|
|
|
|
it('fetches single user', done => {
|
|
|
|
const userId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users/${userId}`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, {
|
2018-12-07 22:12:23 -05:00
|
|
|
name: 'testuser',
|
|
|
|
});
|
|
|
|
|
|
|
|
Api.user(userId)
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.name).toBe('testuser');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-09 04:44:19 -04:00
|
|
|
describe('user counts', () => {
|
|
|
|
it('fetches single user counts', done => {
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/user_counts`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, {
|
2019-07-09 04:44:19 -04:00
|
|
|
merge_requests: 4,
|
|
|
|
});
|
|
|
|
|
|
|
|
Api.userCounts()
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.merge_requests).toBe(4);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-07 22:12:23 -05:00
|
|
|
describe('user status', () => {
|
|
|
|
it('fetches single user status', done => {
|
|
|
|
const userId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users/${userId}/status`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, {
|
2018-12-07 22:12:23 -05:00
|
|
|
message: 'testmessage',
|
|
|
|
});
|
|
|
|
|
|
|
|
Api.userStatus(userId)
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.message).toBe('testmessage');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-04 04:06:21 -05:00
|
|
|
describe('user projects', () => {
|
|
|
|
it('fetches all projects that belong to a particular user', done => {
|
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
|
|
|
const userId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users/${userId}/projects`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2019-11-04 04:06:21 -05:00
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
Api.userProjects(userId, query, options, response => {
|
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-25 06:08:53 -04:00
|
|
|
describe('commitPipelines', () => {
|
|
|
|
it('fetches pipelines for a given commit', done => {
|
|
|
|
const projectId = 'example/foobar';
|
|
|
|
const commitSha = 'abc123def';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/${projectId}/commit/${commitSha}/pipelines`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-05-25 06:08:53 -04:00
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
Api.commitPipelines(projectId, commitSha)
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.length).toBe(1);
|
|
|
|
expect(data[0].name).toBe('test');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2018-06-27 05:43:26 -04:00
|
|
|
|
2020-10-12 17:08:56 -04:00
|
|
|
describe('pipelineJobs', () => {
|
|
|
|
it('fetches the jobs for a given pipeline', done => {
|
|
|
|
const projectId = 123;
|
|
|
|
const pipelineId = 456;
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/pipelines/${pipelineId}/jobs`;
|
|
|
|
const payload = [
|
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, payload);
|
|
|
|
|
|
|
|
Api.pipelineJobs(projectId, pipelineId)
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data).toEqual(payload);
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-27 05:43:26 -04:00
|
|
|
describe('createBranch', () => {
|
|
|
|
it('creates new branch', done => {
|
|
|
|
const ref = 'master';
|
|
|
|
const branch = 'new-branch-name';
|
|
|
|
const dummyProjectPath = 'gitlab-org/gitlab-ce';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent(
|
|
|
|
dummyProjectPath,
|
|
|
|
)}/repository/branches`;
|
|
|
|
|
2019-05-24 14:12:03 -04:00
|
|
|
jest.spyOn(axios, 'post');
|
2018-06-27 05:43:26 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onPost(expectedUrl).replyOnce(httpStatus.OK, {
|
2018-06-27 05:43:26 -04:00
|
|
|
name: branch,
|
|
|
|
});
|
|
|
|
|
|
|
|
Api.createBranch(dummyProjectPath, { ref, branch })
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.name).toBe(branch);
|
|
|
|
expect(axios.post).toHaveBeenCalledWith(expectedUrl, { ref, branch });
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2019-06-19 06:21:48 -04:00
|
|
|
|
|
|
|
describe('projectForks', () => {
|
|
|
|
it('gets forked projects', done => {
|
|
|
|
const dummyProjectPath = 'gitlab-org/gitlab-ce';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent(
|
|
|
|
dummyProjectPath,
|
|
|
|
)}/forks`;
|
|
|
|
|
|
|
|
jest.spyOn(axios, 'get');
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, ['fork']);
|
2019-06-19 06:21:48 -04:00
|
|
|
|
|
|
|
Api.projectForks(dummyProjectPath, { visibility: 'private' })
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data).toEqual(['fork']);
|
|
|
|
expect(axios.get).toHaveBeenCalledWith(expectedUrl, {
|
|
|
|
params: { visibility: 'private' },
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2020-04-01 08:08:00 -04:00
|
|
|
|
2020-08-04 14:09:49 -04:00
|
|
|
describe('createContextCommits', () => {
|
|
|
|
it('creates a new context commit', done => {
|
|
|
|
const projectPath = 'abc';
|
|
|
|
const mergeRequestId = '123456';
|
|
|
|
const commitsData = ['abcdefg'];
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/context_commits`;
|
|
|
|
const expectedData = {
|
|
|
|
commits: commitsData,
|
|
|
|
};
|
|
|
|
|
|
|
|
jest.spyOn(axios, 'post');
|
|
|
|
|
|
|
|
mock.onPost(expectedUrl).replyOnce(200, [
|
|
|
|
{
|
|
|
|
id: 'abcdefghijklmnop',
|
|
|
|
short_id: 'abcdefg',
|
|
|
|
title: 'Dummy commit',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
Api.createContextCommits(projectPath, mergeRequestId, expectedData)
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data[0].title).toBe('Dummy commit');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('allContextCommits', () => {
|
|
|
|
it('gets all context commits', done => {
|
|
|
|
const projectPath = 'abc';
|
|
|
|
const mergeRequestId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/context_commits`;
|
|
|
|
|
|
|
|
jest.spyOn(axios, 'get');
|
|
|
|
|
|
|
|
mock
|
|
|
|
.onGet(expectedUrl)
|
|
|
|
.replyOnce(200, [{ id: 'abcdef', short_id: 'abcdefghi', title: 'Dummy commit title' }]);
|
|
|
|
|
|
|
|
Api.allContextCommits(projectPath, mergeRequestId)
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data[0].title).toBe('Dummy commit title');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removeContextCommits', () => {
|
|
|
|
it('removes context commits', done => {
|
|
|
|
const projectPath = 'abc';
|
|
|
|
const mergeRequestId = '123456';
|
|
|
|
const commitsData = ['abcdefg'];
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/context_commits`;
|
|
|
|
const expectedData = {
|
|
|
|
commits: commitsData,
|
|
|
|
};
|
|
|
|
|
|
|
|
jest.spyOn(axios, 'delete');
|
|
|
|
|
|
|
|
mock.onDelete(expectedUrl).replyOnce(204);
|
|
|
|
|
|
|
|
Api.removeContextCommits(projectPath, mergeRequestId, expectedData)
|
|
|
|
.then(() => {
|
|
|
|
expect(axios.delete).toHaveBeenCalledWith(expectedUrl, { data: expectedData });
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('release-related methods', () => {
|
2020-07-22 05:09:38 -04:00
|
|
|
const dummyProjectPath = 'gitlab-org/gitlab';
|
|
|
|
const dummyTagName = 'v1.3';
|
2020-07-23 02:09:19 -04:00
|
|
|
const baseReleaseUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent(
|
2020-07-22 05:09:38 -04:00
|
|
|
dummyProjectPath,
|
2020-07-23 02:09:19 -04:00
|
|
|
)}/releases`;
|
2020-07-22 05:09:38 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('releases', () => {
|
|
|
|
const expectedUrl = baseReleaseUrl;
|
2020-07-22 05:09:38 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('when releases are successfully returned', () => {
|
|
|
|
it('resolves the Promise', () => {
|
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK);
|
|
|
|
|
|
|
|
return Api.releases(dummyProjectPath).then(() => {
|
|
|
|
expect(mock.history.get).toHaveLength(1);
|
|
|
|
});
|
2020-07-22 05:09:38 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('when an error occurs while fetching releases', () => {
|
|
|
|
it('rejects the Promise', () => {
|
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
2020-07-22 05:09:38 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
return Api.releases(dummyProjectPath).catch(() => {
|
|
|
|
expect(mock.history.get).toHaveLength(1);
|
|
|
|
});
|
2020-07-22 05:09:38 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('release', () => {
|
|
|
|
const expectedUrl = `${baseReleaseUrl}/${encodeURIComponent(dummyTagName)}`;
|
2020-07-22 05:09:38 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('when the release is successfully returned', () => {
|
|
|
|
it('resolves the Promise', () => {
|
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK);
|
2020-07-22 05:09:38 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
return Api.release(dummyProjectPath, dummyTagName).then(() => {
|
|
|
|
expect(mock.history.get).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-07-22 05:09:38 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('when an error occurs while fetching the release', () => {
|
|
|
|
it('rejects the Promise', () => {
|
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
return Api.release(dummyProjectPath, dummyTagName).catch(() => {
|
|
|
|
expect(mock.history.get).toHaveLength(1);
|
|
|
|
});
|
2020-07-22 05:09:38 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('createRelease', () => {
|
|
|
|
const expectedUrl = baseReleaseUrl;
|
2020-07-22 05:09:38 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
const release = {
|
|
|
|
name: 'Version 1.0',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('when the release is successfully created', () => {
|
|
|
|
it('resolves the Promise', () => {
|
|
|
|
mock.onPost(expectedUrl, release).replyOnce(httpStatus.CREATED);
|
|
|
|
|
|
|
|
return Api.createRelease(dummyProjectPath, release).then(() => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when an error occurs while creating the release', () => {
|
|
|
|
it('rejects the Promise', () => {
|
|
|
|
mock.onPost(expectedUrl, release).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
return Api.createRelease(dummyProjectPath, release).catch(() => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
});
|
2020-07-22 05:09:38 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('updateRelease', () => {
|
|
|
|
const expectedUrl = `${baseReleaseUrl}/${encodeURIComponent(dummyTagName)}`;
|
2020-07-22 05:09:38 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
const release = {
|
|
|
|
name: 'Version 1.0',
|
|
|
|
};
|
2020-07-22 05:09:38 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('when the release is successfully updated', () => {
|
|
|
|
it('resolves the Promise', () => {
|
|
|
|
mock.onPut(expectedUrl, release).replyOnce(httpStatus.OK);
|
2020-07-22 05:09:38 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
return Api.updateRelease(dummyProjectPath, dummyTagName, release).then(() => {
|
|
|
|
expect(mock.history.put).toHaveLength(1);
|
|
|
|
});
|
2020-07-22 05:09:38 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('when an error occurs while updating the release', () => {
|
|
|
|
it('rejects the Promise', () => {
|
|
|
|
mock.onPut(expectedUrl, release).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
2020-07-22 05:09:38 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
return Api.updateRelease(dummyProjectPath, dummyTagName, release).catch(() => {
|
|
|
|
expect(mock.history.put).toHaveLength(1);
|
|
|
|
});
|
2020-07-22 05:09:38 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('createReleaseLink', () => {
|
|
|
|
const expectedUrl = `${baseReleaseUrl}/${dummyTagName}/assets/links`;
|
|
|
|
const expectedLink = {
|
|
|
|
url: 'https://example.com',
|
|
|
|
name: 'An example link',
|
|
|
|
};
|
2020-04-01 08:08:00 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('when the Release is successfully created', () => {
|
|
|
|
it('resolves the Promise', () => {
|
|
|
|
mock.onPost(expectedUrl, expectedLink).replyOnce(httpStatus.CREATED);
|
2020-04-01 08:08:00 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
return Api.createReleaseLink(dummyProjectPath, dummyTagName, expectedLink).then(() => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
});
|
2020-04-01 08:08:00 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('when an error occurs while creating the Release', () => {
|
|
|
|
it('rejects the Promise', () => {
|
|
|
|
mock.onPost(expectedUrl, expectedLink).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
2020-04-01 08:08:00 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
return Api.createReleaseLink(dummyProjectPath, dummyTagName, expectedLink).catch(() => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
});
|
2020-04-01 08:08:00 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('deleteReleaseLink', () => {
|
|
|
|
const dummyLinkId = '4';
|
|
|
|
const expectedUrl = `${baseReleaseUrl}/${dummyTagName}/assets/links/${dummyLinkId}`;
|
2020-04-01 08:08:00 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('when the Release is successfully deleted', () => {
|
|
|
|
it('resolves the Promise', () => {
|
|
|
|
mock.onDelete(expectedUrl).replyOnce(httpStatus.OK);
|
2020-04-01 08:08:00 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
return Api.deleteReleaseLink(dummyProjectPath, dummyTagName, dummyLinkId).then(() => {
|
|
|
|
expect(mock.history.delete).toHaveLength(1);
|
|
|
|
});
|
2020-04-01 08:08:00 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
describe('when an error occurs while deleting the Release', () => {
|
|
|
|
it('rejects the Promise', () => {
|
|
|
|
mock.onDelete(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
2020-04-01 08:08:00 -04:00
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
return Api.deleteReleaseLink(dummyProjectPath, dummyTagName, dummyLinkId).catch(() => {
|
|
|
|
expect(mock.history.delete).toHaveLength(1);
|
|
|
|
});
|
2020-04-01 08:08:00 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-04-06 11:10:04 -04:00
|
|
|
|
|
|
|
describe('getRawFile', () => {
|
|
|
|
const dummyProjectPath = 'gitlab-org/gitlab';
|
|
|
|
const dummyFilePath = 'doc/CONTRIBUTING.md';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent(
|
|
|
|
dummyProjectPath,
|
|
|
|
)}/repository/files/${encodeURIComponent(dummyFilePath)}/raw`;
|
|
|
|
|
|
|
|
describe('when the raw file is successfully fetched', () => {
|
|
|
|
it('resolves the Promise', () => {
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK);
|
2020-04-06 11:10:04 -04:00
|
|
|
|
|
|
|
return Api.getRawFile(dummyProjectPath, dummyFilePath).then(() => {
|
|
|
|
expect(mock.history.get).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when an error occurs while getting a raw file', () => {
|
|
|
|
it('rejects the Promise', () => {
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onPost(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
2020-04-06 11:10:04 -04:00
|
|
|
|
|
|
|
return Api.getRawFile(dummyProjectPath, dummyFilePath).catch(() => {
|
|
|
|
expect(mock.history.get).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-04-14 05:09:34 -04:00
|
|
|
|
|
|
|
describe('createProjectMergeRequest', () => {
|
|
|
|
const dummyProjectPath = 'gitlab-org/gitlab';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent(
|
|
|
|
dummyProjectPath,
|
|
|
|
)}/merge_requests`;
|
|
|
|
const options = {
|
|
|
|
source_branch: 'feature',
|
|
|
|
target_branch: 'master',
|
|
|
|
title: 'Add feature',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('when the merge request is successfully created', () => {
|
|
|
|
it('resolves the Promise', () => {
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onPost(expectedUrl, options).replyOnce(httpStatus.CREATED);
|
2020-04-14 05:09:34 -04:00
|
|
|
|
|
|
|
return Api.createProjectMergeRequest(dummyProjectPath, options).then(() => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when an error occurs while getting a raw file', () => {
|
|
|
|
it('rejects the Promise', () => {
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onPost(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
2020-04-14 05:09:34 -04:00
|
|
|
|
|
|
|
return Api.createProjectMergeRequest(dummyProjectPath).catch(() => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-06-02 17:08:00 -04:00
|
|
|
|
|
|
|
describe('updateIssue', () => {
|
|
|
|
it('update an issue with the given payload', done => {
|
|
|
|
const projectId = 8;
|
|
|
|
const issue = 1;
|
|
|
|
const expectedArray = [1, 2, 3];
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/issues/${issue}`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onPut(expectedUrl).reply(httpStatus.OK, { assigneeIds: expectedArray });
|
2020-06-02 17:08:00 -04:00
|
|
|
|
|
|
|
Api.updateIssue(projectId, issue, { assigneeIds: expectedArray })
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.assigneeIds).toEqual(expectedArray);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateMergeRequest', () => {
|
|
|
|
it('update an issue with the given payload', done => {
|
|
|
|
const projectId = 8;
|
|
|
|
const mergeRequest = 1;
|
|
|
|
const expectedArray = [1, 2, 3];
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/merge_requests/${mergeRequest}`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onPut(expectedUrl).reply(httpStatus.OK, { assigneeIds: expectedArray });
|
2020-06-02 17:08:00 -04:00
|
|
|
|
|
|
|
Api.updateMergeRequest(projectId, mergeRequest, { assigneeIds: expectedArray })
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.assigneeIds).toEqual(expectedArray);
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2020-06-11 05:08:16 -04:00
|
|
|
|
|
|
|
describe('tags', () => {
|
|
|
|
it('fetches all tags of a particular project', done => {
|
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
|
|
|
const projectId = 8;
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/repository/tags`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2020-06-11 05:08:16 -04:00
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
Api.tags(projectId, query, options)
|
|
|
|
.then(({ data }) => {
|
|
|
|
expect(data.length).toBe(1);
|
|
|
|
expect(data[0].name).toBe('test');
|
|
|
|
})
|
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2020-07-17 14:09:20 -04:00
|
|
|
|
|
|
|
describe('freezePeriods', () => {
|
|
|
|
it('fetches freezePeriods', () => {
|
|
|
|
const projectId = 8;
|
|
|
|
const freezePeriod = {
|
|
|
|
id: 3,
|
|
|
|
freeze_start: '5 4 * * *',
|
|
|
|
freeze_end: '5 9 * 8 *',
|
|
|
|
cron_timezone: 'America/New_York',
|
|
|
|
created_at: '2020-07-10T05:10:35.122Z',
|
|
|
|
updated_at: '2020-07-10T05:10:35.122Z',
|
|
|
|
};
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/freeze_periods`;
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [freezePeriod]);
|
2020-07-17 14:09:20 -04:00
|
|
|
|
|
|
|
return Api.freezePeriods(projectId).then(({ data }) => {
|
|
|
|
expect(data[0]).toStrictEqual(freezePeriod);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('createFreezePeriod', () => {
|
|
|
|
const projectId = 8;
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/freeze_periods`;
|
|
|
|
const options = {
|
|
|
|
freeze_start: '* * * * *',
|
|
|
|
freeze_end: '* * * * *',
|
|
|
|
cron_timezone: 'America/Juneau',
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectedResult = {
|
|
|
|
id: 10,
|
|
|
|
freeze_start: '* * * * *',
|
|
|
|
freeze_end: '* * * * *',
|
|
|
|
cron_timezone: 'America/Juneau',
|
|
|
|
created_at: '2020-07-11T07:04:50.153Z',
|
|
|
|
updated_at: '2020-07-11T07:04:50.153Z',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('when the freeze period is successfully created', () => {
|
|
|
|
it('resolves the Promise', () => {
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onPost(expectedUrl, options).replyOnce(httpStatus.CREATED, expectedResult);
|
2020-07-17 14:09:20 -04:00
|
|
|
|
|
|
|
return Api.createFreezePeriod(projectId, options).then(({ data }) => {
|
|
|
|
expect(data).toStrictEqual(expectedResult);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-07-20 17:09:23 -04:00
|
|
|
|
|
|
|
describe('createPipeline', () => {
|
|
|
|
it('creates new pipeline', () => {
|
|
|
|
const redirectUrl = 'ci-project/-/pipelines/95';
|
|
|
|
const projectId = 8;
|
|
|
|
const postData = {
|
|
|
|
ref: 'tag-1',
|
|
|
|
variables: [
|
|
|
|
{ key: 'test_file', value: 'test_file_val', variable_type: 'file' },
|
|
|
|
{ key: 'test_var', value: 'test_var_val', variable_type: 'env_var' },
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/pipeline`;
|
|
|
|
|
|
|
|
jest.spyOn(axios, 'post');
|
|
|
|
|
2020-07-23 02:09:19 -04:00
|
|
|
mock.onPost(expectedUrl).replyOnce(httpStatus.OK, {
|
2020-07-20 17:09:23 -04:00
|
|
|
web_url: redirectUrl,
|
|
|
|
});
|
|
|
|
|
|
|
|
return Api.createPipeline(projectId, postData).then(({ data }) => {
|
|
|
|
expect(data.web_url).toBe(redirectUrl);
|
|
|
|
expect(axios.post).toHaveBeenCalledWith(expectedUrl, postData, {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-09-24 08:09:37 -04:00
|
|
|
|
|
|
|
describe('trackRedisHllUserEvent', () => {
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/usage_data/increment_unique_users`;
|
|
|
|
|
|
|
|
const event = 'dummy_event';
|
|
|
|
const postData = { event };
|
|
|
|
const headers = {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('when usage data increment unique users is called with feature flag disabled', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
gon.features = { ...gon.features, usageDataApi: false };
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns null', () => {
|
|
|
|
jest.spyOn(axios, 'post');
|
|
|
|
mock.onPost(expectedUrl).replyOnce(httpStatus.OK, true);
|
|
|
|
|
|
|
|
expect(axios.post).toHaveBeenCalledTimes(0);
|
|
|
|
expect(Api.trackRedisHllUserEvent(event)).toEqual(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when usage data increment unique users is called', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
gon.features = { ...gon.features, usageDataApi: true };
|
|
|
|
});
|
|
|
|
|
|
|
|
it('resolves the Promise', () => {
|
|
|
|
jest.spyOn(axios, 'post');
|
|
|
|
mock.onPost(expectedUrl, { event }).replyOnce(httpStatus.OK, true);
|
|
|
|
|
|
|
|
return Api.trackRedisHllUserEvent(event).then(({ data }) => {
|
|
|
|
expect(data).toEqual(true);
|
|
|
|
expect(axios.post).toHaveBeenCalledWith(expectedUrl, postData, { headers });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-05-19 17:22:46 -04:00
|
|
|
});
|