Files
server/test/Core.Test/Billing/Tax/TaxHelpersTests.cs
Stephon Brown 8302509bf9 [PM-31645] Implement Swiss Tax Logic (#7186)
* feat(tax): introduce direct tax country utilities and Switzerland constant

* refactor(tax): use `TaxHelpers.IsDirectTaxCountry` for country checks

* feat(tax): implement customer tax exempt status alignment

* test(tax): add comprehensive unit tests for tax exempt alignment logic

* tests(billing): clarify tests

* fix(billing): run dotnet format

* fix(billing): run dotnet format

* fix(billing): Prevent NullReferenceException when accessing customer country

* test(billing): Add Stripe adapter mocks for AdjustSubscription scenarios

* refactor(billing): apply null-conditional operator for address country access

* feat(billing): update missing tax exemption determinations

* test(billing): add unit tests for tax exemption updates

* fix(billing) run dotnet format

* fix(billing): add nullability

* style(files): normalize file encoding for billing utilities

* refactor(TaxHelpers): simplify tax exempt status determination

* test(Tax): update tax exempt determination tests

* fix(billing): revert postal code validation

* test(billing): update tax exempt tests

* fix(billing): run dotnet format
2026-03-17 14:09:41 -04:00

43 lines
2.2 KiB
C#

using Bit.Core.Billing.Tax.Utilities;
using Xunit;
using CountryAbbreviations = Bit.Core.Constants.CountryAbbreviations;
using TaxExempt = Bit.Core.Billing.Constants.StripeConstants.TaxExempt;
namespace Bit.Core.Test.Billing.Tax;
public class TaxHelpersTests
{
[Theory]
[InlineData(CountryAbbreviations.UnitedStates, true)]
[InlineData(CountryAbbreviations.Switzerland, true)]
[InlineData("DE", false)]
[InlineData(null, false)]
[InlineData("", false)]
public void IsDirectTaxCountry_ReturnsExpectedResult(string? country, bool expected)
{
var result = TaxHelpers.IsDirectTaxCountry(country);
Assert.Equal(expected, result);
}
[Theory]
[InlineData("DE", TaxExempt.None, TaxExempt.Reverse)] // non-direct-tax → Reverse
[InlineData(CountryAbbreviations.UnitedStates, TaxExempt.Reverse, TaxExempt.None)] // US Reverse → None (direct-tax)
[InlineData(CountryAbbreviations.Switzerland, null, TaxExempt.None)] // CH no existing status → None
[InlineData(CountryAbbreviations.UnitedStates, TaxExempt.None, TaxExempt.None)] // US already None → None
[InlineData(CountryAbbreviations.Switzerland, TaxExempt.Reverse, TaxExempt.None)] // CH Reverse → None (direct-tax, not preserved)
[InlineData("DE", TaxExempt.Reverse, TaxExempt.Reverse)] // non-direct-tax already Reverse → Reverse
[InlineData(null, TaxExempt.None, TaxExempt.Reverse)] // unknown country → Reverse
[InlineData("DE", TaxExempt.Exempt, TaxExempt.Exempt)] // exempt always preserved — non-direct-tax country
[InlineData(CountryAbbreviations.UnitedStates, TaxExempt.Exempt, TaxExempt.Exempt)] // exempt always preserved — direct-tax country
[InlineData(CountryAbbreviations.Switzerland, TaxExempt.Exempt, TaxExempt.Exempt)] // exempt always preserved — CH
public void DetermineTaxExemptStatus_ReturnsExpectedResult(
string? country,
string? currentTaxExempt,
string expected)
{
var result = TaxHelpers.DetermineTaxExemptStatus(country, currentTaxExempt);
Assert.Equal(expected, result);
}
}