Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 36 additions & 20 deletions test/Core.Test/Billing/Extensions/InvoiceExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
๏ปฟusing Bit.Core.Billing.Extensions;
๏ปฟusing System.Globalization;
using Bit.Core.Billing.Extensions;
using Stripe;
using Xunit;

Expand Down Expand Up @@ -356,9 +357,18 @@ public void FormatForProvider_ZeroInvoiceLevelTax_DoesNotAddTax()
[Fact]
public void FormatForProvider_ComplexScenario_HandlesAllLineTypes()
{
// Arrange
var lineItems = new StripeList<InvoiceLineItem>();
lineItems.Data = new List<InvoiceLineItem>
// Set culture to en-US to ensure consistent decimal formatting in tests
// This ensures tests pass on all machines regardless of system locale
var originalCulture = Thread.CurrentThread.CurrentCulture;
var originalUICulture = Thread.CurrentThread.CurrentUICulture;
try
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐ŸŽจ Consider using CultureInfo.InvariantCulture instead of new CultureInfo("en-US") for unit tests. Invariant culture is specifically designed for culture-independent operations and makes the intent clearer - you want consistent formatting regardless of system locale, not specifically US formatting.

Suggested change
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;


// Arrange
var lineItems = new StripeList<InvoiceLineItem>();
lineItems.Data = new List<InvoiceLineItem>
{
new InvoiceLineItem
{
Expand All @@ -372,23 +382,29 @@ public void FormatForProvider_ComplexScenario_HandlesAllLineTypes()
new InvoiceLineItem { Description = "Custom Service", Quantity = 2, Amount = 2000 }
};

var invoice = new Invoice
var invoice = new Invoice
{
Lines = lineItems,
TotalTaxes = [new InvoiceTotalTax { Amount = 200 }] // Additional $2.00 tax
};
var subscription = new Subscription();

// Act
var result = invoice.FormatForProvider(subscription);

// Assert
Assert.Equal(5, result.Count);
Assert.Equal("5 ร— Manage service provider (at $6.00 / month)", result[0]);
Assert.Equal("10 ร— Manage service provider (at $4.00 / month)", result[1]);
Assert.Equal("1 ร— Tax (at $8.00 / month)", result[2]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿ’ญ This assertion now expects $8.00, which correctly matches the test data (line 381: Amount = 800 cents = $8.00). The original test expected $0.00.

Can you confirm this change represents correct business logic? Was the original $0.00 expectation:

  • A test data error that should have been 0 cents?
  • An intentional regression test?
  • Or is $8.00 the correct expected behavior?

This is important to verify we're fixing the test correctly, not just making it pass.

Assert.Equal("Custom Service", result[3]);
Assert.Equal("1 ร— Tax (at $2.00 / month)", result[4]);
}
finally
{
Lines = lineItems,
TotalTaxes = [new InvoiceTotalTax { Amount = 200 }] // Additional $2.00 tax
};
var subscription = new Subscription();

// Act
var result = invoice.FormatForProvider(subscription);

// Assert
Assert.Equal(5, result.Count);
Assert.Equal("5 ร— Manage service provider (at $6.00 / month)", result[0]);
Assert.Equal("10 ร— Manage service provider (at $4.00 / month)", result[1]);
Assert.Equal("1 ร— Tax (at $8.00 / month)", result[2]);
Assert.Equal("Custom Service", result[3]);
Assert.Equal("1 ร— Tax (at $2.00 / month)", result[4]);
Thread.CurrentThread.CurrentCulture = originalCulture;
Thread.CurrentThread.CurrentUICulture = originalUICulture;
}
}

#endregion
Expand Down
Loading