Skip to content

Commit

Permalink
RUN_TJPLAT-1732 - Fix test failures
Browse files Browse the repository at this point in the history
https://jira.corp.stripe.com/browse/RUN_TJPLAT-1732
#263

This work fixes rate change based test failures so we have a better idea if
upcoming changes break things. These tests seemed to be failing because of
natural tax law changes and rate updates, so we've updated the values.
  • Loading branch information
saville-stripe committed Aug 19, 2024
1 parent 59b4f12 commit 1136627
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
18 changes: 9 additions & 9 deletions tests/framework/class-tj-wc-rest-unit-test-case.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ function test_simple_product_tax_on_api_order() {
$order = wc_get_order( $data['id'] );

$this->assertEquals( 201, $response->get_status() );
$this->assertEquals( 0.73, $order->get_total_tax(), '', 0.01 );
$this->assertEquals( 0.75, $order->get_total_tax(), '', 0.01 );

foreach ( $order->get_items() as $item ) {
$this->assertEquals( 0.73, $item->get_total_tax(), '', 0.01 );
$this->assertEquals( 0.75, $item->get_total_tax(), '', 0.01 );
}
}

Expand Down Expand Up @@ -225,14 +225,14 @@ function test_fee_tax_on_api_order() {
$order = wc_get_order( $data['id'] );

$this->assertEquals( 201, $response->get_status() );
$this->assertEquals( 7.98, $order->get_total_tax(), '', 0.01 );
$this->assertEquals( 8.2, $order->get_total_tax(), '', 0.01 );

foreach ( $order->get_items() as $item ) {
$this->assertEquals( 0.73, $item->get_total_tax(), '', 0.01 );
$this->assertEquals( 0.75, $item->get_total_tax(), '', 0.01 );
}

foreach ( $order->get_fees() as $fee ) {
$this->assertEquals( 7.25, $fee->get_total_tax() );
$this->assertEquals( 7.45, $fee->get_total_tax() );
}
}

Expand Down Expand Up @@ -267,10 +267,10 @@ function test_exempt_fee_on_api_order() {
$order = wc_get_order( $data['id'] );

$this->assertEquals( 201, $response->get_status() );
$this->assertEquals( 0.73, $order->get_total_tax(), '', 0.01 );
$this->assertEquals( 0.75, $order->get_total_tax(), '', 0.01 );

foreach ( $order->get_items() as $item ) {
$this->assertEquals( 0.73, $item->get_total_tax(), '', 0.01 );
$this->assertEquals( 0.75, $item->get_total_tax(), '', 0.01 );
}

foreach ( $order->get_fees() as $fee ) {
Expand Down Expand Up @@ -312,10 +312,10 @@ function test_batch_order_creation_through_api() {
foreach ( $data['create'] as $order_response ) {
$order = wc_get_order( $order_response['id'] );

$this->assertEquals( 0.73, $order->get_total_tax(), '', 0.01 );
$this->assertEquals( 0.75, $order->get_total_tax(), '', 0.01 );

foreach ( $order->get_items() as $item ) {
$this->assertEquals( 0.73, $item->get_total_tax(), '', 0.01 );
$this->assertEquals( 0.75, $item->get_total_tax(), '', 0.01 );
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/specs/tax-calculation/test-admin-order-creation.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function test_order_with_single_line_item() {
$this->call_wc_ajax_calc_line_taxes();

$order = wc_get_order( $this->test_order->get_id() );
$this->assert_correct_line_tax( $order, 7.25 );
$this->assert_correct_totals( $order, 107.25, 7.25 );
$this->assert_correct_line_tax( $order, 7.45 );
$this->assert_correct_totals( $order, 107.45, 7.45 );
}

public function test_order_with_taxable_shipping() {
Expand All @@ -80,7 +80,7 @@ public function test_order_with_fee() {
$this->call_wc_ajax_calc_line_taxes();

$order = wc_get_order( $this->test_order->get_id() );
$this->assert_correct_totals( $order, 107.25, 7.25 );
$this->assert_correct_totals( $order, 107.45, 7.45 );
}

public function test_order_with_product_tax_code() {
Expand Down Expand Up @@ -139,8 +139,8 @@ public function test_order_with_discount() {

$order = wc_get_order( $this->test_order->get_id() );

$this->assert_correct_line_tax( $order, 6.53 );
$this->assert_correct_totals( $order, 96.53, 6.53 );
$this->assert_correct_line_tax( $order, 6.71 );
$this->assert_correct_totals( $order, 96.71, 6.71 );
}

public function test_order_without_nexus() {
Expand Down
44 changes: 22 additions & 22 deletions tests/specs/test-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ function test_taxes_with_different_shipping_and_item_rates() {
$this->assertEquals( $item['line_tax'], 0.58, '', 0.01 );
}

$this->assertEquals( WC()->cart->get_shipping_tax(), 0.69, '', 0.01 );
$this->assertEquals( WC()->cart->get_total_tax(), 1.27, '', 0.01 );
$this->assertEquals( WC()->cart->get_shipping_tax(), 0.0, '', 0.01 );
$this->assertEquals( WC()->cart->get_total_tax(), 0.58, '', 0.01 );
}

function test_correct_taxes_with_exempt_shipping() {
Expand Down Expand Up @@ -210,12 +210,12 @@ function test_correct_taxes_with_local_pickup() {
WC()->session->set( 'chosen_shipping_methods', array( 'local_pickup' ) );
WC()->cart->calculate_totals();

$this->assertEquals( WC()->cart->tax_total, 0.73, '', 0.01 );
$this->assertEquals( WC()->cart->tax_total, 0.43, '', 0.01 );
$this->assertEquals( WC()->cart->shipping_tax_total, 0, '', 0.01 );
$this->assertEquals( WC()->cart->get_taxes_total(), 0.73, '', 0.01 );
$this->assertEquals( WC()->cart->get_taxes_total(), 0.43, '', 0.01 );

foreach ( WC()->cart->get_cart() as $cart_item_key => $item ) {
$this->assertEquals( $item['line_tax'], 0.73, '', 0.01 );
$this->assertEquals( $item['line_tax'], 0.43, '', 0.01 );
}

WC()->session->set( 'chosen_shipping_methods', array() );
Expand All @@ -234,15 +234,15 @@ function test_correct_taxes_for_multiple_products() {
WC()->cart->add_to_cart( $extra_product, 2 );
WC()->cart->calculate_totals();

$this->assertEquals( WC()->cart->tax_total, 4.36, '', 0.01 );
$this->assertEquals( WC()->cart->get_taxes_total(), 4.36, '', 0.01 );
$this->assertEquals( WC()->cart->tax_total, 2.56, '', 0.01 );
$this->assertEquals( WC()->cart->get_taxes_total(), 2.56, '', 0.01 );

foreach ( WC()->cart->get_cart() as $cart_item_key => $item ) {
$product = $item['data'];
$sku = $product->get_sku();

if ( 'SIMPLE2' == $sku ) {
$this->assertEquals( $item['line_tax'], 3.63, '', 0.01 );
$this->assertEquals( $item['line_tax'], 2.13, '', 0.01 );
}

if ( 'SIMPLE1' == $sku ) {
Expand All @@ -251,7 +251,7 @@ function test_correct_taxes_for_multiple_products() {
}

if ( version_compare( WC()->version, '3.2', '>=' ) ) {
$this->assertEquals( WC()->cart->get_total( 'amount' ), 64.36, '', 0.01 );
$this->assertEquals( WC()->cart->get_total( 'amount' ), 62.56, '', 0.01 );
}
}

Expand Down Expand Up @@ -357,11 +357,11 @@ function test_correct_taxes_for_duplicate_line_items() {
WC()->cart->add_to_cart( $product, 1, 0, [], [ 'duplicate' => true ] );
WC()->cart->calculate_totals();

$this->assertEquals( WC()->cart->tax_total, 1.46, '', 0.01 );
$this->assertEquals( WC()->cart->get_taxes_total(), 1.46, '', 0.01 );
$this->assertEquals( WC()->cart->tax_total, 0.86, '', 0.01 );
$this->assertEquals( WC()->cart->get_taxes_total(), 0.86, '', 0.01 );

if ( version_compare( WC()->version, '3.2', '>=' ) ) {
$this->assertEquals( WC()->cart->get_total( 'amount' ), 21.46, '', 0.01 );
$this->assertEquals( WC()->cart->get_total( 'amount' ), 20.86, '', 0.01 );
}
}

Expand Down Expand Up @@ -638,19 +638,19 @@ function test_correct_taxes_for_product_exemption_threshold_reduced_rates() {
WC()->cart->add_to_cart( $reduced_product, 2 );
WC()->cart->calculate_totals();

$this->assertEquals( WC()->cart->tax_total, 14.75, '', 0.01 );
$this->assertEquals( WC()->cart->get_taxes_total(), 14.75, '', 0.01 );
$this->assertEquals( WC()->cart->tax_total, 12.56, '', 0.01 );
$this->assertEquals( WC()->cart->get_taxes_total(), 12.56, '', 0.01 );

if ( version_compare( WC()->version, '3.2', '>=' ) ) {
$this->assertEquals( WC()->cart->get_total( 'amount' ), 150 + 50 + 14.75, '', 0.01 );
$this->assertEquals( WC()->cart->get_total( 'amount' ), 150 + 50 + 12.56, '', 0.01 );
}

foreach ( WC()->cart->get_cart() as $item_key => $item ) {
$product = $item['data'];
$sku = $product->get_sku();

if ( 'REDUCED1' == $sku ) {
$this->assertEquals( $item['line_tax'], 2.19, '', 0.01 );
$this->assertEquals( $item['line_tax'], 0.0, '', 0.01 );
}

if ( 'EXEMPTOVER1' == $sku ) {
Expand Down Expand Up @@ -695,11 +695,11 @@ function test_correct_taxes_for_product_exemption_threshold_reduced_rates_and_ot
WC()->cart->add_to_cart( $reduced_product, 2 );
WC()->cart->calculate_totals();

$this->assertEquals( WC()->cart->tax_total, 18.94, '', 0.01 );
$this->assertEquals( WC()->cart->get_taxes_total(), 18.94, '', 0.01 );
$this->assertEquals( WC()->cart->tax_total, 16.75, '', 0.01 );
$this->assertEquals( WC()->cart->get_taxes_total(), 16.75, '', 0.01 );

if ( version_compare( WC()->version, '3.2', '>=' ) ) {
$this->assertEquals( WC()->cart->get_total( 'amount' ), 150 + 50 + 50 + 18.94, '', 0.01 );
$this->assertEquals( WC()->cart->get_total( 'amount' ), 150 + 50 + 50 + 16.75, '', 0.01 );
}

foreach ( WC()->cart->get_cart() as $item_key => $item ) {
Expand Down Expand Up @@ -742,11 +742,11 @@ function test_correct_taxes_for_discounts() {
WC()->cart->add_discount( $coupon );
WC()->cart->calculate_totals();

$this->assertEquals( WC()->cart->tax_total, 4.35, '', 0.01 );
$this->assertEquals( WC()->cart->get_taxes_total(), 4.35, '', 0.01 );
$this->assertEquals( WC()->cart->tax_total, 2.55, '', 0.01 );
$this->assertEquals( WC()->cart->get_taxes_total(), 2.55, '', 0.01 );

if ( version_compare( WC()->version, '3.2', '>=' ) ) {
$this->assertEquals( WC()->cart->get_total( 'amount' ), 64.35, '', 0.01 );
$this->assertEquals( WC()->cart->get_total( 'amount' ), 62.55, '', 0.01 );
}
}

Expand Down
18 changes: 9 additions & 9 deletions tests/specs/test-customer-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ function test_tax_calculation_with_customer_exemption() {
WC()->shipping->shipping_total = 10;
WC()->cart->calculate_totals();

$this->assertEquals( .73, WC()->cart->get_total_tax(), '', 0.01 );
$this->assertEquals( .43, WC()->cart->get_total_tax(), '', 0.01 );
$this->assertEquals( 0, WC()->cart->get_shipping_tax(), '', 0.01 );
$this->assertEquals( .73, WC()->cart->get_taxes_total(), '', 0.01 );
$this->assertEquals( .43, WC()->cart->get_taxes_total(), '', 0.01 );
foreach ( WC()->cart->get_cart() as $cart_item_key => $item ) {
$this->assertEquals( .73, $item['line_tax'], '', 0.01 );
$this->assertEquals( .43, $item['line_tax'], '', 0.01 );
}

// test tax calculation for exempt customer
Expand Down Expand Up @@ -421,11 +421,11 @@ function test_tax_calculation_with_previously_exempt_customer() {
WC()->customer = $customer;
WC()->cart->calculate_totals();

$this->assertEquals( 1.45, WC()->cart->get_total_tax(), '', 0.01 );
$this->assertEquals( 0.85, WC()->cart->get_total_tax(), '', 0.01 );
$this->assertEquals( 0, WC()->cart->get_shipping_tax(), '', 0.01 );
$this->assertEquals( 1.45, WC()->cart->get_taxes_total(), '', 0.01 );
$this->assertEquals( 0.85, WC()->cart->get_taxes_total(), '', 0.01 );
foreach ( WC()->cart->get_cart() as $cart_item_key => $item ) {
$this->assertEquals( 1.45, $item['line_tax'], '', 0.01 );
$this->assertEquals( 0.85, $item['line_tax'], '', 0.01 );
}

$record->delete_in_taxjar();
Expand All @@ -451,11 +451,11 @@ function test_exempt_customer_deleted_from_taxjar() {
WC()->shipping->shipping_total = 10;
WC()->cart->calculate_totals();

$this->assertEquals( .73, WC()->cart->get_total_tax(), '', 0.01 );
$this->assertEquals( .43, WC()->cart->get_total_tax(), '', 0.01 );
$this->assertEquals( 0, WC()->cart->get_shipping_tax(), '', 0.01 );
$this->assertEquals( .73, WC()->cart->get_taxes_total(), '', 0.01 );
$this->assertEquals( .43, WC()->cart->get_taxes_total(), '', 0.01 );
foreach ( WC()->cart->get_cart() as $cart_item_key => $item ) {
$this->assertEquals( .73, $item['line_tax'], '', 0.01 );
$this->assertEquals( .43, $item['line_tax'], '', 0.01 );
}

TaxJar_Customer_Helper::delete_customer( $customer->get_id() );
Expand Down

0 comments on commit 1136627

Please sign in to comment.