mirror of
https://github.com/bitwarden/server
synced 2025-12-15 07:43:54 +00:00
Billing/pm 27217/update secrets manager test fix (#6478)
* fix(billing): Add comments for clarity * fix(billing): Update generated properties for test
This commit is contained in:
@@ -226,7 +226,11 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
|
|||||||
// Check minimum seats currently in use by the organization
|
// Check minimum seats currently in use by the organization
|
||||||
if (organization.SmSeats.Value > update.SmSeats.Value)
|
if (organization.SmSeats.Value > update.SmSeats.Value)
|
||||||
{
|
{
|
||||||
|
// Retrieve the number of currently occupied Secrets Manager seats for the organization.
|
||||||
var occupiedSeats = await _organizationUserRepository.GetOccupiedSmSeatCountByOrganizationIdAsync(organization.Id);
|
var occupiedSeats = await _organizationUserRepository.GetOccupiedSmSeatCountByOrganizationIdAsync(organization.Id);
|
||||||
|
|
||||||
|
// Check if the occupied number of seats exceeds the updated seat count.
|
||||||
|
// If so, throw an exception indicating that the subscription cannot be decreased below the current usage.
|
||||||
if (occupiedSeats > update.SmSeats.Value)
|
if (occupiedSeats > update.SmSeats.Value)
|
||||||
{
|
{
|
||||||
throw new BadRequestException($"{occupiedSeats} users are currently occupying Secrets Manager seats. " +
|
throw new BadRequestException($"{occupiedSeats} users are currently occupying Secrets Manager seats. " +
|
||||||
@@ -412,7 +416,7 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Requests the number of Secret Manager seats and service accounts are currently used by the organization
|
/// Requests the number of Secret Manager seats and service accounts currently used by the organization
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="organizationId"> The id of the organization</param>
|
/// <param name="organizationId"> The id of the organization</param>
|
||||||
/// <returns > A tuple containing the occupied seats and the occupied service account counts</returns>
|
/// <returns > A tuple containing the occupied seats and the occupied service account counts</returns>
|
||||||
|
|||||||
@@ -278,21 +278,27 @@ public class UpdateSecretsManagerSubscriptionCommandTests
|
|||||||
SutProvider<UpdateSecretsManagerSubscriptionCommand> sutProvider)
|
SutProvider<UpdateSecretsManagerSubscriptionCommand> sutProvider)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
const int seatCount = 10;
|
|
||||||
var existingSeatCount = 9;
|
|
||||||
|
|
||||||
// Make sure Password Manager seats is greater or equal to Secrets Manager seats
|
// Make sure Password Manager seats is greater or equal to Secrets Manager seats
|
||||||
organization.Seats = seatCount;
|
const int initialSeatCount = 9;
|
||||||
|
const int maxSeatCount = 20;
|
||||||
|
// This represents the total number of users allowed in the organization.
|
||||||
|
organization.Seats = maxSeatCount;
|
||||||
|
// This represents the number of Secrets Manager users allowed in the organization.
|
||||||
|
organization.SmSeats = initialSeatCount;
|
||||||
|
// This represents the upper limit of Secrets Manager seats that can be automatically scaled.
|
||||||
|
organization.MaxAutoscaleSmSeats = maxSeatCount;
|
||||||
|
|
||||||
|
organization.PlanType = PlanType.EnterpriseAnnually;
|
||||||
var plan = StaticStore.GetPlan(organization.PlanType);
|
var plan = StaticStore.GetPlan(organization.PlanType);
|
||||||
|
|
||||||
var update = new SecretsManagerSubscriptionUpdate(organization, plan, false)
|
var update = new SecretsManagerSubscriptionUpdate(organization, plan, false)
|
||||||
{
|
{
|
||||||
SmSeats = seatCount,
|
SmSeats = 8,
|
||||||
MaxAutoscaleSmSeats = seatCount
|
MaxAutoscaleSmSeats = maxSeatCount
|
||||||
};
|
};
|
||||||
sutProvider.GetDependency<IOrganizationUserRepository>()
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
.GetOccupiedSmSeatCountByOrganizationIdAsync(organization.Id)
|
.GetOccupiedSmSeatCountByOrganizationIdAsync(organization.Id)
|
||||||
.Returns(existingSeatCount);
|
.Returns(5);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await sutProvider.Sut.UpdateSubscriptionAsync(update);
|
await sutProvider.Sut.UpdateSubscriptionAsync(update);
|
||||||
@@ -316,21 +322,29 @@ public class UpdateSecretsManagerSubscriptionCommandTests
|
|||||||
SutProvider<UpdateSecretsManagerSubscriptionCommand> sutProvider)
|
SutProvider<UpdateSecretsManagerSubscriptionCommand> sutProvider)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
const int seatCount = 10;
|
const int initialSeatCount = 5;
|
||||||
const int existingSeatCount = 10;
|
const int maxSeatCount = 10;
|
||||||
var ownerDetailsList = new List<OrganizationUserUserDetails> { new() { Email = "owner@example.com" } };
|
|
||||||
|
|
||||||
// The amount of seats for users in an organization
|
// This represents the total number of users allowed in the organization.
|
||||||
|
organization.Seats = maxSeatCount;
|
||||||
|
// This represents the number of Secrets Manager users allowed in the organization.
|
||||||
|
organization.SmSeats = initialSeatCount;
|
||||||
|
// This represents the upper limit of Secrets Manager seats that can be automatically scaled.
|
||||||
|
organization.MaxAutoscaleSmSeats = maxSeatCount;
|
||||||
|
|
||||||
|
var ownerDetailsList = new List<OrganizationUserUserDetails> { new() { Email = "owner@example.com" } };
|
||||||
|
organization.PlanType = PlanType.EnterpriseAnnually;
|
||||||
var plan = StaticStore.GetPlan(organization.PlanType);
|
var plan = StaticStore.GetPlan(organization.PlanType);
|
||||||
|
|
||||||
var update = new SecretsManagerSubscriptionUpdate(organization, plan, false)
|
var update = new SecretsManagerSubscriptionUpdate(organization, plan, false)
|
||||||
{
|
{
|
||||||
SmSeats = seatCount,
|
SmSeats = maxSeatCount,
|
||||||
MaxAutoscaleSmSeats = seatCount
|
MaxAutoscaleSmSeats = maxSeatCount
|
||||||
};
|
};
|
||||||
|
|
||||||
sutProvider.GetDependency<IOrganizationUserRepository>()
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
.GetOccupiedSmSeatCountByOrganizationIdAsync(organization.Id)
|
.GetOccupiedSmSeatCountByOrganizationIdAsync(organization.Id)
|
||||||
.Returns(existingSeatCount);
|
.Returns(maxSeatCount);
|
||||||
sutProvider.GetDependency<IOrganizationUserRepository>()
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
.GetManyByMinimumRoleAsync(organization.Id, OrganizationUserType.Owner)
|
.GetManyByMinimumRoleAsync(organization.Id, OrganizationUserType.Owner)
|
||||||
.Returns(ownerDetailsList);
|
.Returns(ownerDetailsList);
|
||||||
@@ -340,15 +354,14 @@ public class UpdateSecretsManagerSubscriptionCommandTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
|
||||||
// Currently being called once each for different validation methods
|
|
||||||
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
await sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
.Received(2)
|
.Received(1)
|
||||||
.GetOccupiedSmSeatCountByOrganizationIdAsync(organization.Id);
|
.GetOccupiedSmSeatCountByOrganizationIdAsync(organization.Id);
|
||||||
|
|
||||||
await sutProvider.GetDependency<IMailService>()
|
await sutProvider.GetDependency<IMailService>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.SendSecretsManagerMaxSeatLimitReachedEmailAsync(Arg.Is(organization),
|
.SendSecretsManagerMaxSeatLimitReachedEmailAsync(Arg.Is(organization),
|
||||||
Arg.Is(seatCount),
|
Arg.Is(maxSeatCount),
|
||||||
Arg.Is<IEnumerable<string>>(emails => emails.Contains(ownerDetailsList[0].Email)));
|
Arg.Is<IEnumerable<string>>(emails => emails.Contains(ownerDetailsList[0].Email)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user