-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(members): +members resource api + unit tests (#791)
* feat(members): +members resource api + unit tests * feat(members): remove some un-needed strings
- Loading branch information
1 parent
b357a81
commit f545bc8
Showing
2 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
|
@@ -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`); | ||
}); | ||
}); | ||
}); |