-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1072 from TattsGroup/add-member-role-filter
Add member role filter to OrganizationMembersClient.GetAll() functions
- Loading branch information
Showing
8 changed files
with
415 additions
and
0 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
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
72 changes: 72 additions & 0 deletions
72
Octokit.Tests.Integration/Clients/OrganizationMembersClientTests.cs
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Octokit; | ||
using Octokit.Tests.Integration; | ||
using Octokit.Tests.Integration.Helpers; | ||
using Xunit; | ||
|
||
namespace Octokit.Tests.Integration.Clients | ||
{ | ||
public class OrganizationMembersClientTests | ||
{ | ||
public class TheGetAllMethod | ||
{ | ||
private IGitHubClient _gitHub; | ||
private string _organizationFixture; | ||
|
||
public TheGetAllMethod() | ||
{ | ||
_gitHub = Helper.GetAuthenticatedClient(); | ||
_organizationFixture = "octokit"; | ||
} | ||
|
||
[IntegrationTest] | ||
public async Task ReturnsMembers() | ||
{ | ||
var members = _gitHub.Organization.Member.GetAll(_organizationFixture); | ||
Assert.NotNull(members); | ||
} | ||
|
||
[IntegrationTest(Skip = "TwoFactor filter can't be used unless the requester is an organization owner")] | ||
public async Task ReturnsMembersWithFilter() | ||
{ | ||
var no2FAMembers = await _gitHub.Organization.Member.GetAll(_organizationFixture, OrganizationMembersFilter.TwoFactorAuthenticationDisabled); | ||
Assert.NotNull(no2FAMembers); | ||
} | ||
|
||
[IntegrationTest(Skip = "Admin/Member filter doesn't work unless the requester is an organization member")] | ||
public async Task ReturnsMembersWithRole() | ||
{ | ||
var adminMembers = await _gitHub.Organization.Member.GetAll(_organizationFixture, OrganizationMembersRole.Admin); | ||
Assert.NotNull(adminMembers); | ||
|
||
var normalMembers = await _gitHub.Organization.Member.GetAll(_organizationFixture, OrganizationMembersRole.Member); | ||
Assert.NotNull(normalMembers); | ||
|
||
// There shouldnt be any members that are in both groups if the role filter works correctly | ||
var membersInBoth = adminMembers.Select(a => a.Id).Intersect(normalMembers.Select(n => n.Id)); | ||
Assert.True(membersInBoth.Count() == 0); | ||
} | ||
|
||
[IntegrationTest(Skip = "TwoFactor filter can't be used unless the requester is an organization owner")] | ||
public async Task ReturnsMembersWthFilterAndRole() | ||
{ | ||
// Get count of admin/normal members | ||
var adminCount = (await _gitHub.Organization.Member.GetAll(_organizationFixture, OrganizationMembersRole.Admin)).Count; | ||
var memberCount = (await _gitHub.Organization.Member.GetAll(_organizationFixture, OrganizationMembersRole.Member)).Count; | ||
|
||
// Ensure that there are less admins with no 2 factor, than there are total admins | ||
var adminsWithNo2FA = await _gitHub.Organization.Member.GetAll(_organizationFixture, OrganizationMembersFilter.TwoFactorAuthenticationDisabled, OrganizationMembersRole.Admin); | ||
Assert.NotNull(adminsWithNo2FA); | ||
Assert.True(adminsWithNo2FA.Count <= adminCount); | ||
|
||
// Ensure that there are less members with no 2 factor, than there are total admins | ||
var membersWithNo2FA = await _gitHub.Organization.Member.GetAll(_organizationFixture, OrganizationMembersFilter.TwoFactorAuthenticationDisabled, OrganizationMembersRole.Member); | ||
Assert.NotNull(membersWithNo2FA); | ||
Assert.True(membersWithNo2FA.Count <= memberCount); | ||
} | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.