mirror of
https://github.com/bitwarden/server
synced 2026-02-20 11:23:37 +00:00
[PM-29599] create proration preview endpoint (#6858)
* [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
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Bit.Api.Billing.Models.Requests.Payment;
|
||||
using Bit.Api.Billing.Models.Requests.Premium;
|
||||
using Bit.Core.Billing.Enums;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Api.Test.Billing.Models.Requests;
|
||||
|
||||
public class UpgradePremiumToOrganizationRequestTests
|
||||
{
|
||||
[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 UpgradePremiumToOrganizationRequest
|
||||
{
|
||||
OrganizationName = "Test Organization",
|
||||
Key = "encrypted-key",
|
||||
TargetProductTierType = tierType,
|
||||
BillingAddress = new MinimalBillingAddressRequest
|
||||
{
|
||||
Country = "US",
|
||||
PostalCode = "12345"
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var (organizationName, key, planType, billingAddress) = sut.ToDomain();
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Test Organization", organizationName);
|
||||
Assert.Equal("encrypted-key", key);
|
||||
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 UpgradePremiumToOrganizationRequest
|
||||
{
|
||||
OrganizationName = "Test Organization",
|
||||
Key = "encrypted-key",
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user