mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
[FEAT]: Adding Copilot for Business support (#2826)
* initial tests and implementation of Copilot for Business client API * updated billing settings documentation * renames and refactors - clarity and simplified * using context to ensure license clean up * extra documentation and used ApiOptions instead of custom class * implemented observable clients * Fixing convention issues * renaming for clarity --------- Co-authored-by: Nick Floyd <139819+nickfloyd@users.noreply.github.com>
This commit is contained in:
114
Octokit.Tests/Clients/Copilot/CopilotClientTests.cs
Normal file
114
Octokit.Tests/Clients/Copilot/CopilotClientTests.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
public class CopilotClientTests
|
||||
{
|
||||
private const string orgName = "test";
|
||||
|
||||
public class TheGetCopilotBillingSettingsMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CopilotClient(connection);
|
||||
|
||||
var expectedUri = $"orgs/{orgName}/copilot/billing";
|
||||
client.GetSummaryForOrganization("test");
|
||||
|
||||
connection.Received().Get<BillingSettings>(Arg.Is<Uri>(u => u.ToString() == expectedUri));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllCopilotLicensesMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CopilotClient(connection);
|
||||
|
||||
var expectedUri = $"orgs/{orgName}/copilot/billing/seats";
|
||||
client.Licensing.GetAll("test", new ApiOptions());
|
||||
|
||||
connection.Received().GetAll<CopilotSeats>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<ApiOptions>());
|
||||
}
|
||||
}
|
||||
|
||||
public class TheAssignCopilotLicenseMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CopilotClient(connection);
|
||||
var expectedUri = $"orgs/{orgName}/copilot/billing/selected_users";
|
||||
|
||||
client.Licensing.Assign(orgName, "copilot-user");
|
||||
|
||||
connection.Received().Post<CopilotSeatAllocation>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<UserSeatAllocation>());
|
||||
}
|
||||
}
|
||||
|
||||
public class TheAssignCopilotLicensesMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CopilotClient(connection);
|
||||
var expectedUri = $"orgs/{orgName}/copilot/billing/selected_users";
|
||||
|
||||
var payloadData = new UserSeatAllocation() { SelectedUsernames = new[] { "copilot-user" } };
|
||||
client.Licensing.Assign(orgName, payloadData);
|
||||
|
||||
connection.Received().Post<CopilotSeatAllocation>(Arg.Is<Uri>(u => u.ToString() == expectedUri), payloadData);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheRemoveCopilotLicenseMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CopilotClient(connection);
|
||||
var expectedUri = $"orgs/{orgName}/copilot/billing/selected_users";
|
||||
|
||||
client.Licensing.Remove(orgName, "copilot-user" );
|
||||
|
||||
connection.Received().Delete<CopilotSeatAllocation>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<UserSeatAllocation>());
|
||||
}
|
||||
}
|
||||
|
||||
public class TheRemoveCopilotLicensesMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new CopilotClient(connection);
|
||||
var expectedUri = $"orgs/{orgName}/copilot/billing/selected_users";
|
||||
|
||||
var payloadData = new UserSeatAllocation() { SelectedUsernames = new[] { "copilot-user" } };
|
||||
client.Licensing.Remove(orgName, payloadData);
|
||||
|
||||
connection.Received().Delete<CopilotSeatAllocation>(Arg.Is<Uri>(u => u.ToString() == expectedUri), payloadData);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(
|
||||
() => new CopilotClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
116
Octokit.Tests/Reactive/Copilot/ObservableCopilotClientTests.cs
Normal file
116
Octokit.Tests/Reactive/Copilot/ObservableCopilotClientTests.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NSubstitute;
|
||||
using Octokit.Reactive;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Reactive
|
||||
{
|
||||
public class ObservableCopilotClientTests
|
||||
{
|
||||
private const string orgName = "test";
|
||||
|
||||
public class TheGetCopilotBillingSettingsMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var githubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCopilotClient(githubClient);
|
||||
|
||||
client.GetSummaryForOrganization("test");
|
||||
|
||||
githubClient.Copilot.Received(1).GetSummaryForOrganization(orgName);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllCopilotLicensesMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var endpoint = new Uri($"orgs/test/copilot/billing/seats", UriKind.Relative);
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
gitHubClient.Connection.Returns(connection);
|
||||
var client = new ObservableCopilotClient(gitHubClient);
|
||||
|
||||
var apiOptions = new ApiOptions() { PageSize = 50, PageCount = 10 };
|
||||
client.Licensing.GetAll("test", apiOptions);
|
||||
|
||||
connection.Received().Get<List<CopilotSeats>>(endpoint,
|
||||
Arg.Is<IDictionary<string, string>>(d => d.Count > 0));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheAssignCopilotLicenseMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var githubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCopilotClient(githubClient);
|
||||
const string expectedUser = "copilot-user";
|
||||
|
||||
client.Licensing.Assign(orgName, expectedUser);
|
||||
|
||||
githubClient.Copilot.Licensing.Received().Assign(orgName, expectedUser);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheAssignCopilotLicensesMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var githubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCopilotClient(githubClient);
|
||||
|
||||
var payloadData = new UserSeatAllocation() { SelectedUsernames = new[] { "copilot-user" } };
|
||||
client.Licensing.Assign(orgName, payloadData);
|
||||
|
||||
githubClient.Copilot.Licensing.Received().Assign(orgName, payloadData);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheRemoveCopilotLicenseMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var githubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCopilotClient(githubClient);
|
||||
const string expectedUser = "copilot-user";
|
||||
|
||||
client.Licensing.Remove(orgName, expectedUser);
|
||||
|
||||
githubClient.Copilot.Licensing.Received().Remove(orgName, expectedUser);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheRemoveCopilotLicensesMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var githubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableCopilotClient(githubClient);
|
||||
|
||||
var payloadData = new UserSeatAllocation() { SelectedUsernames = new[] { "copilot-user" } };
|
||||
client.Licensing.Remove(orgName, payloadData);
|
||||
|
||||
githubClient.Copilot.Licensing.Received().Remove(orgName, payloadData);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(
|
||||
() => new ObservableCopilotClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user