Files
octokit.net/Octokit.Tests.Integration/Reactive/ObservableCheckRunsClientTests.cs
Ryan Gribble c5d5df5b08 Implement Check Runs API (#1847)
* Add CheckRunEventPayload

* add CheckRunEventPayload into all the right places

* forgot integration tests for RepositoryId methods (+1 squashed commits)

Squashed commits:

[b2445bf3] Implement Create CheckRun methods for normal and observable clients including unit and integration tests and xmldoc comments

* Implement Update CheckRun method
Refactored NewCheckRun to inherit CheckRunUpdate since they share all fields except HeadSha

* Implement GetAllForReference method

* Implement GetAllForCheckSuite method

* tweak XmlDoc to match github documentation

* Implement Get method

* Implement GetAllAnnotations
Moved CheckRunAnnotation model from Request to Common and added a parameterless ctor, since it is now a response model as well as a request model

* Split common CheckRunAnnotation model into separate response and request models due to different field and ctor requirements
Rename other CheckRun request sub classes to be consistent with NewCheckRunAnnotation (eg NewCheckRunOutput, NewCheckRunImage, etc)

* add title field back into CheckRunAnnotation

* fix up XmlDocs

* fix mutable response property - hooray for convention tests!
2018-07-19 08:29:12 +10:00

461 lines
23 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Octokit.Reactive;
using Octokit.Tests.Integration.Helpers;
using Xunit;
namespace Octokit.Tests.Integration.Reactive
{
public class ObservableCheckRunsClientTests
{
public class TheCreateMethod
{
IObservableGitHubClient _github;
IObservableGitHubClient _githubAppInstallation;
public TheCreateMethod()
{
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task CreatesCheckRun()
{
using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
{
// Create a new feature branch
var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.Queued
};
var result = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);
// Check result
Assert.NotNull(result);
Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
}
}
[GitHubAppsTest]
public async Task CreatesCheckRunWithRepositoryId()
{
using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
{
// Create a new feature branch
var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.Queued
};
var result = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun);
// Check result
Assert.NotNull(result);
Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
}
}
}
public class TheUpdateMethod
{
IObservableGitHubClient _github;
IObservableGitHubClient _githubAppInstallation;
public TheUpdateMethod()
{
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task UpdatesCheckRun()
{
using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
{
// Create a new feature branch
var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.Queued
};
var checkRun = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);
// Update the check run
var update = new CheckRunUpdate("new-name")
{
Status = CheckStatus.InProgress
};
var result = await _githubAppInstallation.Check.Run.Update(repoContext.RepositoryOwner, repoContext.RepositoryName, checkRun.Id, update);
// Check result
Assert.NotNull(result);
Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
Assert.Equal("new-name", result.Name);
Assert.Equal(CheckStatus.InProgress, result.Status);
}
}
[GitHubAppsTest]
public async Task UpdatesCheckRunWithRepositoryId()
{
using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
{
// Create a new feature branch
var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.Queued
};
var checkRun = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun);
// Update the check run
var update = new CheckRunUpdate("new-name")
{
Status = CheckStatus.InProgress
};
var result = await _githubAppInstallation.Check.Run.Update(repoContext.RepositoryId, checkRun.Id, update);
// Check result
Assert.NotNull(result);
Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
Assert.Equal("new-name", result.Name);
Assert.Equal(CheckStatus.InProgress, result.Status);
}
}
}
public class TheGetAllForReferenceMethod
{
IObservableGitHubClient _github;
IObservableGitHubClient _githubAppInstallation;
public TheGetAllForReferenceMethod()
{
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task GetsAllCheckRuns()
{
using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
{
// Create a new feature branch
var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress
};
await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);
// Get the check
var request = new CheckRunRequest
{
CheckName = "name",
Status = CheckStatusFilter.InProgress
};
var checkRuns = await _githubAppInstallation.Check.Run.GetAllForReference(repoContext.RepositoryOwner, repoContext.RepositoryName, featureBranch.Object.Sha, request);
// Check result
Assert.NotEmpty(checkRuns.CheckRuns);
foreach (var checkRun in checkRuns.CheckRuns)
{
Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
Assert.Equal("name", checkRun.Name);
Assert.Equal(CheckStatus.InProgress, checkRun.Status);
}
}
}
[GitHubAppsTest]
public async Task GetsAllCheckRunsWithRepositoryId()
{
using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
{
// Create a new feature branch
var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress
};
await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun);
// Get the check
var request = new CheckRunRequest
{
CheckName = "name",
Status = CheckStatusFilter.InProgress
};
var checkRuns = await _githubAppInstallation.Check.Run.GetAllForReference(repoContext.RepositoryId, featureBranch.Object.Sha, request);
// Check result
Assert.NotEmpty(checkRuns.CheckRuns);
foreach (var checkRun in checkRuns.CheckRuns)
{
Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
Assert.Equal("name", checkRun.Name);
Assert.Equal(CheckStatus.InProgress, checkRun.Status);
}
}
}
}
public class TheGetAllForCheckSuiteMethod
{
IObservableGitHubClient _github;
IObservableGitHubClient _githubAppInstallation;
public TheGetAllForCheckSuiteMethod()
{
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task GetsAllCheckRuns()
{
using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
{
// Create a new feature branch
var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress
};
var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);
// Get the check
var request = new CheckRunRequest
{
CheckName = "name",
Status = CheckStatusFilter.InProgress
};
var checkRuns = await _githubAppInstallation.Check.Run.GetAllForCheckSuite(repoContext.RepositoryOwner, repoContext.RepositoryName, created.CheckSuite.Id, request);
// Check result
Assert.NotEmpty(checkRuns.CheckRuns);
foreach (var checkRun in checkRuns.CheckRuns)
{
Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
Assert.Equal("name", checkRun.Name);
Assert.Equal(CheckStatus.InProgress, checkRun.Status);
}
}
}
[GitHubAppsTest]
public async Task GetsAllCheckRunsWithRepositoryId()
{
using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
{
// Create a new feature branch
var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress
};
var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun);
// Get the check
var request = new CheckRunRequest
{
CheckName = "name",
Status = CheckStatusFilter.InProgress
};
var checkRuns = await _githubAppInstallation.Check.Run.GetAllForCheckSuite(repoContext.RepositoryId, created.CheckSuite.Id, request);
// Check result
Assert.NotEmpty(checkRuns.CheckRuns);
foreach (var checkRun in checkRuns.CheckRuns)
{
Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
Assert.Equal("name", checkRun.Name);
Assert.Equal(CheckStatus.InProgress, checkRun.Status);
}
}
}
}
public class TheGetMethod
{
IObservableGitHubClient _github;
IObservableGitHubClient _githubAppInstallation;
public TheGetMethod()
{
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task GetsCheckRun()
{
using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
{
// Create a new feature branch
var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress
};
var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);
// Get the check
var checkRun = await _githubAppInstallation.Check.Run.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, created.Id);
// Check result
Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
Assert.Equal("name", checkRun.Name);
Assert.Equal(CheckStatus.InProgress, checkRun.Status);
}
}
[GitHubAppsTest]
public async Task GetsCheckRunWithRepositoryId()
{
using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
{
// Create a new feature branch
var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress
};
var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun);
// Get the check
var checkRun = await _githubAppInstallation.Check.Run.Get(repoContext.RepositoryId, created.Id);
// Check result
Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
Assert.Equal("name", checkRun.Name);
Assert.Equal(CheckStatus.InProgress, checkRun.Status);
}
}
}
public class TheGetAllAnnotationsMethod
{
IObservableGitHubClient _github;
IObservableGitHubClient _githubAppInstallation;
public TheGetAllAnnotationsMethod()
{
_github = new ObservableGitHubClient(Helper.GetAuthenticatedClient());
// Authenticate as a GitHubApp Installation
_githubAppInstallation = new ObservableGitHubClient(Helper.GetAuthenticatedGitHubAppInstallationForOwner(Helper.UserName));
}
[GitHubAppsTest]
public async Task GetsAllAnnotations()
{
using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
{
// Create a new feature branch
var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress,
Output = new NewCheckRunOutput("title", "summary")
{
Annotations = new[]
{
new NewCheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning")
}
}
};
var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);
// Get the annotations
var annotations = await _githubAppInstallation.Check.Run.GetAllAnnotations(repoContext.RepositoryOwner, repoContext.RepositoryName, created.Id).ToList();
// Check result
Assert.Equal(1, annotations.Count);
Assert.Equal("this is a warning", annotations.First().Message);
Assert.Equal(CheckWarningLevel.Warning, annotations.First().WarningLevel);
}
}
[GitHubAppsTest]
public async Task GetsAllAnnotationsWithRepositoryId()
{
using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo")) { AutoInit = true }))
{
// Create a new feature branch
var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");
var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");
// Create a check run for the feature branch
var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
{
Status = CheckStatus.InProgress,
Output = new NewCheckRunOutput("title", "summary")
{
Annotations = new[]
{
new NewCheckRunAnnotation("file.txt", "blob", 1, 1, CheckWarningLevel.Warning, "this is a warning")
}
}
};
var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryId, newCheckRun);
// Get the annotations
var annotations = await _githubAppInstallation.Check.Run.GetAllAnnotations(repoContext.RepositoryId, created.Id).ToList();
// Check result
Assert.Equal(1, annotations.Count);
Assert.Equal("this is a warning", annotations.First().Message);
Assert.Equal(CheckWarningLevel.Warning, annotations.First().WarningLevel);
}
}
}
}
}