mirror of
https://github.com/bitwarden/server.git
synced 2026-02-04 02:05:30 -06:00
* [PM-29599] create proration preview endpoint * forgot to inject user and fixing stripe errors * updated proration preview and upgrade to be consistent also using the correct proration behavior and making the upgrade flow start a trial * missed using the billing address * changes to proration behavior and returning more properties from the proration endpoint * missed in refactor * pr feedback
57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using Bit.Api.Billing.Models.Requests.Payment;
|
|
using Bit.Api.Billing.Models.Requests.PreviewInvoice;
|
|
using Bit.Core.Billing.Enums;
|
|
using Xunit;
|
|
|
|
namespace Bit.Api.Test.Billing.Models.Requests;
|
|
|
|
public class PreviewPremiumUpgradeProrationRequestTests
|
|
{
|
|
[Theory]
|
|
[InlineData(ProductTierType.Families, PlanType.FamiliesAnnually)]
|
|
[InlineData(ProductTierType.Teams, PlanType.TeamsAnnually)]
|
|
[InlineData(ProductTierType.Enterprise, PlanType.EnterpriseAnnually)]
|
|
public void ToDomain_ValidTierTypes_ReturnsPlanType(ProductTierType tierType, PlanType expectedPlanType)
|
|
{
|
|
// Arrange
|
|
var sut = new PreviewPremiumUpgradeProrationRequest
|
|
{
|
|
TargetProductTierType = tierType,
|
|
BillingAddress = new MinimalBillingAddressRequest
|
|
{
|
|
Country = "US",
|
|
PostalCode = "12345"
|
|
}
|
|
};
|
|
|
|
// Act
|
|
var (planType, billingAddress) = sut.ToDomain();
|
|
|
|
// Assert
|
|
Assert.Equal(expectedPlanType, planType);
|
|
Assert.Equal("US", billingAddress.Country);
|
|
Assert.Equal("12345", billingAddress.PostalCode);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(ProductTierType.Free)]
|
|
[InlineData(ProductTierType.TeamsStarter)]
|
|
public void ToDomain_InvalidTierTypes_ThrowsInvalidOperationException(ProductTierType tierType)
|
|
{
|
|
// Arrange
|
|
var sut = new PreviewPremiumUpgradeProrationRequest
|
|
{
|
|
TargetProductTierType = tierType,
|
|
BillingAddress = new MinimalBillingAddressRequest
|
|
{
|
|
Country = "US",
|
|
PostalCode = "12345"
|
|
}
|
|
};
|
|
|
|
// Act & Assert
|
|
var exception = Assert.Throws<InvalidOperationException>(() => sut.ToDomain());
|
|
Assert.Contains($"Cannot upgrade Premium subscription to {tierType} plan", exception.Message);
|
|
}
|
|
}
|