diff --git a/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs index d26ada8439..4dcb9b2c17 100644 --- a/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Threading.Tasks; using Xunit; @@ -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; @@ -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); + } + } } } diff --git a/Octokit.Tests/Clients/GitHubAppsClientTests.cs b/Octokit.Tests/Clients/GitHubAppsClientTests.cs index 914f370a33..6e0bc85dd1 100644 --- a/Octokit.Tests/Clients/GitHubAppsClientTests.cs +++ b/Octokit.Tests/Clients/GitHubAppsClientTests.cs @@ -193,7 +193,7 @@ public void GetsFromCorrectUrl() client.GetOrganizationInstallationForCurrent("ducks"); - connection.Received().Get(Arg.Is(u => u.ToString() == "org/ducks/installation"), null, "application/vnd.github.machine-man-preview+json"); + connection.Received().Get(Arg.Is(u => u.ToString() == "orgs/ducks/installation"), null, "application/vnd.github.machine-man-preview+json"); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 86a6f24b9c..244565f315 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -342,15 +342,15 @@ public static Uri RepoInstallation(long repositoryId) } /// - /// Returns the that returns the repository's installation information. + /// Returns the that returns the organization's installation information. /// public static Uri OrganizationInstallation(string organization) { - return "org/{0}/installation".FormatUri(organization); ; + return "orgs/{0}/installation".FormatUri(organization); ; } /// - /// Returns the that returns the repository's installation information. + /// Returns the that returns the user's installation information. /// public static Uri UserInstallation(string username) {