Add support for Freeze Periods (#1231)

See https://gitlab.com/gitlab-org/gitlab/-/blob/master/doc/api/freeze_periods.md
This commit is contained in:
Niklas Lochschmidt 2020-10-15 11:24:14 +00:00 committed by GitHub
parent e56009ba4d
commit 13d43b77b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 149 additions and 0 deletions

View File

@ -241,6 +241,7 @@ ContainerRegistry
Deployments
DeployKeys
Environments
FreezePeriods
Issues
IssuesStatistics
IssueNotes
@ -324,6 +325,7 @@ ContainerRegistry
Deployments
DeployKeys
Environments
FreezePeriods
Issues
IssuesStatistics
IssueNotes

View File

@ -38,6 +38,7 @@ export const {
Deployments,
DeployKeys,
Environments,
FreezePeriods,
Issues,
IssuesStatistics,
IssueNotes,

View File

@ -45,6 +45,7 @@ export const ProjectsBundle = bundler({
DeployKeys: APIServices.DeployKeys,
Deployments: APIServices.Deployments,
Environments: APIServices.Environments,
FreezePeriods: APIServices.FreezePeriods,
Issues: APIServices.Issues,
IssuesStatistics: APIServices.IssuesStatistics,
IssueAwardEmojis: APIServices.IssueAwardEmojis,

View File

@ -0,0 +1,57 @@
import { BaseService } from '@gitbeaker/requester-utils';
import { BaseRequestOptions, RequestHelper } from '../infrastructure';
export interface CreateFreezePeriodOptions {
cronTimezone?: string;
}
export interface EditFreezePeriodOptions {
cronTimezone?: string;
freezeStart?: string;
freezeEnd?: string;
}
export class FreezePeriods extends BaseService {
all(projectId: string | number, options?: BaseRequestOptions) {
const pId = encodeURIComponent(projectId);
return RequestHelper.get(this, `projects/${pId}/freeze_periods`, options);
}
show(projectId: string | number, freezePeriodId: number, options?: BaseRequestOptions) {
const [pId, fId] = [projectId, freezePeriodId].map(encodeURIComponent);
return RequestHelper.get(this, `projects/${pId}/freeze_periods/${fId}`, options);
}
create(
projectId: number | string,
freezeStart: string,
freezeEnd: string,
options?: CreateFreezePeriodOptions & BaseRequestOptions,
) {
const pId = encodeURIComponent(projectId);
return RequestHelper.post(this, `projects/${pId}/freeze_periods`, {
freezeStart,
freezeEnd,
...options,
});
}
edit(
projectId: number | string,
freezePeriodId: number,
options?: EditFreezePeriodOptions & BaseRequestOptions,
) {
const [pId, fId] = [projectId, freezePeriodId].map(encodeURIComponent);
return RequestHelper.put(this, `projects/${pId}/freeze_periods/${fId}`, options);
}
delete(projectId: number | string, freezePeriodId: number, options?: BaseRequestOptions) {
const [pId, fId] = [projectId, freezePeriodId].map(encodeURIComponent);
return RequestHelper.del(this, `projects/${pId}/freeze_periods/${fId}`, options);
}
}

View File

@ -32,6 +32,7 @@ export { ContainerRegistry } from './ContainerRegistry';
export { Deployments } from './Deployments';
export { DeployKeys } from './DeployKeys';
export { Environments } from './Environments';
export { FreezePeriods } from './FreezePeriods';
export { Issues } from './Issues';
export { IssuesStatistics } from './IssuesStatistics';
export { IssueNotes } from './IssueNotes';

View File

@ -0,0 +1,86 @@
import { RequesterType } from '@gitbeaker/requester-utils';
import { RequestHelper } from '../../../src/infrastructure';
import { FreezePeriods } from '../../../src';
jest.mock('../../../src/infrastructure/RequestHelper');
let service: FreezePeriods;
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 FreezePeriods({
requester,
token: 'abcdefg',
requestTimeout: 3000,
});
});
describe('Instantiating FreezePeriods service', () => {
it('should create a valid service object', async () => {
expect(service).toBeInstanceOf(FreezePeriods);
expect(service.url).toBeDefined();
expect(service.rejectUnauthorized).toBeTruthy();
expect(service.headers).toMatchObject({ 'private-token': 'abcdefg' });
expect(service.requestTimeout).toBe(3000);
});
});
describe('FreezePeriods.all', () => {
it('should request GET /projects/:id/freeze_periods', async () => {
await service.all(1);
expect(RequestHelper.get).toHaveBeenCalledWith(service, 'projects/1/freeze_periods', undefined);
});
});
describe('FreezePeriods.show', () => {
it('should request GET /projects/:id/freeze_periods/:freeze_period_id', async () => {
await service.show(1, 2);
expect(RequestHelper.get).toHaveBeenCalledWith(
service,
'projects/1/freeze_periods/2',
undefined,
);
});
});
describe('FreezePeriods.create', () => {
it('should request POST projects/:id/freeze_periods', async () => {
await service.create(1, '* * * * *', '* * * * *', { cronTimezone: 'UTC' });
expect(RequestHelper.post).toHaveBeenCalledWith(service, 'projects/1/freeze_periods', {
freezeStart: '* * * * *',
freezeEnd: '* * * * *',
cronTimezone: 'UTC',
});
});
});
describe('FreezePeriods.edit', () => {
it('should request PUT projects/:id/freeze_periods/:freeze_period_id', async () => {
await service.edit(1, 2, { freezeStart: '* * * * *' });
expect(RequestHelper.put).toHaveBeenCalledWith(service, 'projects/1/freeze_periods/2', {
freezeStart: '* * * * *',
});
});
});
describe('FreezePeriods.delete', () => {
it('should request DELETE projects/:id/freeze_periods/:freeze_period_id', async () => {
await service.delete(1, 2);
expect(RequestHelper.del).toHaveBeenCalledWith(
service,
'projects/1/freeze_periods/2',
undefined,
);
});
});

View File

@ -38,6 +38,7 @@ export const {
Deployments,
DeployKeys,
Environments,
FreezePeriods,
Issues,
IssuesStatistics,
IssueNotes,