gitbeaker/packages/core/test/unit/templates/ResourceCustomAttributes.ts
2021-06-07 08:43:41 -04:00

63 lines
1.8 KiB
TypeScript

import { ResourceCustomAttributes } from '../../../src/templates';
import { RequestHelper } from '../../../src/infrastructure';
jest.mock(
'../../../src/infrastructure/RequestHelper',
() => require('../../__mocks__/RequestHelper').default,
);
let service: ResourceCustomAttributes;
beforeEach(() => {
service = new ResourceCustomAttributes('resource', {
requesterFn: jest.fn(),
token: 'abcdefg',
});
});
afterEach(() => {
jest.clearAllMocks();
});
describe('Instantiating ResourceCustomAttributes service', () => {
it('should create a valid service object', () => {
expect(service).toBeInstanceOf(ResourceCustomAttributes);
expect(service.url).toBeDefined();
expect(service.url).toContain('resource');
});
});
describe('ResourceCustomAttributes.all', () => {
it('should call the correct url with a resource id', async () => {
await service.all('5');
expect(RequestHelper.get()).toBeCalledWith(service, '5/custom_attributes', undefined);
});
});
describe('ResourceCustomAttributes.set', () => {
it('should call the correct url with a resource id', async () => {
await service.set('5', 6, 'on');
expect(RequestHelper.put()).toBeCalledWith(service, '5/custom_attributes/6', {
value: 'on',
});
});
});
describe('ResourceCustomAttributes.remove', () => {
it('should call the correct url with a resource id and custom attribute id', async () => {
await service.remove('5', 6);
expect(RequestHelper.del()).toBeCalledWith(service, '5/custom_attributes/6', undefined);
});
});
describe('ResourceCustomAttributes.show', () => {
it('should call the correct url with a resource id and custom attribute id', async () => {
await service.show('5', 6);
expect(RequestHelper.get()).toBeCalledWith(service, '5/custom_attributes/6', undefined);
});
});