gitbeaker/packages/core/test/unit/templates/ResourceCustomAttributes.ts
Justin Dalrymple 7f1648802b Major Release v36.0.0 - Improved Typing, and API support (16.0) (#2258)
Adding extensive typing support
Unified browser and Node.JS implementations
Adding support of Gitlab API 16.0
2023-04-26 12:58:56 -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()).toHaveBeenCalledWith(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()).toHaveBeenCalledWith(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()).toHaveBeenCalledWith(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()).toHaveBeenCalledWith(service, '5/custom_attributes/6', undefined);
});
});