Skip to content

Commit

Permalink
Additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalrymple committed Dec 31, 2023
1 parent e0db094 commit 366951a
Show file tree
Hide file tree
Showing 8 changed files with 474 additions and 43 deletions.
55 changes: 29 additions & 26 deletions packages/core/src/resources/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,27 +407,6 @@ export class Users<C extends boolean = false> extends BaseResource<C> {
return RequestHelper.post<void>()(this, endpoint`users/${userId}/block`, options);
}

deactivate<E extends boolean = false>(
userId: number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<void, C, E, void>> {
return RequestHelper.post<void>()(this, endpoint`users/${userId}/deactivate`, options);
}

disableTwoFactor<E extends boolean = false>(
userId: number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<void, C, E, void>> {
return RequestHelper.patch<void>()(this, endpoint`users/${userId}/disable_two_factor`, options);
}

follow<E extends boolean = false>(
userId: number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<UserSchema, C, E, void>> {
return RequestHelper.post<UserSchema>()(this, endpoint`users/${userId}/follow`, options);
}

create<E extends boolean = false>(
options?: CreateUserOptions & Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<UserSchema | ExpandedUserSchema, C, E, void>> {
Expand Down Expand Up @@ -461,6 +440,20 @@ export class Users<C extends boolean = false> extends BaseResource<C> {
});
}

deactivate<E extends boolean = false>(
userId: number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<void, C, E, void>> {
return RequestHelper.post<void>()(this, endpoint`users/${userId}/deactivate`, options);
}

disableTwoFactor<E extends boolean = false>(
userId: number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<void, C, E, void>> {
return RequestHelper.patch<void>()(this, endpoint`users/${userId}/disable_two_factor`, options);
}

edit<E extends boolean = false>(
userId: number,
options?: EditUserOptions & Sudo & ShowExpanded<E>,
Expand Down Expand Up @@ -491,13 +484,20 @@ export class Users<C extends boolean = false> extends BaseResource<C> {
showWhitespaceInDiffs: boolean,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<UserPreferenceSchema, C, E, void>> {
return RequestHelper.get<UserPreferenceSchema>()(this, 'user/preferences', {
return RequestHelper.put<UserPreferenceSchema>()(this, 'user/preferences', {
viewDiffsFileByFile,
showWhitespaceInDiffs,
...options,
});
}

follow<E extends boolean = false>(
userId: number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<UserSchema, C, E, void>> {
return RequestHelper.post<UserSchema>()(this, endpoint`users/${userId}/follow`, options);
}

reject<E extends boolean = false>(
userId: number,
options?: Sudo & ShowExpanded<E>,
Expand Down Expand Up @@ -549,12 +549,15 @@ export class Users<C extends boolean = false> extends BaseResource<C> {
return RequestHelper.get<UserPreferenceSchema>()(this, 'user/preferences', options);
}

showStatus<E extends boolean = false>(
options?: { iDOrUsername?: string | number } & Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<UserStatusSchema, C, E, void>> {
showStatus<E extends boolean = false>({
iDOrUsername,
...options
}: { iDOrUsername?: string | number } & Sudo & ShowExpanded<E> = {}): Promise<
GitlabAPIResponse<UserStatusSchema, C, E, void>
> {
let url: string;

if (options?.iDOrUsername) url = `users/${options?.iDOrUsername}/status`;
if (iDOrUsername) url = `users/${iDOrUsername}/status`;
else url = 'user/status';

return RequestHelper.get<UserStatusSchema>()(this, url, options);
Expand Down
1 change: 1 addition & 0 deletions packages/core/test/__mocks__/RequestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export default {
get: () => mockHelperFn,
put: () => mockHelperFn,
del: () => mockHelperFn,
patch: () => mockHelperFn,
},
};
95 changes: 95 additions & 0 deletions packages/core/test/unit/resources/GeoSites.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { RequestHelper } from '../../../src/infrastructure';
import { GeoSites } from '../../../src';

jest.mock(
'../../../src/infrastructure/RequestHelper',
() => require('../../__mocks__/RequestHelper').default,
);

let service: GeoSites;

beforeEach(() => {
service = new GeoSites({
requesterFn: jest.fn(),
token: 'abcdefg',
});
});

describe('GeoSites.all', () => {
it('should request GET /geo_sites', async () => {
await service.all();

expect(RequestHelper.get()).toHaveBeenCalledWith(service, 'geo_sites', undefined);
});
});

describe('GeoSites.create', () => {
it('should request POST /geo_sites', async () => {
await service.create('name', 'url');

expect(RequestHelper.post()).toHaveBeenCalledWith(service, 'geo_sites', {
name: 'name',
url: 'url',
});
});
});

describe('GeoSites.edit', () => {
it('should request PUT /geo_sites/:id', async () => {
await service.edit(1);

expect(RequestHelper.put()).toHaveBeenCalledWith(service, 'geo_sites/1', undefined);
});

it('should request PUT /geo_sites/:id with options', async () => {
await service.edit(1, { internalUrl: 'url' });

expect(RequestHelper.put()).toHaveBeenCalledWith(service, 'geo_sites/1', {
internalUrl: 'url',
});
});
});

describe('GeoSites.allFailures', () => {
it('should request POST /geo_sites/current/failures', async () => {
await service.allFailures();

expect(RequestHelper.post()).toHaveBeenCalledWith(
service,
'geo_sites/current/failures',
undefined,
);
});
});

describe('GeoSites.repair', () => {
it('should request POST /geo_sites/:id/repair', async () => {
await service.repair(1);

expect(RequestHelper.post()).toHaveBeenCalledWith(service, 'geo_sites/1/repair', undefined);
});
});

describe('GeoSites.show', () => {
it('should request GET /geo_sites/:id', async () => {
await service.show(1);

expect(RequestHelper.get()).toHaveBeenCalledWith(service, 'geo_sites/1', undefined);
});
});

describe('GeoSites.showStatus', () => {
it('should request GET /geo_sites/:id/status', async () => {
await service.showStatus(1);

expect(RequestHelper.get()).toHaveBeenCalledWith(service, 'geo_sites/1/status', undefined);
});
});

describe('GeoSites.allStatuses', () => {
it('should request GET /geo_sites/statuses', async () => {
await service.allStatuses();

expect(RequestHelper.get()).toHaveBeenCalledWith(service, 'geo_sites/statuses', undefined);
});
});
24 changes: 24 additions & 0 deletions packages/core/test/unit/resources/GitlabPages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { RequestHelper } from '../../../src/infrastructure';
import { GitlabPages } from '../../../src';

jest.mock(
'../../../src/infrastructure/RequestHelper',
() => require('../../__mocks__/RequestHelper').default,
);

let service: GitlabPages;

beforeEach(() => {
service = new GitlabPages({
requesterFn: jest.fn(),
token: 'abcdefg',
});
});

describe('GitlabPages.remove', () => {
it('should request DEL /projects/1/pages', async () => {
await service.remove(1);

expect(RequestHelper.del()).toHaveBeenCalledWith(service, 'projects/1/pages', undefined);
});
});
60 changes: 60 additions & 0 deletions packages/core/test/unit/resources/GroupEpicBoards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { GroupEpicBoards } from '../../../src/resources';
import { RequestHelper } from '../../../src/infrastructure';

jest.mock(
'../../../src/infrastructure/RequestHelper',
() => require('../../__mocks__/RequestHelper').default,
);

let service: GroupEpicBoards;

beforeEach(() => {
service = new GroupEpicBoards({
requesterFn: jest.fn(),
token: 'abcdefg',
});
});

afterEach(() => {
jest.clearAllMocks();
});

describe('GroupEpicBoards.all', () => {
it('should call the correct url with a group id', async () => {
await service.all(1);

expect(RequestHelper.get()).toHaveBeenCalledWith(service, 'groups/1/epic_boards', undefined);
});
});

describe('GroupEpicBoards.allLists', () => {
it('should call the correct url with a group id and board id', async () => {
await service.allLists('5', 6);

expect(RequestHelper.get()).toHaveBeenCalledWith(
service,
'groups/5/epic_boards/6/lists',
undefined,
);
});
});

describe('GroupEpicBoards.show', () => {
it('should call the correct url with a group id and board id', async () => {
await service.show('5', 6);

expect(RequestHelper.get()).toHaveBeenCalledWith(service, 'groups/5/epic_boards/6', undefined);
});
});

describe('GroupEpicBoards.showList', () => {
it('should call the correct url with a group id, board id and list id', async () => {
await service.showList('5', 6, 7);

expect(RequestHelper.get()).toHaveBeenCalledWith(
service,
'groups/5/epic_boards/6/lists/7',
undefined,
);
});
});
63 changes: 63 additions & 0 deletions packages/core/test/unit/resources/InstanceLevelCICDVariables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { RequestHelper } from '../../../src/infrastructure';
import { InstanceLevelCICDVariables } from '../../../src';

jest.mock(
'../../../src/infrastructure/RequestHelper',
() => require('../../__mocks__/RequestHelper').default,
);

let service: InstanceLevelCICDVariables;

beforeEach(() => {
service = new InstanceLevelCICDVariables({
requesterFn: jest.fn(),
token: 'abcdefg',
});
});

describe('InstanceLevelCICDVariables.all', () => {
it('should request GET admin/ci/variables', async () => {
await service.all();

expect(RequestHelper.get()).toHaveBeenCalledWith(service, 'admin/ci/variables', undefined);
});
});

describe('InstanceLevelCICDVariables.create', () => {
it('should request POST admin/ci/variables', async () => {
await service.create('key', 'value', { raw: false });

expect(RequestHelper.post()).toHaveBeenCalledWith(service, 'admin/ci/variables', {
key: 'key',
value: 'value',
raw: false,
});
});
});

describe('InstanceLevelCICDVariables.edit', () => {
it('should request PUT admin/ci/variables/:key', async () => {
await service.edit('key', 'value', { raw: false });

expect(RequestHelper.post()).toHaveBeenCalledWith(service, 'admin/ci/variables/key', {
value: 'value',
raw: false,
});
});
});

describe('InstanceLevelCICDVariables.remove', () => {
it('should request DEL admin/ci/variables/:key', async () => {
await service.remove('key');

expect(RequestHelper.del()).toHaveBeenCalledWith(service, 'admin/ci/variables/key', undefined);
});
});

describe('InstanceLevelCICDVariables.show', () => {
it('should request GET admin/ci/variables/:name', async () => {
await service.show('key');

expect(RequestHelper.get()).toHaveBeenCalledWith(service, 'admin/ci/variables/key', undefined);
});
});
Loading

0 comments on commit 366951a

Please sign in to comment.