mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-06 03:55:55 +00:00
Implement Check Suites API (#1846)
* Check run request models * Check Run response models * Check run clients * Check run ApiUrls and AcceptHeaders * Pack it all together for now * Add missing accept headers to connection calls * Standardize class definitions * Standardize function names * Merge ICheckRunAnnotationsClient into ICheckRunsClient * Properly organize clients * Cleanup CheckRun response model * Fix slug check run urls * Add checks installation permission * Use StringEnums where appropriate * Cleanup check run output models * Flesh out CheckSuite model * Delete CheckRunsList * Remove a sealed, fix some line endings * Adding check suite models * Skeleton check suite client implementation * Add check suite ApiUrls * Flesh out check suites client * Add parameterless CheckRun constructor * Add DebuggerDisplay to checks models * Add observable checks interfaces * Add return values to POST and PATCH check clients * Fix some check suite client return values * Skeleton reactive checks implementation * Implement observable checks clients * Remove rogue tabs * Add CheckSuiteEventPayload * Add CheckRunEventPayload * Add DebuggerDisplay attributes to checks API payloads * Properly nullables check suite/run conclusion * Add CheckSuiteEventTests * Fix checks client accessor naming issues * Add missing Text field to CheckRunOutput * Marks CheckRunUpdate's conclusion as nullable * Fix reactive checks client naming * Today I learned DateTimeOffset is a struct Makes CheckRunUpdate's DateTimeOffsets nullable * Modify check clients to put slug version before repo id version * Add nullable to CheckRun.CompletedAt * Implement parameterless ICheckRunsClient.GetAllForReference and GetAllForCheckSuite * Add missing RequestParameters base to CheckSuiteRequest * Implement checks API GetAll methods * Bring parity to Reactive checks clients * fix project settings to get GitHubApp helper working again * remove un-needed InstallationId setting - provide helper method to find installation based on owner * fix up request object ctors based on required/optional parameters * fix up request object ctors based on required/optional parameters * add some initial integration tests for CheckSuites and CheckRuns including some helper methods * Add test for Request CheckSuite Fix Request CheckSuite to use correct Uri Fix Request CheckSuite return type as it doesnt return an object Fix CheckSuiteTriggerRequest ctor to make required fields mandatory * simplify Get CheckSuite test to not require as much data setup * Add test for CheckSuite GetAllForReference * Add test for CheckSuite UpdatePreferences * rename response models * rename CheckSuitesList to CheckSuitesResponse and use as response to the GetAll calls * Fix tests * Fix observable * fix model convention tests * remove CheckRuns so we can focus only on CheckSuites for now * naming things is hard * oh so many unit tests for CheckSuites methods * make client mockable * Fix issue with .Max() when no results returned * fix request parameter names * add Xml doc comments * Add XmlDoc comments to request/common model objects * rename class to match usage * tidy ups * xmldoc for observable clients * fix method order * add observable unit tests and get them passing * Add Observable unit tests and get them passing * add observable integration tests * tidy up ApiUrl method name * whitespace/using tidy ups * Ensure CheckSuiteEventPayload class is handled in deserializer and add to activity test * add response model XmlDoc comments * missed one xmldoc * add xmldoc to NewCheckSuite request and remove HeadBranch property as it doesnt exist anymore * add some extra check suites integration tests
This commit is contained in:
@@ -0,0 +1,373 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Reactive;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
public class ObservableObservableCheckSuitesClientTests
|
||||
{
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new ObservableCheckSuitesClient(null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
client.Get("fake", "repo", 1);
|
||||
|
||||
gitHubClient.Check.Suite.Received().Get("fake", "repo", 1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
client.Get(1, 1);
|
||||
|
||||
gitHubClient.Check.Suite.Received().Get(1, 1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get(null, "repo", 1));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get("fake", null, 1));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Get(null, "repo", 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Get("", "repo", 1));
|
||||
Assert.Throws<ArgumentException>(() => client.Get("fake", "", 1));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllForReferenceMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = new GitHubClient(connection);
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
client.GetAllForReference("fake", "repo", "ref");
|
||||
|
||||
connection.Received().Get<List<CheckSuitesResponse>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits/ref/check-suites"),
|
||||
Args.EmptyDictionary,
|
||||
"application/vnd.github.antiope-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = new GitHubClient(connection);
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
client.GetAllForReference(1, "ref");
|
||||
|
||||
connection.Received().Get<List<CheckSuitesResponse>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repositories/1/commits/ref/check-suites"),
|
||||
Args.EmptyDictionary,
|
||||
"application/vnd.github.antiope-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRequest()
|
||||
{
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = new GitHubClient(connection);
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var request = new CheckSuiteRequest
|
||||
{
|
||||
AppId = 123,
|
||||
CheckName = "build"
|
||||
};
|
||||
|
||||
client.GetAllForReference("fake", "repo", "ref", request);
|
||||
|
||||
connection.Received().Get<List<CheckSuitesResponse>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits/ref/check-suites"),
|
||||
Arg.Is<Dictionary<string, string>>(x =>
|
||||
x["app_id"] == "123"
|
||||
&& x["check_name"] == "build"),
|
||||
"application/vnd.github.antiope-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRequestWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = new GitHubClient(connection);
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var request = new CheckSuiteRequest
|
||||
{
|
||||
AppId = 123,
|
||||
CheckName = "build"
|
||||
};
|
||||
|
||||
client.GetAllForReference(1, "ref", request);
|
||||
|
||||
connection.Received().Get<List<CheckSuitesResponse>>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repositories/1/commits/ref/check-suites"),
|
||||
Arg.Is<Dictionary<string, string>>(x =>
|
||||
x["app_id"] == "123"
|
||||
&& x["check_name"] == "build"),
|
||||
"application/vnd.github.antiope-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var request = new CheckSuiteRequest();
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference(null, "repo", "ref"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference("fake", null, "ref"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference("fake", "repo", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference(null, "repo", "ref", request));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference("fake", null, "ref", request));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference("fake", "repo", null, request));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference("fake", "repo", "ref", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference(null, "repo", "ref", request, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference("fake", null, "ref", request, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference("fake", "repo", null, request, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference("fake", "repo", "ref", null, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference("fake", "repo", "ref", request, null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference(1, null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference(1, null, request));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference(1, "ref", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference(1, null, request, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference(1, "ref", null, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllForReference(1, "ref", request, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var request = new CheckSuiteRequest();
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForReference("", "repo", "ref"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForReference("fake", "", "ref"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForReference("fake", "repo", ""));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForReference("", "repo", "ref", request));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForReference("fake", "", "ref", request));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForReference("fake", "repo", "", request));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForReference("", "repo", "ref", request, ApiOptions.None));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForReference("fake", "", "ref", request, ApiOptions.None));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForReference("fake", "repo", "", request, ApiOptions.None));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForReference(1, ""));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForReference(1, "", request));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForReference(1, "", request, ApiOptions.None));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheUpdatePreferencesMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var preferences = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(123, true) });
|
||||
|
||||
client.UpdatePreferences("fake", "repo", preferences);
|
||||
|
||||
gitHubClient.Check.Suite.Received().UpdatePreferences("fake", "repo", preferences);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var preferences = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(123, true) });
|
||||
|
||||
client.UpdatePreferences(1, preferences);
|
||||
|
||||
gitHubClient.Check.Suite.Received().UpdatePreferences(1, preferences);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var preferences = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(123, true) });
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.UpdatePreferences(null, "repo", preferences));
|
||||
Assert.Throws<ArgumentNullException>(() => client.UpdatePreferences("fake", null, preferences));
|
||||
Assert.Throws<ArgumentNullException>(() => client.UpdatePreferences("fake", "repo", null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var preferences = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(123, true) });
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.UpdatePreferences("", "repo", preferences));
|
||||
Assert.Throws<ArgumentException>(() => client.UpdatePreferences("fake", "", preferences));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var newCheckSuite = new NewCheckSuite("123abc");
|
||||
|
||||
client.Create("fake", "repo", newCheckSuite);
|
||||
|
||||
gitHubClient.Check.Suite.Received().Create("fake", "repo", newCheckSuite);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var newCheckSuite = new NewCheckSuite("123abc");
|
||||
|
||||
client.Create(1, newCheckSuite);
|
||||
|
||||
gitHubClient.Check.Suite.Received().Create(1, newCheckSuite);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var newCheckSuite = new NewCheckSuite("123abc");
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create(null, "repo", newCheckSuite));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("fake", null, newCheckSuite));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("fake", "repo", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create(1, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var newCheckSuite = new NewCheckSuite("123abc");
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Create("", "repo", newCheckSuite));
|
||||
Assert.Throws<ArgumentException>(() => client.Create("fake", "", newCheckSuite));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheRequestMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var request = new CheckSuiteTriggerRequest("123abc");
|
||||
|
||||
client.Request("fake", "repo", request);
|
||||
|
||||
gitHubClient.Check.Suite.Received().Request("fake", "repo", request);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var request = new CheckSuiteTriggerRequest("123abc");
|
||||
|
||||
client.Request(1, request);
|
||||
|
||||
gitHubClient.Check.Suite.Received().Request(1, request);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var request = new CheckSuiteTriggerRequest("123abc");
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Request(null, "repo", request));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Request("fake", null, request));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Request("fake", "repo", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Request(1, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCheckSuitesClient(gitHubClient);
|
||||
|
||||
var request = new CheckSuiteTriggerRequest("123abc");
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Request("", "repo", request));
|
||||
Assert.Throws<ArgumentException>(() => client.Request("fake", "", request));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user