2018-03-17 18:26:18 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2022-01-26 12:08:38 +05:30
|
|
|
import Api, { DEFAULT_PER_PAGE } from '~/api';
|
2021-03-11 19:13:27 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-10-24 23:57:45 +05:30
|
|
|
import httpStatus from '~/lib/utils/http_status';
|
2022-06-21 17:19:12 +05:30
|
|
|
import createFlash from '~/flash';
|
|
|
|
|
|
|
|
jest.mock('~/flash');
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
describe('Api', () => {
|
|
|
|
const dummyApiVersion = 'v3000';
|
2019-07-31 22:56:46 +05:30
|
|
|
const dummyUrlRoot = '/gitlab';
|
2017-09-10 17:25:29 +05:30
|
|
|
const dummyGon = {
|
|
|
|
api_version: dummyApiVersion,
|
|
|
|
relative_url_root: dummyUrlRoot,
|
|
|
|
};
|
|
|
|
let originalGon;
|
2018-03-17 18:26:18 +05:30
|
|
|
let mock;
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
mock = new MockAdapter(axios);
|
2017-09-10 17:25:29 +05:30
|
|
|
originalGon = window.gon;
|
2020-05-24 23:13:21 +05:30
|
|
|
window.gon = { ...dummyGon };
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-03-17 18:26:18 +05:30
|
|
|
mock.restore();
|
2017-09-10 17:25:29 +05:30
|
|
|
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-07-31 22:56:46 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
[null, '', '/'].forEach((root) => {
|
2019-07-31 22:56:46 +05:30
|
|
|
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-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
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-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, apiResponse);
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
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-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, apiResponse);
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
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-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, apiResponse);
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
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-10-24 23:57:45 +05:30
|
|
|
mock.onDelete(expectedUrl).replyOnce(httpStatus.OK, true);
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
return Api.deleteProjectPackage(projectId, packageId).then(({ data }) => {
|
|
|
|
expect(data).toEqual(true);
|
|
|
|
expect(axios.delete).toHaveBeenCalledWith(expectedUrl);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
describe('deleteProjectPackageFile', () => {
|
|
|
|
const packageFileId = 'package_file_id';
|
|
|
|
|
|
|
|
it('delete a package', () => {
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/packages/${packageId}/package_files/${packageFileId}`;
|
|
|
|
|
|
|
|
jest.spyOn(axios, 'delete');
|
|
|
|
mock.onDelete(expectedUrl).replyOnce(httpStatus.OK, true);
|
|
|
|
|
|
|
|
return Api.deleteProjectPackageFile(projectId, packageId, packageFileId).then(
|
|
|
|
({ data }) => {
|
|
|
|
expect(data).toEqual(true);
|
|
|
|
expect(axios.delete).toHaveBeenCalledWith(expectedUrl);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2020-07-28 23:09:34 +05:30
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('container registry', () => {
|
|
|
|
describe('containerRegistryDetails', () => {
|
|
|
|
it('fetch container registry details', async () => {
|
|
|
|
const expectedUrl = `foo`;
|
|
|
|
const apiResponse = {};
|
|
|
|
|
|
|
|
jest.spyOn(axios, 'get');
|
|
|
|
jest.spyOn(Api, 'buildUrl').mockReturnValueOnce(expectedUrl);
|
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, apiResponse);
|
|
|
|
|
|
|
|
const { data } = await Api.containerRegistryDetails(1);
|
|
|
|
|
|
|
|
expect(data).toEqual(apiResponse);
|
|
|
|
expect(axios.get).toHaveBeenCalledWith(expectedUrl, {});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe('group', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches a group', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
const groupId = '123456';
|
2018-03-17 18:26:18 +05:30
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, {
|
2018-03-17 18:26:18 +05:30
|
|
|
name: 'test',
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.group(groupId, (response) => {
|
|
|
|
expect(response.name).toBe('test');
|
|
|
|
resolve();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
describe('groupMembers', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches group members', () => {
|
2019-03-02 22:35:43 +05:30
|
|
|
const groupId = '54321';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/members`;
|
|
|
|
const expectedData = [{ id: 7 }];
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, expectedData);
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.groupMembers(groupId).then(({ data }) => {
|
|
|
|
expect(data).toEqual(expectedData);
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
describe('inviteGroupMembers', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
it('invites a new email address to create a new User and become a Group Member', () => {
|
|
|
|
const groupId = 1;
|
|
|
|
const email = 'email@example.com';
|
2022-06-21 17:19:12 +05:30
|
|
|
const userId = '1';
|
2021-03-08 18:12:59 +05:30
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/1/invitations`;
|
|
|
|
const params = {
|
|
|
|
email,
|
2022-06-21 17:19:12 +05:30
|
|
|
userId,
|
2021-03-08 18:12:59 +05:30
|
|
|
access_level: 10,
|
|
|
|
expires_at: undefined,
|
|
|
|
};
|
|
|
|
|
|
|
|
mock.onPost(expectedUrl).reply(200, {
|
|
|
|
status: 'success',
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.inviteGroupMembers(groupId, params).then(({ data }) => {
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(data.status).toBe('success');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('groupMilestones', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches group milestones', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
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);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.groupMilestones(groupId).then(({ data }) => {
|
|
|
|
expect(data).toEqual(expectedData);
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe('groups', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches groups', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups.json`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-05-09 12:01:36 +05:30
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.groups(query, options, (response) => {
|
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
|
|
|
resolve();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
describe('groupLabels', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches group labels', () => {
|
2021-03-11 19:13:27 +05:30
|
|
|
const options = { params: { search: 'foo' } };
|
|
|
|
const expectedGroup = 'gitlab-org';
|
2021-04-29 21:17:54 +05:30
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${expectedGroup}/labels`;
|
2021-03-11 19:13:27 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
|
|
|
{
|
|
|
|
id: 1,
|
2021-04-29 21:17:54 +05:30
|
|
|
name: 'Foo Label',
|
2021-03-11 19:13:27 +05:30
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.groupLabels(expectedGroup, options).then((res) => {
|
|
|
|
expect(res.length).toBe(1);
|
|
|
|
expect(res[0].name).toBe('Foo Label');
|
|
|
|
});
|
2021-03-11 19:13:27 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe('namespaces', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches namespaces', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
const query = 'dummy query';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/namespaces.json`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-05-09 12:01:36 +05:30
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.namespaces(query, (response) => {
|
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
|
|
|
resolve();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('projects', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches projects with membership when logged in', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
2018-03-17 18:26:18 +05:30
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects.json`;
|
|
|
|
window.gon.current_user_id = 1;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-05-09 12:01:36 +05:30
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.projects(query, options, (response) => {
|
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
|
|
|
resolve();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches projects without membership when not logged in', () => {
|
2018-03-17 18:26:18 +05:30
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects.json`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-05-09 12:01:36 +05:30
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.projects(query, options, (response) => {
|
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
|
|
|
resolve();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe('updateProject', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('update a project with the given payload', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
const projectPath = 'foo';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onPut(expectedUrl).reply(httpStatus.OK, { foo: 'bar' });
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.updateProject(projectPath, { foo: 'bar' }).then(({ data }) => {
|
|
|
|
expect(data.foo).toBe('bar');
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
describe('projectUsers', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches all users of a particular project', () => {
|
2019-12-04 20:38:33 +05:30
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
|
|
|
const projectPath = 'gitlab-org%2Fgitlab-ce';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/users`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2019-12-04 20:38:33 +05:30
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.projectUsers('gitlab-org/gitlab-ce', query, options).then((response) => {
|
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
|
|
|
});
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe('projectMergeRequests', () => {
|
|
|
|
const projectPath = 'abc';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests`;
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches all merge requests for a project', () => {
|
2019-07-07 11:18:12 +05:30
|
|
|
const mockData = [{ source_branch: 'foo' }, { source_branch: 'bar' }];
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, mockData);
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.projectMergeRequests(projectPath).then(({ data }) => {
|
|
|
|
expect(data.length).toEqual(2);
|
|
|
|
expect(data[0].source_branch).toBe('foo');
|
|
|
|
expect(data[1].source_branch).toBe('bar');
|
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches merge requests filtered with passed params', () => {
|
2019-07-07 11:18:12 +05:30
|
|
|
const params = {
|
|
|
|
source_branch: 'bar',
|
|
|
|
};
|
|
|
|
const mockData = [{ source_branch: 'bar' }];
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl, { params }).reply(httpStatus.OK, mockData);
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.projectMergeRequests(projectPath, params).then(({ data }) => {
|
|
|
|
expect(data.length).toEqual(1);
|
|
|
|
expect(data[0].source_branch).toBe('bar');
|
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
describe('projectMergeRequest', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches a merge request', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
const projectPath = 'abc';
|
|
|
|
const mergeRequestId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, {
|
2018-05-09 12:01:36 +05:30
|
|
|
title: 'test',
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.projectMergeRequest(projectPath, mergeRequestId).then(({ data }) => {
|
|
|
|
expect(data.title).toBe('test');
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
describe('projectMergeRequestChanges', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches the changes of a merge request', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
const projectPath = 'abc';
|
|
|
|
const mergeRequestId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/changes`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, {
|
2018-05-09 12:01:36 +05:30
|
|
|
title: 'test',
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.projectMergeRequestChanges(projectPath, mergeRequestId).then(({ data }) => {
|
|
|
|
expect(data.title).toBe('test');
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
describe('projectMergeRequestVersions', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches the versions of a merge request', () => {
|
2018-05-09 12:01:36 +05:30
|
|
|
const projectPath = 'abc';
|
|
|
|
const mergeRequestId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/merge_requests/${mergeRequestId}/versions`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-05-09 12:01:36 +05:30
|
|
|
{
|
|
|
|
id: 123,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.projectMergeRequestVersions(projectPath, mergeRequestId).then(({ data }) => {
|
|
|
|
expect(data.length).toBe(1);
|
|
|
|
expect(data[0].id).toBe(123);
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
describe('projectRunners', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches the runners of a project', () => {
|
2019-02-15 15:39:39 +05:30
|
|
|
const projectPath = 7;
|
|
|
|
const params = { scope: 'active' };
|
|
|
|
const mockData = [{ id: 4 }];
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectPath}/runners`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl, { params }).reply(httpStatus.OK, mockData);
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.projectRunners(projectPath, { params }).then(({ data }) => {
|
|
|
|
expect(data).toEqual(mockData);
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('projectShareWithGroup', () => {
|
|
|
|
it('invites a group to share access with the authenticated project', () => {
|
|
|
|
const projectId = 1;
|
|
|
|
const sharedGroupId = 99;
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/share`;
|
|
|
|
const options = {
|
|
|
|
group_id: sharedGroupId,
|
|
|
|
group_access: 10,
|
|
|
|
expires_at: undefined,
|
|
|
|
};
|
|
|
|
|
|
|
|
jest.spyOn(axios, 'post');
|
|
|
|
|
|
|
|
mock.onPost(expectedUrl).reply(200, {
|
|
|
|
status: 'success',
|
|
|
|
});
|
|
|
|
|
|
|
|
return Api.projectShareWithGroup(projectId, options).then(({ data }) => {
|
|
|
|
expect(data.status).toBe('success');
|
|
|
|
expect(axios.post).toHaveBeenCalledWith(expectedUrl, options);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
describe('projectMilestones', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches project milestones', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
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',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.projectMilestones(projectId, options).then(({ data }) => {
|
|
|
|
expect(data.length).toBe(1);
|
|
|
|
expect(data[0].title).toBe('milestone1');
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
describe('inviteProjectMembers', () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
it('invites a new email address to create a new User and become a Project Member', () => {
|
|
|
|
const projectId = 1;
|
2022-06-21 17:19:12 +05:30
|
|
|
const email = 'email@example.com';
|
|
|
|
const userId = '1';
|
2021-03-08 18:12:59 +05:30
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/1/invitations`;
|
|
|
|
const params = {
|
2022-06-21 17:19:12 +05:30
|
|
|
email,
|
|
|
|
userId,
|
2021-03-08 18:12:59 +05:30
|
|
|
access_level: 10,
|
|
|
|
expires_at: undefined,
|
|
|
|
};
|
|
|
|
|
|
|
|
mock.onPost(expectedUrl).reply(200, {
|
|
|
|
status: 'success',
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.inviteProjectMembers(projectId, params).then(({ data }) => {
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(data.status).toBe('success');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe('newLabel', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('creates a new project label', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
const namespace = 'some namespace';
|
|
|
|
const project = 'some project';
|
|
|
|
const labelData = { some: 'data' };
|
2019-09-04 21:01:54 +05:30
|
|
|
const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/-/labels`;
|
2017-09-10 17:25:29 +05:30
|
|
|
const expectedData = {
|
|
|
|
label: labelData,
|
|
|
|
};
|
2021-03-08 18:12:59 +05:30
|
|
|
mock.onPost(expectedUrl).reply((config) => {
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(config.data).toBe(JSON.stringify(expectedData));
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
return [
|
2020-10-24 23:57:45 +05:30
|
|
|
httpStatus.OK,
|
2018-05-09 12:01:36 +05:30
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
];
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.newLabel(namespace, project, labelData, (response) => {
|
|
|
|
expect(response.name).toBe('test');
|
|
|
|
resolve();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('creates a new group label', () => {
|
2018-03-27 19:54:05 +05:30
|
|
|
const namespace = 'group/subgroup';
|
2021-04-29 21:17:54 +05:30
|
|
|
const labelData = { name: 'Foo', color: '#000000' };
|
2019-09-04 21:01:54 +05:30
|
|
|
const expectedUrl = Api.buildUrl(Api.groupLabelsPath).replace(':namespace_path', namespace);
|
2021-03-08 18:12:59 +05:30
|
|
|
mock.onPost(expectedUrl).reply((config) => {
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(config.data).toBe(JSON.stringify({ color: labelData.color }));
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
return [
|
2020-10-24 23:57:45 +05:30
|
|
|
httpStatus.OK,
|
2018-05-09 12:01:36 +05:30
|
|
|
{
|
2021-04-29 21:17:54 +05:30
|
|
|
...labelData,
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
];
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.newLabel(namespace, undefined, labelData, (response) => {
|
|
|
|
expect(response.name).toBe('Foo');
|
|
|
|
resolve();
|
|
|
|
});
|
2018-03-27 19:54:05 +05:30
|
|
|
});
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('groupProjects', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches group projects', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
const groupId = '123456';
|
|
|
|
const query = 'dummy query';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/projects.json`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-05-09 12:01:36 +05:30
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.groupProjects(groupId, query, {}, (response) => {
|
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uses flesh on error by default', async () => {
|
|
|
|
const groupId = '123456';
|
|
|
|
const query = 'dummy query';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/projects.json`;
|
|
|
|
const flashCallback = (callCount) => {
|
|
|
|
expect(createFlash).toHaveBeenCalledTimes(callCount);
|
|
|
|
createFlash.mockClear();
|
|
|
|
};
|
|
|
|
|
|
|
|
mock.onGet(expectedUrl).reply(500, null);
|
|
|
|
|
|
|
|
const response = await Api.groupProjects(groupId, query, {}, () => {}).then(() => {
|
|
|
|
flashCallback(1);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(response).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('NOT uses flesh on error with param useCustomErrorHandler', async () => {
|
|
|
|
const groupId = '123456';
|
|
|
|
const query = 'dummy query';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/projects.json`;
|
|
|
|
|
|
|
|
mock.onGet(expectedUrl).reply(500, null);
|
|
|
|
const apiCall = Api.groupProjects(groupId, query, {}, () => {}, true);
|
|
|
|
await expect(apiCall).rejects.toThrow();
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('groupShareWithGroup', () => {
|
|
|
|
it('invites a group to share access with the authenticated group', () => {
|
|
|
|
const groupId = 1;
|
|
|
|
const sharedGroupId = 99;
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/share`;
|
|
|
|
const options = {
|
|
|
|
group_id: sharedGroupId,
|
|
|
|
group_access: 10,
|
|
|
|
expires_at: undefined,
|
|
|
|
};
|
|
|
|
|
|
|
|
jest.spyOn(axios, 'post');
|
|
|
|
|
|
|
|
mock.onPost(expectedUrl).reply(200, {
|
|
|
|
status: 'success',
|
|
|
|
});
|
|
|
|
|
|
|
|
return Api.groupShareWithGroup(groupId, options).then(({ data }) => {
|
|
|
|
expect(data.status).toBe('success');
|
|
|
|
expect(axios.post).toHaveBeenCalledWith(expectedUrl, options);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
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-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, { id: sha });
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
return Api.commit(projectId, sha).then(({ data: commit }) => {
|
|
|
|
expect(commit.id).toBe(sha);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('fetches a single commit without stats', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl, { params: { stats: false } }).reply(httpStatus.OK, { id: sha });
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
return Api.commit(projectId, sha, { stats: false }).then(({ data: commit }) => {
|
|
|
|
expect(commit.id).toBe(sha);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
describe('issueTemplate', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
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,
|
|
|
|
)}`;
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches an issue template', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, 'test');
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.issueTemplate(namespace, project, templateKey, templateType, (_, response) => {
|
|
|
|
expect(response).toBe('test');
|
|
|
|
resolve();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
describe('when an error occurs while fetching an issue template', () => {
|
|
|
|
it('rejects the Promise', () => {
|
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.issueTemplate(namespace, project, templateKey, templateType, () => {
|
|
|
|
expect(mock.history.get).toHaveLength(1);
|
|
|
|
resolve();
|
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('issueTemplates', () => {
|
|
|
|
const namespace = 'some namespace';
|
|
|
|
const project = 'some project';
|
|
|
|
const templateType = 'template type';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/${namespace}/${project}/templates/${templateType}`;
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches all templates by type', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
const expectedData = [
|
|
|
|
{ key: 'Template1', name: 'Template 1', content: 'This is template 1!' },
|
|
|
|
];
|
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, expectedData);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.issueTemplates(namespace, project, templateType, (_, response) => {
|
|
|
|
expect(response.length).toBe(1);
|
|
|
|
const { key, name, content } = response[0];
|
|
|
|
expect(key).toBe('Template1');
|
|
|
|
expect(name).toBe('Template 1');
|
|
|
|
expect(content).toBe('This is template 1!');
|
|
|
|
resolve();
|
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when an error occurs while fetching issue templates', () => {
|
|
|
|
it('rejects the Promise', () => {
|
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
Api.issueTemplates(namespace, project, templateType, () => {
|
|
|
|
expect(mock.history.get).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
describe('projectTemplates', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches a list of templates', () => {
|
2018-12-05 23:21:45 +05:30
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses`;
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, 'test');
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.projectTemplates('gitlab-org/gitlab-ce', 'licenses', {}, (response) => {
|
|
|
|
expect(response).toBe('test');
|
|
|
|
resolve();
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
describe('projectTemplate', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches a single template', () => {
|
2018-12-05 23:21:45 +05:30
|
|
|
const data = { unused: 'option' };
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/gitlab-org%2Fgitlab-ce/templates/licenses/test%20license`;
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, 'test');
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.projectTemplate(
|
|
|
|
'gitlab-org/gitlab-ce',
|
|
|
|
'licenses',
|
|
|
|
'test license',
|
|
|
|
data,
|
|
|
|
(response) => {
|
|
|
|
expect(response).toBe('test');
|
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
);
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('users', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches users', () => {
|
2017-09-10 17:25:29 +05:30
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users.json`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-05-09 12:01:36 +05:30
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.users(query, options).then(({ data }) => {
|
|
|
|
expect(data.length).toBe(1);
|
|
|
|
expect(data[0].name).toBe('test');
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
describe('user', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches single user', () => {
|
2019-02-15 15:39:39 +05:30
|
|
|
const userId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users/${userId}`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, {
|
2019-02-15 15:39:39 +05:30
|
|
|
name: 'testuser',
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.user(userId).then(({ data }) => {
|
|
|
|
expect(data.name).toBe('testuser');
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe('user counts', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches single user counts', () => {
|
2019-09-30 21:07:59 +05:30
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/user_counts`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, {
|
2019-09-30 21:07:59 +05:30
|
|
|
merge_requests: 4,
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.userCounts().then(({ data }) => {
|
|
|
|
expect(data.merge_requests).toBe(4);
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
describe('user status', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches single user status', () => {
|
2019-02-15 15:39:39 +05:30
|
|
|
const userId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users/${userId}/status`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, {
|
2019-02-15 15:39:39 +05:30
|
|
|
message: 'testmessage',
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.userStatus(userId).then(({ data }) => {
|
|
|
|
expect(data.message).toBe('testmessage');
|
|
|
|
});
|
2019-02-15 15:39:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
describe('user projects', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches all projects that belong to a particular user', () => {
|
2019-12-26 22:10:19 +05:30
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
|
|
|
const userId = '123456';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/users/${userId}/projects`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2019-12-26 22:10:19 +05:30
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return new Promise((resolve) => {
|
|
|
|
Api.userProjects(userId, query, options, (response) => {
|
|
|
|
expect(response.length).toBe(1);
|
|
|
|
expect(response[0].name).toBe('test');
|
|
|
|
resolve();
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('commitPipelines', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches pipelines for a given commit', () => {
|
2018-11-08 19:23:39 +05:30
|
|
|
const projectId = 'example/foobar';
|
|
|
|
const commitSha = 'abc123def';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/${projectId}/commit/${commitSha}/pipelines`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2018-11-08 19:23:39 +05:30
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.commitPipelines(projectId, commitSha).then(({ data }) => {
|
|
|
|
expect(data.length).toBe(1);
|
|
|
|
expect(data[0].name).toBe('test');
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
describe('pipelineJobs', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
it.each([undefined, {}, { foo: true }])(
|
|
|
|
'fetches the jobs for a given pipeline given %p params',
|
2021-03-08 18:12:59 +05:30
|
|
|
async (params) => {
|
2021-01-29 00:20:46 +05:30
|
|
|
const projectId = 123;
|
|
|
|
const pipelineId = 456;
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/pipelines/${pipelineId}/jobs`;
|
|
|
|
const payload = [
|
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
mock.onGet(expectedUrl, { params }).reply(httpStatus.OK, payload);
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
const { data } = await Api.pipelineJobs(projectId, pipelineId, params);
|
|
|
|
expect(data).toEqual(payload);
|
|
|
|
},
|
|
|
|
);
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
describe('createBranch', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('creates new branch', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
const ref = 'main';
|
2018-11-08 19:23:39 +05:30
|
|
|
const branch = 'new-branch-name';
|
|
|
|
const dummyProjectPath = 'gitlab-org/gitlab-ce';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent(
|
|
|
|
dummyProjectPath,
|
|
|
|
)}/repository/branches`;
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
jest.spyOn(axios, 'post');
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onPost(expectedUrl).replyOnce(httpStatus.OK, {
|
2018-11-08 19:23:39 +05:30
|
|
|
name: branch,
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.createBranch(dummyProjectPath, { ref, branch }).then(({ data }) => {
|
|
|
|
expect(data.name).toBe(branch);
|
|
|
|
expect(axios.post).toHaveBeenCalledWith(expectedUrl, { ref, branch });
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
describe('projectForks', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('gets forked projects', () => {
|
2019-09-30 21:07:59 +05:30
|
|
|
const dummyProjectPath = 'gitlab-org/gitlab-ce';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent(
|
|
|
|
dummyProjectPath,
|
|
|
|
)}/forks`;
|
|
|
|
|
|
|
|
jest.spyOn(axios, 'get');
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, ['fork']);
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.projectForks(dummyProjectPath, { visibility: 'private' }).then(({ data }) => {
|
|
|
|
expect(data).toEqual(['fork']);
|
|
|
|
expect(axios.get).toHaveBeenCalledWith(expectedUrl, {
|
|
|
|
params: { visibility: 'private' },
|
|
|
|
});
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('createContextCommits', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('creates a new context commit', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
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',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.createContextCommits(projectPath, mergeRequestId, expectedData).then(
|
|
|
|
({ data }) => {
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(data[0].title).toBe('Dummy commit');
|
2022-06-21 17:19:12 +05:30
|
|
|
},
|
|
|
|
);
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('allContextCommits', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('gets all context commits', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
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' }]);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.allContextCommits(projectPath, mergeRequestId).then(({ data }) => {
|
|
|
|
expect(data[0].title).toBe('Dummy commit title');
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removeContextCommits', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('removes context commits', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
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);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.removeContextCommits(projectPath, mergeRequestId, expectedData).then(() => {
|
|
|
|
expect(axios.delete).toHaveBeenCalledWith(expectedUrl, { data: expectedData });
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('release-related methods', () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
const dummyProjectPath = 'gitlab-org/gitlab';
|
2020-10-24 23:57:45 +05:30
|
|
|
const dummyTagName = 'v1.3';
|
|
|
|
const baseReleaseUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent(
|
2020-04-22 19:07:51 +05:30
|
|
|
dummyProjectPath,
|
2020-10-24 23:57:45 +05:30
|
|
|
)}/releases`;
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('releases', () => {
|
|
|
|
const expectedUrl = baseReleaseUrl;
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when an error occurs while fetching releases', () => {
|
|
|
|
it('rejects the Promise', () => {
|
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
return Api.releases(dummyProjectPath).catch(() => {
|
|
|
|
expect(mock.history.get).toHaveLength(1);
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('release', () => {
|
|
|
|
const expectedUrl = `${baseReleaseUrl}/${encodeURIComponent(dummyTagName)}`;
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('when the release is successfully returned', () => {
|
|
|
|
it('resolves the Promise', () => {
|
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK);
|
|
|
|
|
|
|
|
return Api.release(dummyProjectPath, dummyTagName).then(() => {
|
|
|
|
expect(mock.history.get).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('createRelease', () => {
|
|
|
|
const expectedUrl = baseReleaseUrl;
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
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-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('updateRelease', () => {
|
|
|
|
const expectedUrl = `${baseReleaseUrl}/${encodeURIComponent(dummyTagName)}`;
|
|
|
|
|
|
|
|
const release = {
|
|
|
|
name: 'Version 1.0',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('when the release is successfully updated', () => {
|
|
|
|
it('resolves the Promise', () => {
|
|
|
|
mock.onPut(expectedUrl, release).replyOnce(httpStatus.OK);
|
|
|
|
|
|
|
|
return Api.updateRelease(dummyProjectPath, dummyTagName, release).then(() => {
|
|
|
|
expect(mock.history.put).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
describe('when an error occurs while updating the release', () => {
|
|
|
|
it('rejects the Promise', () => {
|
|
|
|
mock.onPut(expectedUrl, release).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
return Api.updateRelease(dummyProjectPath, dummyTagName, release).catch(() => {
|
|
|
|
expect(mock.history.put).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('createReleaseLink', () => {
|
|
|
|
const expectedUrl = `${baseReleaseUrl}/${dummyTagName}/assets/links`;
|
|
|
|
const expectedLink = {
|
|
|
|
url: 'https://example.com',
|
|
|
|
name: 'An example link',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('when the Release is successfully created', () => {
|
|
|
|
it('resolves the Promise', () => {
|
|
|
|
mock.onPost(expectedUrl, expectedLink).replyOnce(httpStatus.CREATED);
|
|
|
|
|
|
|
|
return Api.createReleaseLink(dummyProjectPath, dummyTagName, expectedLink).then(() => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when an error occurs while creating the Release', () => {
|
|
|
|
it('rejects the Promise', () => {
|
|
|
|
mock.onPost(expectedUrl, expectedLink).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
return Api.createReleaseLink(dummyProjectPath, dummyTagName, expectedLink).catch(() => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deleteReleaseLink', () => {
|
|
|
|
const dummyLinkId = '4';
|
|
|
|
const expectedUrl = `${baseReleaseUrl}/${dummyTagName}/assets/links/${dummyLinkId}`;
|
|
|
|
|
|
|
|
describe('when the Release is successfully deleted', () => {
|
|
|
|
it('resolves the Promise', () => {
|
|
|
|
mock.onDelete(expectedUrl).replyOnce(httpStatus.OK);
|
|
|
|
|
|
|
|
return Api.deleteReleaseLink(dummyProjectPath, dummyTagName, dummyLinkId).then(() => {
|
|
|
|
expect(mock.history.delete).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when an error occurs while deleting the Release', () => {
|
|
|
|
it('rejects the Promise', () => {
|
|
|
|
mock.onDelete(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
return Api.deleteReleaseLink(dummyProjectPath, dummyTagName, dummyLinkId).catch(() => {
|
|
|
|
expect(mock.history.delete).toHaveLength(1);
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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', () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
beforeEach(() => {
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it('resolves the Promise', () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
return Api.getRawFile(dummyProjectPath, dummyFilePath).then(() => {
|
|
|
|
expect(mock.history.get).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
describe('when the method is called with params', () => {
|
|
|
|
it('sets the params on the request', () => {
|
|
|
|
const params = { ref: 'main' };
|
|
|
|
jest.spyOn(axios, 'get');
|
|
|
|
|
|
|
|
Api.getRawFile(dummyProjectPath, dummyFilePath, params);
|
|
|
|
|
|
|
|
expect(axios.get).toHaveBeenCalledWith(expectedUrl, { params });
|
|
|
|
});
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('when an error occurs while getting a raw file', () => {
|
|
|
|
it('rejects the Promise', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onPost(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
return Api.getRawFile(dummyProjectPath, dummyFilePath).catch(() => {
|
|
|
|
expect(mock.history.get).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('createProjectMergeRequest', () => {
|
|
|
|
const dummyProjectPath = 'gitlab-org/gitlab';
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${encodeURIComponent(
|
|
|
|
dummyProjectPath,
|
|
|
|
)}/merge_requests`;
|
|
|
|
const options = {
|
|
|
|
source_branch: 'feature',
|
2021-06-08 01:23:25 +05:30
|
|
|
target_branch: 'main',
|
2020-04-22 19:07:51 +05:30
|
|
|
title: 'Add feature',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('when the merge request is successfully created', () => {
|
|
|
|
it('resolves the Promise', () => {
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onPost(expectedUrl, options).replyOnce(httpStatus.CREATED);
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
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-10-24 23:57:45 +05:30
|
|
|
mock.onPost(expectedUrl).replyOnce(httpStatus.INTERNAL_SERVER_ERROR);
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
return Api.createProjectMergeRequest(dummyProjectPath).catch(() => {
|
|
|
|
expect(mock.history.post).toHaveLength(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
describe('updateIssue', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('update an issue with the given payload', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const projectId = 8;
|
|
|
|
const issue = 1;
|
|
|
|
const expectedArray = [1, 2, 3];
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/issues/${issue}`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onPut(expectedUrl).reply(httpStatus.OK, { assigneeIds: expectedArray });
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.updateIssue(projectId, issue, { assigneeIds: expectedArray }).then(({ data }) => {
|
|
|
|
expect(data.assigneeIds).toEqual(expectedArray);
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateMergeRequest', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('update an issue with the given payload', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const projectId = 8;
|
|
|
|
const mergeRequest = 1;
|
|
|
|
const expectedArray = [1, 2, 3];
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/merge_requests/${mergeRequest}`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onPut(expectedUrl).reply(httpStatus.OK, { assigneeIds: expectedArray });
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.updateMergeRequest(projectId, mergeRequest, { assigneeIds: expectedArray }).then(
|
|
|
|
({ data }) => {
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(data.assigneeIds).toEqual(expectedArray);
|
2022-06-21 17:19:12 +05:30
|
|
|
},
|
|
|
|
);
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('tags', () => {
|
2022-06-21 17:19:12 +05:30
|
|
|
it('fetches all tags of a particular project', () => {
|
2020-06-23 00:09:42 +05:30
|
|
|
const query = 'dummy query';
|
|
|
|
const options = { unused: 'option' };
|
|
|
|
const projectId = 8;
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/repository/tags`;
|
2020-10-24 23:57:45 +05:30
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [
|
2020-06-23 00:09:42 +05:30
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return Api.tags(projectId, query, options).then(({ data }) => {
|
|
|
|
expect(data.length).toBe(1);
|
|
|
|
expect(data[0].name).toBe('test');
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
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`;
|
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, [freezePeriod]);
|
|
|
|
|
|
|
|
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', () => {
|
|
|
|
mock.onPost(expectedUrl, options).replyOnce(httpStatus.CREATED, expectedResult);
|
|
|
|
|
|
|
|
return Api.createFreezePeriod(projectId, options).then(({ data }) => {
|
|
|
|
expect(data).toStrictEqual(expectedResult);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('updateFreezePeriod', () => {
|
|
|
|
const options = {
|
|
|
|
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',
|
|
|
|
};
|
|
|
|
const projectId = 8;
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/freeze_periods/${options.id}`;
|
|
|
|
|
|
|
|
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 updated', () => {
|
|
|
|
it('resolves the Promise', () => {
|
|
|
|
mock.onPut(expectedUrl, options).replyOnce(httpStatus.OK, expectedResult);
|
|
|
|
|
|
|
|
return Api.updateFreezePeriod(projectId, options).then(({ data }) => {
|
|
|
|
expect(data).toStrictEqual(expectedResult);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
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');
|
|
|
|
|
|
|
|
mock.onPost(expectedUrl).replyOnce(httpStatus.OK, {
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
describe('trackRedisCounterEvent', () => {
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/usage_data/increment_counter`;
|
|
|
|
|
|
|
|
const event = 'dummy_event';
|
|
|
|
const postData = { event };
|
|
|
|
const headers = {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
};
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
describe('when service data increment counter is called with feature flag disabled', () => {
|
2021-02-22 17:27:13 +05:30
|
|
|
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.trackRedisCounterEvent(event)).toEqual(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
describe('when service data increment counter is called', () => {
|
2021-02-22 17:27:13 +05:30
|
|
|
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.trackRedisCounterEvent(event).then(({ data }) => {
|
|
|
|
expect(data).toEqual(true);
|
|
|
|
expect(axios.post).toHaveBeenCalledWith(expectedUrl, postData, { headers });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
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',
|
|
|
|
};
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
describe('when user is set', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
beforeEach(() => {
|
2021-09-04 01:27:46 +05:30
|
|
|
window.gon.current_user_id = 1;
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
describe('when service data increment unique users is called with feature flag disabled', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
gon.features = { ...gon.features, usageDataApi: false };
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it('returns null and does not call the endpoint', () => {
|
|
|
|
jest.spyOn(axios, 'post');
|
|
|
|
|
|
|
|
const result = Api.trackRedisHllUserEvent(event);
|
|
|
|
|
|
|
|
expect(result).toEqual(null);
|
|
|
|
expect(axios.post).toHaveBeenCalledTimes(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
describe('when service data increment unique users is called', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
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 });
|
|
|
|
});
|
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
describe('when user is not set and feature flag enabled', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
gon.features = { ...gon.features, usageDataApi: true };
|
|
|
|
});
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it('returns null and does not call the endpoint', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
jest.spyOn(axios, 'post');
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
const result = Api.trackRedisHllUserEvent(event);
|
|
|
|
|
|
|
|
expect(result).toEqual(null);
|
|
|
|
expect(axios.post).toHaveBeenCalledTimes(0);
|
2021-01-03 14:25:43 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
describe('deployKeys', () => {
|
|
|
|
it('fetches deploy keys', async () => {
|
|
|
|
const deployKeys = [
|
|
|
|
{
|
|
|
|
id: 7,
|
|
|
|
title: 'My title 1',
|
|
|
|
created_at: '2021-10-29T16:59:55.229Z',
|
|
|
|
expires_at: null,
|
|
|
|
key:
|
|
|
|
'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDLvQzRX960N7dxPdge9o5a96+M4GEGQ7rxT2D3wAQDtQFjQV5ZcKb5wfeLtYLe3kRVI4lCO10PXeQppb1XBaYmVO31IaRkcgmMEPVyfp76Dp4CJZz6aMEbbcqfaHkDre0Fa8kzTXnBJVh2NeDbBfGMjFM5NRQLhKykodNsepO6dQ== dummy@gitlab.com',
|
|
|
|
fingerprint: '81:93:63:b9:1e:24:a2:aa:e0:87:d3:3f:42:81:f2:c2',
|
|
|
|
projects_with_write_access: [
|
|
|
|
{
|
|
|
|
id: 11,
|
|
|
|
description: null,
|
|
|
|
name: 'project1',
|
|
|
|
name_with_namespace: 'John Doe3 / project1',
|
|
|
|
path: 'project1',
|
|
|
|
path_with_namespace: 'namespace1/project1',
|
|
|
|
created_at: '2021-10-29T16:59:54.668Z',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 12,
|
|
|
|
description: null,
|
|
|
|
name: 'project2',
|
|
|
|
name_with_namespace: 'John Doe4 / project2',
|
|
|
|
path: 'project2',
|
|
|
|
path_with_namespace: 'namespace2/project2',
|
|
|
|
created_at: '2021-10-29T16:59:55.116Z',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/deploy_keys`;
|
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, deployKeys);
|
|
|
|
|
|
|
|
const params = { page: 2, public: true };
|
|
|
|
const { data } = await Api.deployKeys(params);
|
|
|
|
|
|
|
|
expect(data).toEqual(deployKeys);
|
|
|
|
expect(mock.history.get[0].params).toEqual({ ...params, per_page: DEFAULT_PER_PAGE });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
describe('projectSecureFiles', () => {
|
|
|
|
it('fetches secure files for a project', async () => {
|
|
|
|
const projectId = 1;
|
|
|
|
const secureFiles = [
|
|
|
|
{
|
|
|
|
id: projectId,
|
|
|
|
title: 'File Name',
|
|
|
|
permissions: 'read_only',
|
|
|
|
checksum: '12345',
|
|
|
|
checksum_algorithm: 'sha256',
|
|
|
|
created_at: '2022-02-21T15:27:18',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/secure_files`;
|
|
|
|
mock.onGet(expectedUrl).reply(httpStatus.OK, secureFiles);
|
|
|
|
const { data } = await Api.projectSecureFiles(projectId, {});
|
|
|
|
|
|
|
|
expect(data).toEqual(secureFiles);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
describe('uploadProjectSecureFile', () => {
|
|
|
|
it('uploads a secure file to a project', async () => {
|
|
|
|
const projectId = 1;
|
|
|
|
const secureFile = {
|
|
|
|
id: projectId,
|
|
|
|
title: 'File Name',
|
|
|
|
permissions: 'read_only',
|
|
|
|
checksum: '12345',
|
|
|
|
checksum_algorithm: 'sha256',
|
|
|
|
created_at: '2022-02-21T15:27:18',
|
|
|
|
};
|
|
|
|
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/secure_files`;
|
|
|
|
mock.onPost(expectedUrl).reply(httpStatus.OK, secureFile);
|
|
|
|
const { data } = await Api.uploadProjectSecureFile(projectId, 'some data');
|
|
|
|
|
|
|
|
expect(data).toEqual(secureFile);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deleteProjectSecureFile', () => {
|
|
|
|
it('removes a secure file from a project', async () => {
|
|
|
|
const projectId = 1;
|
|
|
|
const secureFileId = 2;
|
|
|
|
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/secure_files/${secureFileId}`;
|
|
|
|
mock.onDelete(expectedUrl).reply(httpStatus.NO_CONTENT, '');
|
|
|
|
const { data } = await Api.deleteProjectSecureFile(projectId, secureFileId);
|
|
|
|
expect(data).toEqual('');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
describe('dependency proxy cache', () => {
|
|
|
|
it('schedules the cache list for deletion', async () => {
|
|
|
|
const groupId = 1;
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/groups/${groupId}/dependency_proxy/cache`;
|
|
|
|
|
|
|
|
mock.onDelete(expectedUrl).reply(httpStatus.ACCEPTED);
|
|
|
|
const { status } = await Api.deleteDependencyProxyCacheList(groupId, {});
|
|
|
|
|
|
|
|
expect(status).toBe(httpStatus.ACCEPTED);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
describe('Feature Flag User List', () => {
|
|
|
|
let expectedUrl;
|
|
|
|
let projectId;
|
|
|
|
let mockUserList;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
projectId = 1000;
|
|
|
|
expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${projectId}/feature_flags_user_lists`;
|
|
|
|
mockUserList = {
|
|
|
|
name: 'mock_user_list',
|
|
|
|
user_xids: '1,2,3,4',
|
|
|
|
project_id: 1,
|
|
|
|
id: 1,
|
|
|
|
iid: 1,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchFeatureFlagUserLists', () => {
|
|
|
|
it('GETs the right url', () => {
|
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, []);
|
|
|
|
|
|
|
|
return Api.fetchFeatureFlagUserLists(projectId).then(({ data }) => {
|
|
|
|
expect(data).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('searchFeatureFlagUserLists', () => {
|
|
|
|
it('GETs the right url', () => {
|
|
|
|
mock.onGet(expectedUrl, { params: { search: 'test' } }).replyOnce(httpStatus.OK, []);
|
|
|
|
|
|
|
|
return Api.searchFeatureFlagUserLists(projectId, 'test').then(({ data }) => {
|
|
|
|
expect(data).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('createFeatureFlagUserList', () => {
|
|
|
|
it('POSTs data to the right url', () => {
|
|
|
|
const mockUserListData = {
|
|
|
|
name: 'mock_user_list',
|
|
|
|
user_xids: '1,2,3,4',
|
|
|
|
};
|
|
|
|
mock.onPost(expectedUrl, mockUserListData).replyOnce(httpStatus.OK, mockUserList);
|
|
|
|
|
|
|
|
return Api.createFeatureFlagUserList(projectId, mockUserListData).then(({ data }) => {
|
|
|
|
expect(data).toEqual(mockUserList);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchFeatureFlagUserList', () => {
|
|
|
|
it('GETs the right url', () => {
|
|
|
|
mock.onGet(`${expectedUrl}/1`).replyOnce(httpStatus.OK, mockUserList);
|
|
|
|
|
|
|
|
return Api.fetchFeatureFlagUserList(projectId, 1).then(({ data }) => {
|
|
|
|
expect(data).toEqual(mockUserList);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('updateFeatureFlagUserList', () => {
|
|
|
|
it('PUTs the right url', () => {
|
|
|
|
mock
|
|
|
|
.onPut(`${expectedUrl}/1`)
|
|
|
|
.replyOnce(httpStatus.OK, { ...mockUserList, user_xids: '5' });
|
|
|
|
|
|
|
|
return Api.updateFeatureFlagUserList(projectId, {
|
|
|
|
...mockUserList,
|
|
|
|
user_xids: '5',
|
|
|
|
}).then(({ data }) => {
|
|
|
|
expect(data).toEqual({ ...mockUserList, user_xids: '5' });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deleteFeatureFlagUserList', () => {
|
|
|
|
it('DELETEs the right url', () => {
|
|
|
|
mock.onDelete(`${expectedUrl}/1`).replyOnce(httpStatus.OK, 'deleted');
|
|
|
|
|
|
|
|
return Api.deleteFeatureFlagUserList(projectId, 1).then(({ data }) => {
|
|
|
|
expect(data).toBe('deleted');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-06-21 17:19:12 +05:30
|
|
|
|
|
|
|
describe('projectProtectedBranch', () => {
|
|
|
|
const branchName = 'new-branch-name';
|
|
|
|
const dummyProjectId = 5;
|
|
|
|
const expectedUrl = `${dummyUrlRoot}/api/${dummyApiVersion}/projects/${dummyProjectId}/protected_branches/${branchName}`;
|
|
|
|
|
|
|
|
it('returns 404 for non-existing branch', () => {
|
|
|
|
jest.spyOn(axios, 'get');
|
|
|
|
|
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.NOT_FOUND, {
|
|
|
|
message: '404 Not found',
|
|
|
|
});
|
|
|
|
|
|
|
|
return Api.projectProtectedBranch(dummyProjectId, branchName).catch((error) => {
|
|
|
|
expect(error.response.status).toBe(httpStatus.NOT_FOUND);
|
|
|
|
expect(axios.get).toHaveBeenCalledWith(expectedUrl);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns 200 with branch information', () => {
|
|
|
|
const expectedObj = { name: branchName };
|
|
|
|
|
|
|
|
jest.spyOn(axios, 'get');
|
|
|
|
|
|
|
|
mock.onGet(expectedUrl).replyOnce(httpStatus.OK, expectedObj);
|
|
|
|
|
|
|
|
return Api.projectProtectedBranch(dummyProjectId, branchName).then((data) => {
|
|
|
|
expect(data).toEqual(expectedObj);
|
|
|
|
expect(axios.get).toHaveBeenCalledWith(expectedUrl);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-09-10 17:25:29 +05:30
|
|
|
});
|