From 4c9d9b248c7f70b98c0467fd2f7dac253f085fd7 Mon Sep 17 00:00:00 2001 From: Justin Baur Date: Mon, 1 Nov 2021 12:13:31 -0400 Subject: [PATCH] Fix bug in TaxInfo (#1682) * Fixed bug in TaxInfo * Added a few more tests to TaxInfoTests * Added tests for HasTaxId --- src/Core/Models/Business/TaxInfo.cs | 1 + .../Core.Test/Models/Business/TaxInfoTests.cs | 38 ++++++++++++++++++- test/coverage.sh | 0 3 files changed, 38 insertions(+), 1 deletion(-) mode change 100644 => 100755 test/coverage.sh diff --git a/src/Core/Models/Business/TaxInfo.cs b/src/Core/Models/Business/TaxInfo.cs index 03a7df562..62d30b8fe 100644 --- a/src/Core/Models/Business/TaxInfo.cs +++ b/src/Core/Models/Business/TaxInfo.cs @@ -51,6 +51,7 @@ if (BillingAddressState?.Contains("bec") ?? false) { _taxIdType = "ca_qst"; + break; } _taxIdType = "ca_bn"; break; diff --git a/test/Core.Test/Models/Business/TaxInfoTests.cs b/test/Core.Test/Models/Business/TaxInfoTests.cs index 0dc1c0a38..20ccf4a3d 100644 --- a/test/Core.Test/Models/Business/TaxInfoTests.cs +++ b/test/Core.Test/Models/Business/TaxInfoTests.cs @@ -1,4 +1,5 @@ using Bit.Core.Models.Business; +using NSubstitute; using Xunit; namespace Bit.Core.Test.Models.Business @@ -14,7 +15,7 @@ namespace Bit.Core.Test.Models.Business [InlineData("AE", "PH", null, "ae_trn")] [InlineData("AU", "PH", null, "au_abn")] [InlineData("BR", "PH", null, "br_cnpj")] - // [InlineData("CA", "PH", "bec", "ca_qst")] // This test will fail, I believe this is a bug + [InlineData("CA", "PH", "bec", "ca_qst")] [InlineData("CA", "PH", null, "ca_bn")] [InlineData("CL", "PH", null, "cl_tin")] [InlineData("AT", "PH", null, "eu_vat")] @@ -76,5 +77,40 @@ namespace Bit.Core.Test.Models.Business Assert.Equal(expectedTaxIdType, taxInfo.TaxIdType); } + + [Fact] + public void GetTaxIdType_CreateOnce_ReturnCacheSecondTime() + { + var taxInfo = new TaxInfo + { + BillingAddressCountry = "US", + TaxIdNumber = "PH", + BillingAddressState = null, + }; + + Assert.Equal("us_ein", taxInfo.TaxIdType); + + // Per the current spec even if the values change to something other than null it + // will return the cached version of TaxIdType. + taxInfo.BillingAddressCountry = "ZA"; + + Assert.Equal("us_ein", taxInfo.TaxIdType); + } + + [Theory] + [InlineData(null, null, false)] + [InlineData("123", "US", true)] + [InlineData("123", "ZQ12", false)] + [InlineData(" ", "US", false)] + public void HasTaxId_ReturnsExpected(string taxIdNumber, string billingAddressCountry, bool expected) + { + var taxInfo = new TaxInfo + { + TaxIdNumber = taxIdNumber, + BillingAddressCountry = billingAddressCountry, + }; + + Assert.Equal(expected, taxInfo.HasTaxId); + } } } diff --git a/test/coverage.sh b/test/coverage.sh old mode 100644 new mode 100755