1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-28 13:15:12 +01:00
bitwarden-server/test/Core.Test/Models/Business/StorageSubscriptionUpdateTests.cs
cyprain-okeke f94ddb2a90
[BEEEP][AC-2497] Create unit test for the SubscriptionUpdate classes (#4054)
* Add unit tests for the StorageSubscriptionUpdateTests.cs

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

* remove unwanted comment from the class

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

* Create a class file and add unit tests for SmSeatSubscriptionUpdateTest.cs

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

* Add unit test for the secrets manager seat update

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

* Fix the failing test cases

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

* Add unit test for service account update

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>

---------

Signed-off-by: Cy Okeke <cokeke@bitwarden.com>
2024-05-13 20:35:22 +01:00

107 lines
3.6 KiB
C#

using Bit.Core.Enums;
using Bit.Core.Models.Business;
using Bit.Core.Utilities;
using Bit.Test.Common.AutoFixture.Attributes;
using Stripe;
using Xunit;
namespace Bit.Core.Test.Models.Business;
public class StorageSubscriptionUpdateTests
{
[Theory]
[BitAutoData(PlanType.EnterpriseMonthly2019)]
[BitAutoData(PlanType.EnterpriseMonthly2020)]
[BitAutoData(PlanType.EnterpriseMonthly)]
[BitAutoData(PlanType.EnterpriseAnnually2019)]
[BitAutoData(PlanType.EnterpriseAnnually2020)]
[BitAutoData(PlanType.EnterpriseAnnually)]
[BitAutoData(PlanType.TeamsMonthly2019)]
[BitAutoData(PlanType.TeamsMonthly2020)]
[BitAutoData(PlanType.TeamsMonthly)]
[BitAutoData(PlanType.TeamsAnnually2019)]
[BitAutoData(PlanType.TeamsAnnually2020)]
[BitAutoData(PlanType.TeamsAnnually)]
[BitAutoData(PlanType.TeamsStarter)]
public void UpgradeItemsOptions_ReturnsCorrectOptions(PlanType planType)
{
var plan = StaticStore.GetPlan(planType);
var subscription = new Subscription
{
Items = new StripeList<SubscriptionItem>
{
Data = new List<SubscriptionItem>
{
new ()
{
Id = "subscription_item",
Price = new Price { Id = plan.PasswordManager.StripeStoragePlanId },
Quantity = 1
}
}
}
};
var update = new StorageSubscriptionUpdate("plan_id", 100);
var options = update.UpgradeItemsOptions(subscription);
Assert.Single(options);
Assert.Equal("plan_id", options[0].Plan);
Assert.Equal(100, options[0].Quantity);
Assert.Null(options[0].Deleted);
}
[Fact]
public void RevertItemsOptions_ThrowsExceptionIfPrevStorageIsNull()
{
var subscription = new Subscription();
var update = new StorageSubscriptionUpdate("plan_id", 100);
Assert.Throws<Exception>(() => update.RevertItemsOptions(subscription));
}
[Theory]
[BitAutoData(PlanType.EnterpriseMonthly2019)]
[BitAutoData(PlanType.EnterpriseMonthly2020)]
[BitAutoData(PlanType.EnterpriseMonthly)]
[BitAutoData(PlanType.EnterpriseAnnually2019)]
[BitAutoData(PlanType.EnterpriseAnnually2020)]
[BitAutoData(PlanType.EnterpriseAnnually)]
[BitAutoData(PlanType.TeamsMonthly2019)]
[BitAutoData(PlanType.TeamsMonthly2020)]
[BitAutoData(PlanType.TeamsMonthly)]
[BitAutoData(PlanType.TeamsAnnually2019)]
[BitAutoData(PlanType.TeamsAnnually2020)]
[BitAutoData(PlanType.TeamsAnnually)]
[BitAutoData(PlanType.TeamsStarter)]
public void RevertItemsOptions_ReturnsCorrectOptions(PlanType planType)
{
var plan = StaticStore.GetPlan(planType);
var subscription = new Subscription
{
Items = new StripeList<SubscriptionItem>
{
Data = new List<SubscriptionItem>
{
new ()
{
Id = "subscription_item",
Price = new Price { Id = plan.PasswordManager.StripeStoragePlanId },
Quantity = 100
}
}
}
};
var update = new StorageSubscriptionUpdate(plan.PasswordManager.StripeStoragePlanId, 100);
update.UpgradeItemsOptions(subscription);
var options = update.RevertItemsOptions(subscription);
Assert.Single(options);
Assert.Equal(plan.PasswordManager.StripeStoragePlanId, options[0].Plan);
Assert.Equal(100, options[0].Quantity);
Assert.Null(options[0].Deleted);
}
}