[AC-1568] Finish refactor of update subscription interface, minor fixes (#3189)
* Remove UpdateSecretsManagerSubscriptionCommand.AdjustServiceAccounts interface
* Rewrite tests and use autofixture customizations
* Reduce method nesting in the command, simplify parameters
* Fix capitalization and wording of error messages
* Add checks for existing SM beta enrolment etc
@ -14,11 +14,12 @@ public class SecretsManagerSubscriptionUpdateRequestModel
@@ -14,11 +14,12 @@ public class SecretsManagerSubscriptionUpdateRequestModel
@ -62,6 +62,17 @@ public class AddSecretsManagerSubscriptionCommand : IAddSecretsManagerSubscripti
@@ -62,6 +62,17 @@ public class AddSecretsManagerSubscriptionCommand : IAddSecretsManagerSubscripti
thrownewNotFoundException();
}
if(organization.SecretsManagerBeta)
{
thrownewBadRequestException("Organization is enrolled in Secrets Manager Beta. "+
"Please contact Customer Success to add Secrets Manager to your subscription.");
@ -51,82 +49,46 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@@ -51,82 +49,46 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@ -134,16 +96,16 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@@ -134,16 +96,16 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@ -151,12 +113,12 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@@ -151,12 +113,12 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
_logger.LogError(e,$"Error encountered notifying organization owners of Service Accounts limit reached.");
_logger.LogError(e,$"Error encountered notifying organization owners of service accounts limit reached.");
}
}
@ -171,46 +133,45 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@@ -171,46 +133,45 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
thrownewNotFoundException("Organization is not found.");
}
varorganization=update.Organization;
if(!organization.UseSecretsManager)
{
thrownewBadRequestException("Organization has no access to Secrets Manager.");
}
varplan=GetPlanForOrganization(organization);
if(plan.Product==ProductType.Free)
if(organization.SecretsManagerBeta)
{
thrownewBadRequestException("Organization is enrolled in Secrets Manager Beta. "+
"Please contact Customer Success to add Secrets Manager to your subscription.");
}
if(update.Plan.Product==ProductType.Free)
{
// No need to check the organization is set up with Stripe
return;
@ -227,18 +188,11 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@@ -227,18 +188,11 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@ -282,21 +236,24 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@@ -282,21 +236,24 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
// Check minimum seats currently in use by the organization
@ -326,13 +283,13 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@@ -326,13 +283,13 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
// Check minimum service accounts included with plan
thrownewBadRequestException($"Plan has a minimum of {plan.BaseServiceAccount} Service Accounts.");
thrownewBadRequestException($"Plan has a minimum of {plan.BaseServiceAccount} service accounts.");
}
// Check minimum service accounts required by business logic
if(update.SmServiceAccounts.Value<=0)
{
thrownewBadRequestException("You must have at least 1 Service Account.");
thrownewBadRequestException("You must have at least 1 service account.");
}
// Check minimum service accounts currently in use by the organization
@ -341,30 +298,32 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@@ -341,30 +298,32 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
$"Your plan has a Secrets Manager seat limit of {plan.MaxUsers}, ",
$"but you have specified a max autoscale count of {maxAutoscaleSeats}.",
$"but you have specified a max autoscale count of {update.MaxAutoscaleSmSeats}.",
"Reduce your max autoscale count."));
}
@ -374,30 +333,32 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@@ -374,30 +333,32 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs
@ -1418,8 +1418,8 @@ public class OrganizationService : IOrganizationService
@@ -1418,8 +1418,8 @@ public class OrganizationService : IOrganizationService
@ -137,6 +137,7 @@ public class SecretsManagerOrganizationCustomization : ICustomization
@@ -137,6 +137,7 @@ public class SecretsManagerOrganizationCustomization : ICustomization
@ -125,8 +125,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -125,8 +125,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@ -151,6 +150,23 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -151,6 +150,23 @@ public class UpdateSecretsManagerSubscriptionCommandTests
Assert.Contains("Organization is enrolled in Secrets Manager Beta",exception.Message);
awaitVerifyDependencyNotCalledAsync(sutProvider);
}
[Theory]
[BitAutoData(PlanType.EnterpriseAnnually)]
[BitAutoData(PlanType.EnterpriseMonthly)]
@ -163,8 +179,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -163,8 +179,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@ -183,8 +198,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -183,8 +198,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@ -223,8 +237,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -223,8 +237,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@ -247,7 +260,6 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -247,7 +260,6 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@ -267,8 +279,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -267,8 +279,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@ -283,8 +294,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -283,8 +294,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
Assert.Contains("Cannot use autoscaling to subtract seats.",exception.Message);
@ -299,8 +309,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -299,8 +309,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
Assert.Contains("You have reached the maximum number of Secrets Manager seats (2) for this plan",
@ -317,8 +326,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -317,8 +326,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
Assert.Contains("Secrets Manager seat limit has been reached.",exception.Message);
@ -375,7 +383,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -375,7 +383,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
Assert.Contains("Your organization currently has 8 Secrets Manager seats. Your plan only allows 7 Secrets Manager seats. Remove some Secrets Manager users",exception.Message);
Assert.Contains("8 users are currently occupying Secrets Manager seats. You cannot decrease your subscription below your current occupied seat count",exception.Message);
awaitVerifyDependencyNotCalledAsync(sutProvider);
}
@ -385,7 +393,6 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -385,7 +393,6 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@ -405,11 +412,10 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -405,11 +412,10 @@ public class UpdateSecretsManagerSubscriptionCommandTests
Assert.Contains("Organization has no Service Accounts limit, no need to adjust Service Accounts",exception.Message);
Assert.Contains("Organization has no service accounts limit, no need to adjust service accounts",exception.Message);
awaitVerifyDependencyNotCalledAsync(sutProvider);
}
@ -419,8 +425,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -419,8 +425,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
Assert.Contains("Cannot use autoscaling to subtract service accounts.",exception.Message);
@ -435,8 +440,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -435,8 +440,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
Assert.Contains("You have reached the maximum number of service accounts (3) for this plan",
@ -453,8 +457,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -453,8 +457,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
Assert.Contains("Secrets Manager service account limit has been reached.",exception.Message);
@ -492,7 +495,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -492,7 +495,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
Assert.Contains("Plan has a minimum of 200 Service Accounts",exception.Message);
Assert.Contains("Plan has a minimum of 200 service accounts",exception.Message);
awaitVerifyDependencyNotCalledAsync(sutProvider);
}
@ -516,7 +519,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -516,7 +519,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
Assert.Contains("Your organization currently has 301 Service Accounts. Your plan only allows 201 Service Accounts. Remove some Service Accounts",exception.Message);
Assert.Contains("Your organization currently has 301 service accounts. You cannot decrease your subscription below your current service account usage",exception.Message);
awaitVerifyDependencyNotCalledAsync(sutProvider);
}
@ -588,7 +591,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests
@@ -588,7 +591,7 @@ public class UpdateSecretsManagerSubscriptionCommandTests