From b866d669d664e2726a5cd9e6ad985a382e800f64 Mon Sep 17 00:00:00 2001 From: Chris Simpson Date: Fri, 12 Aug 2022 18:21:36 +0100 Subject: [PATCH] feat: Adding seats and filled seats to plan response. (#2539) --- .../Clients/OrganizationClientTests.cs | 46 ++++++++++++------- Octokit/Models/Response/Plan.cs | 31 ++++++++----- 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/OrganizationClientTests.cs b/Octokit.Tests.Integration/Clients/OrganizationClientTests.cs index 1ca0e804c9..8faabf581d 100644 --- a/Octokit.Tests.Integration/Clients/OrganizationClientTests.cs +++ b/Octokit.Tests.Integration/Clients/OrganizationClientTests.cs @@ -8,19 +8,12 @@ public class OrganizationClientTests { public class TheGetAllMethod { - readonly IGitHubClient _github; - readonly IOrganizationsClient _organizationsClient; - - public TheGetAllMethod() - { - _github = EnterpriseHelper.GetAuthenticatedClient(); - - _organizationsClient = _github.Organization; - } - [GitHubEnterpriseTest] public async Task CanListAllOrganizations() { + var github = EnterpriseHelper.GetAuthenticatedClient(); + var organizationsClient = github.Organization; + string orgLogin1 = Helper.MakeNameWithTimestamp("MyOrganization1"); string orgName1 = string.Concat(orgLogin1, " Display Name 1"); string orgLogin2 = Helper.MakeNameWithTimestamp("MyOrganization2"); @@ -28,10 +21,10 @@ public async Task CanListAllOrganizations() var newOrganization1 = new NewOrganization(orgLogin1, EnterpriseHelper.UserName, orgName1); var newOrganization2 = new NewOrganization(orgLogin2, EnterpriseHelper.UserName, orgName2); - await _github.Enterprise.Organization.Create(newOrganization1); - await _github.Enterprise.Organization.Create(newOrganization2); + await github.Enterprise.Organization.Create(newOrganization1); + await github.Enterprise.Organization.Create(newOrganization2); - var organizations = await _organizationsClient.GetAll(); + var organizations = await organizationsClient.GetAll(); Assert.Contains(organizations, (org => org.Login == orgLogin1)); Assert.Contains(organizations, (org => org.Login == orgLogin2)); @@ -40,6 +33,9 @@ public async Task CanListAllOrganizations() [GitHubEnterpriseTest] public async Task ReturnsCorrectOrganizationsWithSince() { + var github = EnterpriseHelper.GetAuthenticatedClient(); + var organizationsClient = github.Organization; + string orgLogin1 = Helper.MakeNameWithTimestamp("MyOrganization1"); string orgName1 = string.Concat(orgLogin1, " Display Name 1"); string orgLogin2 = Helper.MakeNameWithTimestamp("MyOrganization2"); @@ -51,13 +47,13 @@ public async Task ReturnsCorrectOrganizationsWithSince() var newOrganization2 = new NewOrganization(orgLogin2, EnterpriseHelper.UserName, orgName2); var newOrganization3 = new NewOrganization(orgLogin3, EnterpriseHelper.UserName, orgName3); - var createdOrganization1 = await _github.Enterprise.Organization.Create(newOrganization1); - var createdOrganization2 = await _github.Enterprise.Organization.Create(newOrganization2); - var createdOrganization3 = await _github.Enterprise.Organization.Create(newOrganization3); + var createdOrganization1 = await github.Enterprise.Organization.Create(newOrganization1); + var createdOrganization2 = await github.Enterprise.Organization.Create(newOrganization2); + var createdOrganization3 = await github.Enterprise.Organization.Create(newOrganization3); var requestParameter = new OrganizationRequest(createdOrganization1.Id); - var organizations = await _organizationsClient.GetAll(requestParameter); + var organizations = await organizationsClient.GetAll(requestParameter); Assert.DoesNotContain(organizations, (org => org.Login == orgLogin1)); Assert.Contains(organizations, (org => org.Login == orgLogin2)); @@ -65,6 +61,22 @@ public async Task ReturnsCorrectOrganizationsWithSince() } } + public class TheGetMethod + { + [IntegrationTest] + [PotentiallyFlakyTest] + public async Task GetFreeOrganization() + { + var github = Helper.GetAuthenticatedClient(); + + var organization = await + github.Organization.Get("snyrting6orggithub"); + + Assert.Equal(0, organization.Plan.Seats); + Assert.Equal(1, organization.Plan.FilledSeats); + } + } + public class TheGetAllForCurrentMethod { readonly IGitHubClient _github; diff --git a/Octokit/Models/Response/Plan.cs b/Octokit/Models/Response/Plan.cs index f5de2a8b3b..336dc1baca 100644 --- a/Octokit/Models/Response/Plan.cs +++ b/Octokit/Models/Response/Plan.cs @@ -1,5 +1,5 @@ +using Octokit.Internal; using System.Diagnostics; -using System.Globalization; namespace Octokit { @@ -11,46 +11,55 @@ public class Plan { public Plan() { } - public Plan(long collaborators, string name, long privateRepos, long space, string billingEmail) + public Plan(long collaborators, string name, long privateRepos, long space, string billingEmail, int filledSeats, int seats) { Collaborators = collaborators; Name = name; PrivateRepos = privateRepos; Space = space; BillingEmail = billingEmail; + FilledSeats = filledSeats; + Seats = seats; } /// /// The number of collaborators allowed with this plan. /// /// This returns because GitHub Enterprise uses a sentinel value of 999999999999 to denote an "unlimited" number of collaborators. - public long Collaborators { get; protected set; } + public long Collaborators { get; private set; } /// /// The name of the plan. /// - public string Name { get; protected set; } + public string Name { get; private set; } /// /// The number of private repositories allowed with this plan. /// /// This returns because GitHub Enterprise uses a sentinel value of 999999999999 to denote an "unlimited" number of plans. - public long PrivateRepos { get; protected set; } + public long PrivateRepos { get; private set; } /// /// The amount of disk space allowed with this plan. /// /// This returns because GitHub Enterprise uses a sentinel value of 999999999999 to denote an "unlimited" amount of disk space. - public long Space { get; protected set; } + public long Space { get; private set; } /// /// The billing email for the organization. Only has a value in response to editing an organization. /// - public string BillingEmail { get; protected set; } + public string BillingEmail { get; private set; } - internal string DebuggerDisplay - { - get { return string.Format(CultureInfo.InvariantCulture, "Name: {0}, Space: {1}, Private Repos: {2}, Collaborators: {3}", Name, Space, PrivateRepos, Collaborators); } - } + /// + /// The number of seats filled on this plan + /// + public int FilledSeats { get; private set; } + + /// + /// The number of seats available for this plan + /// + public int Seats { get; private set; } + + internal string DebuggerDisplay => new SimpleJsonSerializer().Serialize(this); } }