Organization membership preview API changes - Review user permission (#1633)

* Add organization membership preview header

* Add API endpoints to preview a collaborators permission

* Add methods to preview a collaborators permission

* Add methods to the observable repo collaborator client

* Fix convention test failure

* Use correct API endpoint when using repository ID

* Move the helper function pair so they aren't in between another pair

* Use the correct URL for the review permission API endpoint

* Add unit tests

* Add integration tests for review permission methods

* Fix spelling mistake

* Renaming enum as per review
This commit is contained in:
Henrik Andersson
2017-07-29 15:08:44 +10:00
committed by Ryan Gribble
parent db74c3b4ad
commit cda714bef6
12 changed files with 597 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Xunit;
@@ -260,6 +261,153 @@ public class RepositoryCollaboratorClientTests
}
}
public class TheReviewPermissionMethod
{
[IntegrationTest]
public async Task ReturnsReadPermissionForNonCollaborator()
{
var github = Helper.GetAuthenticatedClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await github.CreateRepositoryContext(new NewRepository(repoName)))
{
var fixture = github.Repository.Collaborator;
var permission = await fixture.ReviewPermission(context.RepositoryOwner, context.RepositoryName, "alfhenrik-test-2");
Assert.Equal(PermissionLevel.Read, permission.Permission);
}
}
[IntegrationTest]
public async Task ReturnsReadPermissionForNonCollaboratorWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await github.CreateRepositoryContext(new NewRepository(repoName)))
{
var fixture = github.Repository.Collaborator;
var permission = await fixture.ReviewPermission(context.RepositoryId, "alfhenrik-test-2");
Assert.Equal(PermissionLevel.Read, permission.Permission);
}
}
[IntegrationTest]
public async Task ReturnsWritePermissionForCollaborator()
{
var github = Helper.GetAuthenticatedClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await github.CreateRepositoryContext(new NewRepository(repoName)))
{
var fixture = github.Repository.Collaborator;
// add a collaborator
await fixture.Add(context.RepositoryOwner, context.RepositoryName, "alfhenrik-test-2");
var permission = await fixture.ReviewPermission(context.RepositoryOwner, context.RepositoryName, "alfhenrik-test-2");
Assert.Equal(PermissionLevel.Write, permission.Permission);
}
}
[IntegrationTest]
public async Task ReturnsWritePermissionForCollaboratorWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await github.CreateRepositoryContext(new NewRepository(repoName)))
{
var fixture = github.Repository.Collaborator;
// add a collaborator
await fixture.Add(context.RepositoryOwner, context.RepositoryName, "alfhenrik-test-2");
var permission = await fixture.ReviewPermission(context.RepositoryId, "alfhenrik-test-2");
Assert.Equal(PermissionLevel.Write, permission.Permission);
}
}
[IntegrationTest]
public async Task ReturnsAdminPermissionForOwner()
{
var github = Helper.GetAuthenticatedClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await github.CreateRepositoryContext(new NewRepository(repoName)))
{
var fixture = github.Repository.Collaborator;
var permission = await fixture.ReviewPermission(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner);
Assert.Equal(PermissionLevel.Admin, permission.Permission);
}
}
[IntegrationTest]
public async Task ReturnsAdminPermissionForOwnerWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await github.CreateRepositoryContext(new NewRepository(repoName)))
{
var fixture = github.Repository.Collaborator;
var permission = await fixture.ReviewPermission(context.RepositoryId, context.RepositoryOwner);
Assert.Equal(PermissionLevel.Admin, permission.Permission);
}
}
[PaidAccountTest]
public async Task ReturnsNonePermissionForPrivateRepository()
{
var github = Helper.GetAuthenticatedClient();
var userDetails = await github.User.Current();
if (userDetails.Plan.PrivateRepos == 0)
{
throw new Exception("Test cannot complete, account is on free plan");
}
var repoName = Helper.MakeNameWithTimestamp("private-repo");
using (var context = await github.CreateRepositoryContext(new NewRepository(repoName) { Private = true }))
{
var fixture = github.Repository.Collaborator;
var permission = await fixture.ReviewPermission(context.RepositoryOwner, context.RepositoryName, "alfhenrik-test-2");
Assert.Equal(PermissionLevel.None, permission.Permission);
}
}
[PaidAccountTest]
public async Task ReturnsNonePermissionForPrivateRepositoryWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();
var userDetails = await github.User.Current();
if (userDetails.Plan.PrivateRepos == 0)
{
throw new Exception("Test cannot complete, account is on free plan");
}
var repoName = Helper.MakeNameWithTimestamp("private-repo");
using (var context = await github.CreateRepositoryContext(new NewRepository(repoName) { Private = true }))
{
var fixture = github.Repository.Collaborator;
var permission = await fixture.ReviewPermission(context.RepositoryId, "alfhenrik-test-2");
Assert.Equal(PermissionLevel.None, permission.Permission);
}
}
}
public class TheDeleteMethod
{
[IntegrationTest]