Skip to content

Commit

Permalink
add integration tests for new GitHubAppsClient methods, fixed an inco…
Browse files Browse the repository at this point in the history
…rrect route that the tests found!
  • Loading branch information
ryangribble committed Aug 29, 2018
1 parent 27ef381 commit 9effc1d
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 4 deletions.
99 changes: 99 additions & 0 deletions Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

Expand Down Expand Up @@ -104,6 +105,25 @@ public async Task GetsInstallation()
}
}

public class TheGetAllInstallationsForCurrentUserMethod
{
IGitHubClient _github;

public TheGetAllInstallationsForCurrentUserMethod()
{
// Need to Authenticate as User to Server but not possible without receiving redirect from github.com
//_github = Helper.GetAuthenticatedUserToServer();
}

[GitHubAppsTest(Skip ="Not possible to authenticate with User to Server auth")]
public async Task GetsAllInstallationsForCurrentUser()
{
var result = await _github.GitHubApps.GetAllInstallationsForCurrentUser();

Assert.NotNull(result);
}
}

public class TheCreateInstallationTokenMethod
{
IGitHubClient _github;
Expand All @@ -127,5 +147,84 @@ public async Task CreatesInstallationToken()
Assert.True(DateTimeOffset.Now < result.ExpiresAt);
}
}

public class TheGetOrganizationInstallationForCurrentMethod
{
IGitHubClient _github;

public TheGetOrganizationInstallationForCurrentMethod()
{
// Authenticate as a GitHubApp
_github = Helper.GetAuthenticatedGitHubAppsClient();
}

[GitHubAppsTest]
public async Task GetsOrganizationInstallations()
{
var result = await _github.GitHubApps.GetOrganizationInstallationForCurrent(Helper.Organization);

Assert.NotNull(result);
}
}

public class TheGetRepositoryInstallationForCurrentMethod
{
IGitHubClient _github;
IGitHubClient _githubAppInstallation;

public TheGetRepositoryInstallationForCurrentMethod()
{
// Autheticate as a GitHubApp
_github = Helper.GetAuthenticatedGitHubAppsClient();

// Authenticate as a GitHubApp Installation
_githubAppInstallation = Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName);
}

[GitHubAppsTest]
public async Task GetsRepositoryInstallations()
{
// Find a repo under the installation
var repos = await _githubAppInstallation.GitHubApps.Installation.GetAllRepositoriesForCurrent();
var repo = repos.Repositories.First();

// Now, using the GitHub App auth, find this repository installation
var result = await _github.GitHubApps.GetRepositoryInstallationForCurrent(repo.Owner.Login, repo.Name);

Assert.NotNull(result);
}

[GitHubAppsTest]
public async Task GetsRepositoryInstallationsWithRepositoryId()
{
// Find a repo under the installation
var repos = await _githubAppInstallation.GitHubApps.Installation.GetAllRepositoriesForCurrent();
var repo = repos.Repositories.First();

// Now, using the GitHub App auth, find this repository installation
var result = await _github.GitHubApps.GetRepositoryInstallationForCurrent(repo.Id);

Assert.NotNull(result);
}
}

public class TheGetUserInstallationForCurrentMethod
{
IGitHubClient _github;

public TheGetUserInstallationForCurrentMethod()
{
// Authenticate as a GitHubApp
_github = Helper.GetAuthenticatedGitHubAppsClient();
}

[GitHubAppsTest]
public async Task GetsUserInstallations()
{
var result = await _github.GitHubApps.GetUserInstallationForCurrent(Helper.UserName);

Assert.NotNull(result);
}
}
}
}
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/GitHubAppsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void GetsFromCorrectUrl()

client.GetOrganizationInstallationForCurrent("ducks");

connection.Received().Get<Installation>(Arg.Is<Uri>(u => u.ToString() == "org/ducks/installation"), null, "application/vnd.github.machine-man-preview+json");
connection.Received().Get<Installation>(Arg.Is<Uri>(u => u.ToString() == "orgs/ducks/installation"), null, "application/vnd.github.machine-man-preview+json");
}
}

Expand Down
6 changes: 3 additions & 3 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,15 @@ public static Uri RepoInstallation(long repositoryId)
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns the repository's installation information.
/// Returns the <see cref="Uri"/> that returns the organization's installation information.
/// </summary>
public static Uri OrganizationInstallation(string organization)
{
return "org/{0}/installation".FormatUri(organization); ;
return "orgs/{0}/installation".FormatUri(organization); ;
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns the repository's installation information.
/// Returns the <see cref="Uri"/> that returns the user's installation information.
/// </summary>
public static Uri UserInstallation(string username)
{
Expand Down

0 comments on commit 9effc1d

Please sign in to comment.