diff --git a/src/Api/Billing/Controllers/ProviderClientsController.cs b/src/Api/Billing/Controllers/ProviderClientsController.cs index 6f7bd809f..a47ab568b 100644 --- a/src/Api/Billing/Controllers/ProviderClientsController.cs +++ b/src/Api/Billing/Controllers/ProviderClientsController.cs @@ -133,10 +133,17 @@ public class ProviderClientsController( return TypedResults.Problem(); } - await assignSeatsToClientOrganizationCommand.AssignSeatsToClientOrganization( - provider, - clientOrganization, - requestBody.AssignedSeats); + if (clientOrganization.Seats != requestBody.AssignedSeats) + { + await assignSeatsToClientOrganizationCommand.AssignSeatsToClientOrganization( + provider, + clientOrganization, + requestBody.AssignedSeats); + } + + clientOrganization.Name = requestBody.Name; + + await organizationRepository.ReplaceAsync(clientOrganization); return TypedResults.Ok(); } diff --git a/src/Api/Billing/Models/Requests/UpdateClientOrganizationRequestBody.cs b/src/Api/Billing/Models/Requests/UpdateClientOrganizationRequestBody.cs index c6e04aa79..6ed1083b4 100644 --- a/src/Api/Billing/Models/Requests/UpdateClientOrganizationRequestBody.cs +++ b/src/Api/Billing/Models/Requests/UpdateClientOrganizationRequestBody.cs @@ -7,4 +7,7 @@ public class UpdateClientOrganizationRequestBody [Required] [Range(0, int.MaxValue, ErrorMessage = "You cannot assign negative seats to a client organization.")] public int AssignedSeats { get; set; } + + [Required] + public string Name { get; set; } } diff --git a/test/Api.Test/Billing/Controllers/ProviderClientsControllerTests.cs b/test/Api.Test/Billing/Controllers/ProviderClientsControllerTests.cs index b6acb73e4..e0c9a27a6 100644 --- a/test/Api.Test/Billing/Controllers/ProviderClientsControllerTests.cs +++ b/test/Api.Test/Billing/Controllers/ProviderClientsControllerTests.cs @@ -301,7 +301,7 @@ public class ProviderClientsControllerTests } [Theory, BitAutoData] - public async Task UpdateAsync_NoContent( + public async Task UpdateAsync_AssignedSeats_NoContent( Guid providerId, Guid providerOrganizationId, UpdateClientOrganizationRequestBody requestBody, @@ -333,6 +333,50 @@ public class ProviderClientsControllerTests organization, requestBody.AssignedSeats); + await sutProvider.GetDependency().Received(1) + .ReplaceAsync(Arg.Is(org => org.Name == requestBody.Name)); + + Assert.IsType(result); + } + + [Theory, BitAutoData] + public async Task UpdateAsync_Name_NoContent( + Guid providerId, + Guid providerOrganizationId, + UpdateClientOrganizationRequestBody requestBody, + Provider provider, + ProviderOrganization providerOrganization, + Organization organization, + SutProvider sutProvider) + { + sutProvider.GetDependency().IsEnabled(FeatureFlagKeys.EnableConsolidatedBilling) + .Returns(true); + + sutProvider.GetDependency().ProviderProviderAdmin(providerId) + .Returns(true); + + sutProvider.GetDependency().GetByIdAsync(providerId) + .Returns(provider); + + sutProvider.GetDependency().GetByIdAsync(providerOrganizationId) + .Returns(providerOrganization); + + sutProvider.GetDependency().GetByIdAsync(providerOrganization.OrganizationId) + .Returns(organization); + + requestBody.AssignedSeats = organization.Seats!.Value; + + var result = await sutProvider.Sut.UpdateAsync(providerId, providerOrganizationId, requestBody); + + await sutProvider.GetDependency().DidNotReceiveWithAnyArgs() + .AssignSeatsToClientOrganization( + Arg.Any(), + Arg.Any(), + Arg.Any()); + + await sutProvider.GetDependency().Received(1) + .ReplaceAsync(Arg.Is(org => org.Name == requestBody.Name)); + Assert.IsType(result); } #endregion