-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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>
- Loading branch information
1 parent
7f9d7c0
commit f94ddb2
Showing
4 changed files
with
406 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
test/Core.Test/Models/Business/SeatSubscriptionUpdateTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using Bit.Core.AdminConsole.Entities; | ||
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 SeatSubscriptionUpdateTests | ||
{ | ||
[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, Organization organization) | ||
{ | ||
var plan = StaticStore.GetPlan(planType); | ||
organization.PlanType = planType; | ||
var subscription = new Subscription | ||
{ | ||
Items = new StripeList<SubscriptionItem> | ||
{ | ||
Data = new List<SubscriptionItem> | ||
{ | ||
new () | ||
{ | ||
Id = "subscription_item", | ||
Price = new Price { Id = plan.PasswordManager.StripeSeatPlanId }, | ||
Quantity = 1 | ||
} | ||
} | ||
} | ||
}; | ||
var update = new SeatSubscriptionUpdate(organization, plan, 100); | ||
|
||
var options = update.UpgradeItemsOptions(subscription); | ||
|
||
Assert.Single(options); | ||
Assert.Equal(plan.PasswordManager.StripeSeatPlanId, options[0].Plan); | ||
Assert.Equal(100, options[0].Quantity); | ||
Assert.Null(options[0].Deleted); | ||
} | ||
|
||
[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)] | ||
public void RevertItemsOptions_ReturnsCorrectOptions(PlanType planType, Organization organization) | ||
{ | ||
var plan = StaticStore.GetPlan(planType); | ||
organization.PlanType = planType; | ||
var subscription = new Subscription | ||
{ | ||
Items = new StripeList<SubscriptionItem> | ||
{ | ||
Data = new List<SubscriptionItem> | ||
{ | ||
new () | ||
{ | ||
Id = "subscription_item", | ||
Price = new Price { Id = plan.PasswordManager.StripeSeatPlanId }, | ||
Quantity = 100 | ||
} | ||
} | ||
} | ||
}; | ||
var update = new SeatSubscriptionUpdate(organization, plan, 100); | ||
update.UpgradeItemsOptions(subscription); | ||
|
||
var options = update.RevertItemsOptions(subscription); | ||
|
||
Assert.Single(options); | ||
Assert.Equal(plan.PasswordManager.StripeSeatPlanId, options[0].Plan); | ||
Assert.Equal(organization.Seats, options[0].Quantity); | ||
Assert.Null(options[0].Deleted); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
test/Core.Test/Models/Business/ServiceAccountSubscriptionUpdateTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using Bit.Core.AdminConsole.Entities; | ||
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 ServiceAccountSubscriptionUpdateTests | ||
{ | ||
[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, Organization organization) | ||
{ | ||
var plan = StaticStore.GetPlan(planType); | ||
organization.PlanType = planType; | ||
var subscription = new Subscription | ||
{ | ||
Items = new StripeList<SubscriptionItem> | ||
{ | ||
Data = new List<SubscriptionItem> | ||
{ | ||
new () | ||
{ | ||
Id = "subscription_item", | ||
Price = new Price { Id = plan.SecretsManager.StripeServiceAccountPlanId }, | ||
Quantity = 1 | ||
} | ||
} | ||
} | ||
}; | ||
var update = new ServiceAccountSubscriptionUpdate(organization, plan, 3); | ||
|
||
var options = update.UpgradeItemsOptions(subscription); | ||
|
||
Assert.Single(options); | ||
Assert.Equal(plan.SecretsManager.StripeServiceAccountPlanId, options[0].Plan); | ||
Assert.Equal(3, options[0].Quantity); | ||
Assert.Null(options[0].Deleted); | ||
} | ||
|
||
[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)] | ||
public void RevertItemsOptions_ReturnsCorrectOptions(PlanType planType, Organization organization) | ||
{ | ||
var plan = StaticStore.GetPlan(planType); | ||
organization.PlanType = planType; | ||
var quantity = 5; | ||
var subscription = new Subscription | ||
{ | ||
Items = new StripeList<SubscriptionItem> | ||
{ | ||
Data = new List<SubscriptionItem> | ||
{ | ||
new () | ||
{ | ||
Id = "subscription_item", | ||
Price = new Price { Id = plan.SecretsManager.StripeServiceAccountPlanId }, | ||
Quantity = quantity | ||
} | ||
} | ||
} | ||
}; | ||
var update = new ServiceAccountSubscriptionUpdate(organization, plan, quantity); | ||
update.UpgradeItemsOptions(subscription); | ||
|
||
var options = update.RevertItemsOptions(subscription); | ||
|
||
Assert.Single(options); | ||
Assert.Equal(plan.SecretsManager.StripeServiceAccountPlanId, options[0].Plan); | ||
Assert.Equal(quantity, options[0].Quantity); | ||
Assert.Null(options[0].Deleted); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
test/Core.Test/Models/Business/SmSeatSubscriptionUpdateTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using Bit.Core.AdminConsole.Entities; | ||
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 SmSeatSubscriptionUpdateTests | ||
{ | ||
[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, Organization organization) | ||
{ | ||
var plan = StaticStore.GetPlan(planType); | ||
organization.PlanType = planType; | ||
var quantity = 3; | ||
var subscription = new Subscription | ||
{ | ||
Items = new StripeList<SubscriptionItem> | ||
{ | ||
Data = new List<SubscriptionItem> | ||
{ | ||
new () | ||
{ | ||
Id = "subscription_item", | ||
Price = new Price { Id = plan.SecretsManager.StripeSeatPlanId }, | ||
Quantity = quantity | ||
} | ||
} | ||
} | ||
}; | ||
var update = new SmSeatSubscriptionUpdate(organization, plan, quantity); | ||
|
||
var options = update.UpgradeItemsOptions(subscription); | ||
|
||
Assert.Single(options); | ||
Assert.Equal(plan.SecretsManager.StripeSeatPlanId, options[0].Plan); | ||
Assert.Equal(quantity, options[0].Quantity); | ||
Assert.Null(options[0].Deleted); | ||
} | ||
|
||
[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)] | ||
public void RevertItemsOptions_ReturnsCorrectOptions(PlanType planType, Organization organization) | ||
{ | ||
var plan = StaticStore.GetPlan(planType); | ||
organization.PlanType = planType; | ||
var quantity = 5; | ||
var subscription = new Subscription | ||
{ | ||
Items = new StripeList<SubscriptionItem> | ||
{ | ||
Data = new List<SubscriptionItem> | ||
{ | ||
new () | ||
{ | ||
Id = "subscription_item", | ||
Price = new Price { Id = plan.SecretsManager.StripeSeatPlanId }, | ||
Quantity = quantity | ||
} | ||
} | ||
} | ||
}; | ||
var update = new SmSeatSubscriptionUpdate(organization, plan, quantity); | ||
update.UpgradeItemsOptions(subscription); | ||
|
||
var options = update.RevertItemsOptions(subscription); | ||
|
||
Assert.Single(options); | ||
Assert.Equal(plan.SecretsManager.StripeSeatPlanId, options[0].Plan); | ||
Assert.Equal(organization.SmSeats, options[0].Quantity); | ||
Assert.Null(options[0].Deleted); | ||
} | ||
} |
Oops, something went wrong.