Flavien Bridault 704ab0c5b3
Add related merge requests and closed by in Issues service (#903)
* Add `related merge requests` and `closed by` in Issues service
* Rename all issueId variables to issueIid to comply with GitLab API
* Reflect also the change in the unit-test, though only one occurrence was
found.
2020-06-25 23:19:19 +02:00

198 lines
5.5 KiB
TypeScript

import { RequesterType } from '@gitbeaker/requester-utils';
import { RequestHelper } from '../../../src/infrastructure';
import { Issues } from '../../../src';
jest.mock('../../../src/infrastructure/RequestHelper');
let service: Issues;
beforeEach(() => {
const requester = {
get: jest.fn(() => Promise.resolve([])),
post: jest.fn(() => Promise.resolve({})),
put: jest.fn(() => Promise.resolve({})),
delete: jest.fn(() => Promise.resolve({})),
} as RequesterType;
service = new Issues({
requester,
token: 'abcdefg',
requestTimeout: 3000,
});
});
describe('Instantiating Issues service', () => {
it('should create a valid service object', async () => {
expect(service).toBeInstanceOf(Issues);
expect(service.url).toBeDefined();
expect(service.rejectUnauthorized).toBeTruthy();
expect(service.headers).toMatchObject({ 'private-token': 'abcdefg' });
expect(service.requestTimeout).toBe(3000);
});
});
describe('Issues.addSpentTime', () => {
it('should request POST projects/:id/issues:id/add_spent_time', async () => {
await service.addSpentTime(2, 3, '10m');
expect(RequestHelper.post).toHaveBeenCalledWith(service, 'projects/2/issues/3/add_spent_time', {
duration: '10m',
});
});
});
describe('Issues.addTimeEstimate', () => {
it('should request POST projects/:id/issues:id/add_spent_time', async () => {
await service.addTimeEstimate(2, 3, '10m');
expect(RequestHelper.post).toHaveBeenCalledWith(service, 'projects/2/issues/3/time_estimate', {
duration: '10m',
});
});
});
describe('Issues.all', () => {
it('should request GET /issues', async () => {
await service.all();
expect(RequestHelper.get).toHaveBeenCalledWith(service, 'issues', {});
});
it('should request GET /projects/:id/issues when project Id is passed', async () => {
await service.all({ projectId: 1 });
expect(RequestHelper.get).toHaveBeenCalledWith(service, 'projects/1/issues', {});
});
it('should request GET /group/:id/issues when group Id is passed', async () => {
await service.all({ groupId: 2 });
expect(RequestHelper.get).toHaveBeenCalledWith(service, 'groups/2/issues', {});
});
});
describe('Issues.edit', () => {
it('should request PUT /projects/:id/issues/:iid', async () => {
await service.edit(1, 2, { title: 'Testing terms' });
expect(RequestHelper.put).toHaveBeenCalledWith(service, 'projects/1/issues/2', {
title: 'Testing terms',
});
});
});
describe('Issues.create', () => {
it('should request POST projects/:id/issues', async () => {
await service.create(2, {
title: 'Issue.create Test',
description: 'A test issue',
});
expect(RequestHelper.post).toHaveBeenCalledWith(service, 'projects/2/issues', {
title: 'Issue.create Test',
description: 'A test issue',
});
});
});
// FIXME: Seems to error out with the correct # of calls but incorrect # recieved
// https://gitlab.com/jdalrymple/gitbeaker/-/jobs/574881954#L253
describe.skip('Issues.link', () => {
it('should request POST projects/:id/issues/:id/links', async () => {
await service.link(8, 3, 4, 5);
expect(RequestHelper.post).toHaveBeenCalledWith(service, 'projects/8/issues/3/links', {
targetProjectId: 4,
targetIssueIid: 5,
});
});
});
describe('Issues.participants', () => {
it('should request GET /projects/:id/issues/:id/participants', async () => {
await service.participants(1, 2);
expect(RequestHelper.get).toHaveBeenCalledWith(
service,
'projects/1/issues/2/participants',
undefined,
);
});
});
describe('Issues.remove', () => {
it('should request DEL /projects/:id/issues/:id', async () => {
await service.remove(1, 2);
expect(RequestHelper.del).toHaveBeenCalledWith(service, 'projects/1/issues/2', undefined);
});
});
describe('Issues.resetSpentTime', () => {
it('should request POST projects/:id/issues/:iid/reset_spent_time', async () => {
await service.resetSpentTime(2, 3);
expect(RequestHelper.post).toHaveBeenCalledWith(
service,
'projects/2/issues/3/reset_spent_time',
undefined,
);
});
});
describe('Issues.resetTimeEstimate', () => {
it('should request POST projects/:id/issues/:iid/reset_time_estimate', async () => {
await service.resetTimeEstimate(2, 3);
expect(RequestHelper.post).toHaveBeenCalledWith(
service,
'projects/2/issues/3/reset_time_estimate',
undefined,
);
});
});
describe('Issues.show', () => {
it('should request GET /projects/:id/issues/:id', async () => {
await service.show(1, 2);
expect(RequestHelper.get).toHaveBeenCalledWith(service, 'projects/1/issues/2', undefined);
});
});
describe('Issues.subscribe', () => {
it('should request POST projects/:id/issues/:iid/subscribe', async () => {
await service.subscribe(2, 3);
expect(RequestHelper.post).toHaveBeenCalledWith(
service,
'projects/2/issues/3/subscribe',
undefined,
);
});
});
describe('Issues.timeStats', () => {
it('should request GET /projects/:id/issues/:id/time_stats', async () => {
await service.timeStats(1, 2);
expect(RequestHelper.get).toHaveBeenCalledWith(
service,
'projects/1/issues/2/time_stats',
undefined,
);
});
});
describe('Issues.unsubscribe', () => {
it('should request DEL projects/:id/issues/:iid/unsubscribe', async () => {
await service.unsubscribe(2, 3);
expect(RequestHelper.del).toHaveBeenCalledWith(
service,
'projects/2/issues/3/unsubscribe',
undefined,
);
});
});