Skip to content

Commit

Permalink
feat(members): +members resource api + unit tests (#791)
Browse files Browse the repository at this point in the history
* feat(members): +members resource api + unit tests

* feat(members): remove some un-needed strings
  • Loading branch information
FelixBlaisThon authored Jan 22, 2024
1 parent b357a81 commit f545bc8
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/resources/Organizations/Members/Members.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,63 @@
import API from '../../../APICore.js';
import {GlobalPrivilegeModel} from '../../GlobalGroups/GlobalGroupInterfaces.js';
import {GroupModel, UpdateGroupOptions} from '../../Groups/GroupsInterfaces.js';
import Resource from '../../Resource.js';
import {OrganizationMemberModel} from './MembersInterface.js';

export default class Members extends Resource {
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/members`;

/**
* Lists the members of an organization.
*/
getAll() {
return this.api.get<OrganizationMemberModel[]>(Members.baseUrl);
}

/**
* deletes the member from all groups of an organization.
* Note: Deleted users can still be included by domain.
*
* @param username The username of the member to delete.
*/
delete(username: string) {
return this.api.delete<void>(`${Members.baseUrl}/${username}`);
}

/**
* Shows a member of an organization.
*
* @param username The username of the member to show.
*/
get(username: string) {
return this.api.get<OrganizationMemberModel>(`${Members.baseUrl}/${username}`);
}
/**
* Lists the privileges for the current user on an organization.
*/
getPrivileges() {
return this.api.get<GlobalPrivilegeModel[]>(`${Members.baseUrl}/privileges`);
}
/**
* Updates the members of an organization.
*
* @param sendEmailToInvitedUsers Whether to send an invitation email alongside the invite(s). Default to true.
*/
updateOrganizationMembers(model: OrganizationMemberModel[], options?: UpdateGroupOptions) {
return this.api.put<OrganizationMemberModel[]>(this.buildPath(Members.baseUrl, options), model);
}
/**
* Updates a member of an organization.
*
* @param username The username of the member to update.
*/
updateMember(username: string, model: OrganizationMemberModel) {
return this.api.put<OrganizationMemberModel>(`${Members.baseUrl}/${username}`, model);
}
/**
* Lists the groups to which an organization member belongs.
*
* @param username The username of the user for which to list groups.
*/
getGroups(username: string) {
return this.api.get<GroupModel[]>(`${Members.baseUrl}/${username}/groups`);
}
}
69 changes: 69 additions & 0 deletions src/resources/Organizations/Members/tests/Members.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import API from '../../../../APICore.js';
import {AuthProvider} from '../../../Enums.js';
import Members from '../Members.js';

jest.mock('../../../../APICore.js');
Expand Down Expand Up @@ -41,4 +42,72 @@ describe('Members', () => {
expect(api.get).toHaveBeenCalledWith(`${Members.baseUrl}/Gael`);
});
});

describe('getPrivileges', () => {
it('makes a GET call to check the privileges the user has in the organization', () => {
members.getPrivileges();

expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${Members.baseUrl}/privileges`);
});
});

describe('updateOrganizationMembers', () => {
it('makes a PUT call to update members of an organization', () => {
members.updateOrganizationMembers([
{
displayName: 'test',
email: '[email protected]',
groups: [],
provider: AuthProvider.GOOGLE,
providerUsername: 'test',
username: 'tttest',
},
]);

expect(api.put).toHaveBeenCalledTimes(1);
expect(api.put).toHaveBeenCalledWith(`${Members.baseUrl}`, [
{
displayName: 'test',
email: '[email protected]',
groups: [],
provider: 'GOOGLE',
providerUsername: 'test',
username: 'tttest',
},
]);
});
});

describe('updateMember', () => {
it('makes a PUT call to update a member of an organization', () => {
members.updateMember('gael', {
displayName: 'test',
email: '[email protected]',
groups: [],
provider: AuthProvider.GOOGLE,
providerUsername: 'test',
username: 'tttest',
});

expect(api.put).toHaveBeenCalledTimes(1);
expect(api.put).toHaveBeenCalledWith(`${Members.baseUrl}/gael`, {
displayName: 'test',
email: '[email protected]',
groups: [],
provider: 'GOOGLE',
providerUsername: 'test',
username: 'tttest',
});
});
});

describe('getGroups', () => {
it('makes a GET call to lists the groups to which an organization member belongs', () => {
members.getGroups('gael');

expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${Members.baseUrl}/gael/groups`);
});
});
});

0 comments on commit f545bc8

Please sign in to comment.