Skip to content

Commit

Permalink
List pending organization / team invitations (#1640)
Browse files Browse the repository at this point in the history
* Add methods for listing pending organization invites

* Add unit/integration tests

* Add methods for getting all pending invites for a team

* Add unit/integration tests

* 🔥 whitespace 🔥

* Move new enum to it's own correct file and location

* Invite(s) -> Invitation(s)

* Add helper functions for adding invitations and cleaning the invitations up at the end of the test

* Add methods with ApiOptions

* Fix helper methods for adding/removing invitations

* Forgot to actually pass in the ApiOptions to the API call

* Add tests for new ApiOptions methods

* tweak integration tests

* Update outside collaborator tests to use [OrganizationTest] attribute for consistency

* Update test accounts used

* use octokitnet-test2 account now it has 2FA turned on
  • Loading branch information
hnrkndrssn authored and ryangribble committed Aug 14, 2017
1 parent b0ff506 commit 7c17021
Show file tree
Hide file tree
Showing 25 changed files with 929 additions and 65 deletions.
23 changes: 23 additions & 0 deletions Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,28 @@ public interface IObservableOrganizationMembersClient
/// <param name="user">The login for the user</param>
/// <returns></returns>
IObservable<Unit> Conceal(string org, string user);

/// <summary>
/// List all pending invitations for the organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <returns></returns>
IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(string org);

/// <summary>
/// List all pending invitations for the organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="options">Options to change API behaviour</param>
/// <returns></returns>
IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(string org, ApiOptions options);
}
}
23 changes: 23 additions & 0 deletions Octokit.Reactive/Clients/IObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,28 @@ public interface IObservableTeamsClient
/// </remarks>
/// <returns><see langword="true"/> if the repository is managed by the given team; <see langword="false"/> otherwise.</returns>
IObservable<bool> IsRepositoryManagedByTeam(int id, string owner, string repo);

/// <summary>
/// List all pending invitations for the given team.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="id">The team identifier</param>
/// <returns></returns>
IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(int id);

/// <summary>
/// List all pending invitations for the given team.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="id">The team identifier</param>
/// <param name="options">Options to change API behaviour.</param>
/// <returns></returns>
IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(int id, ApiOptions options);
}
}
34 changes: 34 additions & 0 deletions Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,5 +375,39 @@ public IObservable<Unit> Conceal(string org, string user)

return _client.Conceal(org, user).ToObservable();
}

/// <summary>
/// List all pending invitations for the organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <returns></returns>
public IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));

return GetAllPendingInvitations(org, ApiOptions.None);
}

/// <summary>
/// List all pending invitations for the organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/members/#list-pending-organization-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="options">Options to change API behaviour</param>
/// <returns></returns>
public IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(string org, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<OrganizationMembershipInvitation>(ApiUrls.OrganizationPendingInvititations(org), null, AcceptHeaders.OrganizationMembershipPreview, options);
}
}
}
34 changes: 34 additions & 0 deletions Octokit.Reactive/Clients/ObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,39 @@ public IObservable<bool> IsRepositoryManagedByTeam(int id, string owner, string
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
return _client.IsRepositoryManagedByTeam(id, owner, repo).ToObservable();
}

/// <summary>
/// List all pending invitations for the given team.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="id">The team identifier</param>
/// <returns></returns>
public IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(int id)
{
Ensure.ArgumentNotNull(id, nameof(id));

return GetAllPendingInvitations(id, ApiOptions.None);
}

/// <summary>
/// List all pending invitations for the given team.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="id">The team identifier</param>
/// <param name="options">Options to change API behaviour</param>
/// <returns></returns>
public IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(int id, ApiOptions options)
{
Ensure.ArgumentNotNull(id, nameof(id));
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<OrganizationMembershipInvitation>(ApiUrls.TeamPendingInvitations(id), null, AcceptHeaders.OrganizationMembershipPreview, options);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using System.Threading.Tasks;
using Octokit.Tests.Integration.Helpers;
using Xunit;

namespace Octokit.Tests.Integration.Clients
Expand All @@ -17,15 +18,15 @@ public TheGetAllMethod()
_organizationFixture = "octokit";
}

[IntegrationTest]
[OrganizationTest]
public async Task ReturnsMembers()
{
var members = await
_gitHub.Organization.Member.GetAll(_organizationFixture);
Assert.NotEmpty(members);
}

[IntegrationTest]
[OrganizationTest]
public async Task ReturnsCorrectCountOfMembersWithoutStart()
{
var options = new ApiOptions
Expand All @@ -39,7 +40,7 @@ public async Task ReturnsCorrectCountOfMembersWithoutStart()
Assert.Equal(1, members.Count);
}

[IntegrationTest]
[OrganizationTest]
public async Task ReturnsCorrectCountOfMembersWithStart()
{
var options = new ApiOptions
Expand All @@ -54,7 +55,7 @@ public async Task ReturnsCorrectCountOfMembersWithStart()
Assert.Equal(1, members.Count);
}

[IntegrationTest]
[OrganizationTest]
public async Task ReturnsDistinctMembersBasedOnStartPage()
{
var startOptions = new ApiOptions
Expand Down Expand Up @@ -119,5 +120,91 @@ public async Task ReturnsMembersWthFilterAndRole()
Assert.True(membersWithNo2FA.Count <= memberCount);
}
}

public class TheGetAllPendingInvitationsMethod
{
readonly IGitHubClient _gitHub;

public TheGetAllPendingInvitationsMethod()
{
_gitHub = Helper.GetAuthenticatedClient();
}

[OrganizationTest]
public async Task ReturnsNoPendingInvitations()
{
var pendingInvitations = await _gitHub.Organization.Member.GetAllPendingInvitations(Helper.Organization);
Assert.NotNull(pendingInvitations);
Assert.Empty(pendingInvitations);
}

[OrganizationTest]
public async Task ReturnsPendingInvitations()
{
using (var teamContext = await _gitHub.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team"))))
{
teamContext.InviteMember("octokitnet-test1");
teamContext.InviteMember("octokitnet-test2");

var pendingInvitations = await _gitHub.Organization.Member.GetAllPendingInvitations(Helper.Organization);
Assert.NotEmpty(pendingInvitations);
Assert.Equal(2, pendingInvitations.Count);
}
}

[OrganizationTest]
public async Task ReturnsCorrectCountOfPendingInvitationsWithoutStart()
{
using (var teamContext = await _gitHub.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team"))))
{
teamContext.InviteMember("octokitnet-test1");
teamContext.InviteMember("octokitnet-test2");

var options = new ApiOptions
{
PageCount = 1,
PageSize = 1
};

var pendingInvitations = await _gitHub.Organization.Member.GetAllPendingInvitations(Helper.Organization, options);
Assert.NotEmpty(pendingInvitations);
Assert.Equal(1, pendingInvitations.Count);
}
}

[OrganizationTest]
public async Task ReturnsCorrectCountOfPendingInvitationsWithStart()
{
using (var teamContext = await _gitHub.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team"))))
{
teamContext.InviteMember("octokitnet-test1");
teamContext.InviteMember("octokitnet-test2");

var firstPageOptions = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};

var firstPagePendingInvitations = await _gitHub.Organization.Member.GetAllPendingInvitations(Helper.Organization, firstPageOptions);
Assert.NotEmpty(firstPagePendingInvitations);
Assert.Equal(1, firstPagePendingInvitations.Count);

var secondPageOptions = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 2
};

var secondPagePendingInvitations = await _gitHub.Organization.Member.GetAllPendingInvitations(Helper.Organization, secondPageOptions);
Assert.NotEmpty(secondPagePendingInvitations);
Assert.Equal(1, secondPagePendingInvitations.Count);

Assert.NotEqual(firstPagePendingInvitations[0].Login, secondPagePendingInvitations[0].Login);
}
}
}
}
}
Loading

0 comments on commit 7c17021

Please sign in to comment.