2023-11-29 09:18:08 +10:00
|
|
|
|
using Bit.Core.AdminConsole.Entities;
|
2024-06-14 15:34:47 -04:00
|
|
|
|
using Bit.Core.Billing.Enums;
|
2023-08-22 09:55:39 +10:00
|
|
|
|
using Bit.Core.Exceptions;
|
|
|
|
|
|
using Bit.Core.Models.Business;
|
2025-02-27 07:55:46 -05:00
|
|
|
|
using Bit.Core.Models.StaticStore;
|
2023-08-22 09:55:39 +10:00
|
|
|
|
using Bit.Core.Test.AutoFixture.OrganizationFixtures;
|
2025-02-27 07:55:46 -05:00
|
|
|
|
using Bit.Core.Utilities;
|
2023-08-22 09:55:39 +10:00
|
|
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.Test.Models.Business;
|
|
|
|
|
|
|
|
|
|
|
|
[SecretsManagerOrganizationCustomize]
|
|
|
|
|
|
public class SecretsManagerSubscriptionUpdateTests
|
|
|
|
|
|
{
|
2025-02-27 07:55:46 -05:00
|
|
|
|
private static TheoryData<Plan> ToPlanTheory(List<PlanType> types)
|
|
|
|
|
|
{
|
|
|
|
|
|
var theoryData = new TheoryData<Plan>();
|
|
|
|
|
|
var plans = types.Select(StaticStore.GetPlan).ToArray();
|
|
|
|
|
|
theoryData.AddRange(plans);
|
|
|
|
|
|
return theoryData;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static TheoryData<Plan> NonSmPlans =>
|
|
|
|
|
|
ToPlanTheory([PlanType.Custom, PlanType.FamiliesAnnually, PlanType.FamiliesAnnually2019]);
|
|
|
|
|
|
|
|
|
|
|
|
public static TheoryData<Plan> SmPlans => ToPlanTheory([
|
|
|
|
|
|
PlanType.EnterpriseAnnually2019,
|
|
|
|
|
|
PlanType.EnterpriseAnnually,
|
|
|
|
|
|
PlanType.TeamsMonthly2019,
|
|
|
|
|
|
PlanType.TeamsAnnually2020,
|
|
|
|
|
|
PlanType.TeamsMonthly,
|
|
|
|
|
|
PlanType.TeamsAnnually2019,
|
|
|
|
|
|
PlanType.TeamsAnnually2020,
|
|
|
|
|
|
PlanType.TeamsAnnually,
|
|
|
|
|
|
PlanType.TeamsStarter
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
2023-08-22 09:55:39 +10:00
|
|
|
|
[Theory]
|
2025-02-27 07:55:46 -05:00
|
|
|
|
[BitMemberAutoData(nameof(NonSmPlans))]
|
2023-11-01 08:43:35 -04:00
|
|
|
|
public Task UpdateSubscriptionAsync_WithNonSecretsManagerPlanType_ThrowsBadRequestException(
|
2025-02-27 07:55:46 -05:00
|
|
|
|
Plan plan,
|
2023-11-01 08:43:35 -04:00
|
|
|
|
Organization organization)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
2025-02-27 07:55:46 -05:00
|
|
|
|
organization.PlanType = plan.Type;
|
2023-11-01 08:43:35 -04:00
|
|
|
|
|
|
|
|
|
|
// Act
|
2025-02-27 07:55:46 -05:00
|
|
|
|
var exception = Assert.Throws<NotFoundException>(() => new SecretsManagerSubscriptionUpdate(organization, plan, false));
|
2023-11-01 08:43:35 -04:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.Contains("Invalid Secrets Manager plan", exception.Message, StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Theory]
|
2025-02-27 07:55:46 -05:00
|
|
|
|
[BitMemberAutoData(nameof(SmPlans))]
|
2023-11-01 08:43:35 -04:00
|
|
|
|
public void UpdateSubscription_WithNonSecretsManagerPlanType_DoesNotThrowException(
|
2025-02-27 07:55:46 -05:00
|
|
|
|
Plan plan,
|
2023-08-22 09:55:39 +10:00
|
|
|
|
Organization organization)
|
|
|
|
|
|
{
|
2023-11-01 08:43:35 -04:00
|
|
|
|
// Arrange
|
2025-02-27 07:55:46 -05:00
|
|
|
|
organization.PlanType = plan.Type;
|
2023-08-22 09:55:39 +10:00
|
|
|
|
|
2023-11-01 08:43:35 -04:00
|
|
|
|
// Act
|
2025-02-27 07:55:46 -05:00
|
|
|
|
var ex = Record.Exception(() => new SecretsManagerSubscriptionUpdate(organization, plan, false));
|
2023-11-01 08:43:35 -04:00
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.Null(ex);
|
2023-08-22 09:55:39 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|