Justin Dalrymple db63076a5a
Reach > 90% coverage and add Integration Testing (#709)
- Added many many more unit tests to increase coverage to 90% +
- Removed the upsert functionality of PushRules to maintain documented API parity
2020-06-20 14:55:12 +02:00

101 lines
2.7 KiB
TypeScript

import { RequesterType } from '@gitbeaker/requester-utils';
import { RequestHelper } from '../../../src/infrastructure';
import { GeoNodes } from '../../../src';
jest.mock('../../../src/infrastructure/RequestHelper');
let service: GeoNodes;
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 GeoNodes({
requester,
token: 'abcdefg',
requestTimeout: 3000,
});
});
describe('Instantiating GeoNodes service', () => {
it('should create a valid service object', async () => {
expect(service).toBeInstanceOf(GeoNodes);
expect(service.url).toBeDefined();
expect(service.rejectUnauthorized).toBeTruthy();
expect(service.headers).toMatchObject({ 'private-token': 'abcdefg' });
expect(service.requestTimeout).toBe(3000);
});
});
describe('GeoNodes.all', () => {
it('should request GET /geo_nodes', async () => {
await service.all();
expect(RequestHelper.get).toHaveBeenCalledWith(service, 'geo_nodes', undefined);
});
});
describe('GeoNodes.create', () => {
it('should request POST /geo_nodes', async () => {
await service.create(1);
expect(RequestHelper.post).toHaveBeenCalledWith(service, 'geo_nodes/1', undefined);
});
});
describe('GeoNodes.edit', () => {
it('should request PUT /geo_nodes/:id', async () => {
await service.edit(1);
expect(RequestHelper.put).toHaveBeenCalledWith(service, 'geo_nodes/1', undefined);
});
});
describe('GeoNodes.failures', () => {
it('should request POST /geo_nodes/current/failures', async () => {
await service.failures();
expect(RequestHelper.post).toHaveBeenCalledWith(
service,
'geo_nodes/current/failures',
undefined,
);
});
});
describe('GeoNodes.repair', () => {
it('should request DELETE /geo_nodes/:id', async () => {
await service.repair(1);
expect(RequestHelper.del).toHaveBeenCalledWith(service, 'geo_nodes/1', undefined);
});
});
describe('GeoNodes.show', () => {
it('should request GET /geo_nodes/:id', async () => {
await service.show(1);
expect(RequestHelper.get).toHaveBeenCalledWith(service, 'geo_nodes/1', undefined);
});
});
describe('GeoNodes.status', () => {
it('should request GET /geo_nodes/:id/status', async () => {
await service.status(1);
expect(RequestHelper.get).toHaveBeenCalledWith(service, 'geo_nodes/1/status', undefined);
});
});
describe('GeoNodes.statuses', () => {
it('should request GET /geo_nodes/statuses', async () => {
await service.statuses();
expect(RequestHelper.get).toHaveBeenCalledWith(service, 'geo_nodes/statuses', undefined);
});
});