From 113662740291f78baae523ceffe5530182458825 Mon Sep 17 00:00:00 2001 From: Lee Saville Date: Mon, 19 Aug 2024 11:51:21 -0600 Subject: [PATCH] RUN_TJPLAT-1732 - Fix test failures https://jira.corp.stripe.com/browse/RUN_TJPLAT-1732 https://github.com/taxjar/taxjar-woocommerce-plugin/pull/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. --- .../class-tj-wc-rest-unit-test-case.php | 18 ++++---- .../test-admin-order-creation.php | 10 ++--- tests/specs/test-actions.php | 44 +++++++++---------- tests/specs/test-customer-sync.php | 18 ++++---- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/tests/framework/class-tj-wc-rest-unit-test-case.php b/tests/framework/class-tj-wc-rest-unit-test-case.php index 0e8db04..abc4f20 100644 --- a/tests/framework/class-tj-wc-rest-unit-test-case.php +++ b/tests/framework/class-tj-wc-rest-unit-test-case.php @@ -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 ); } } @@ -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() ); } } @@ -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 ) { @@ -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 ); } } } diff --git a/tests/specs/tax-calculation/test-admin-order-creation.php b/tests/specs/tax-calculation/test-admin-order-creation.php index 0b38f91..60458b2 100644 --- a/tests/specs/tax-calculation/test-admin-order-creation.php +++ b/tests/specs/tax-calculation/test-admin-order-creation.php @@ -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() { @@ -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() { @@ -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() { diff --git a/tests/specs/test-actions.php b/tests/specs/test-actions.php index c645375..f611510 100644 --- a/tests/specs/test-actions.php +++ b/tests/specs/test-actions.php @@ -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() { @@ -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() ); @@ -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 ) { @@ -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 ); } } @@ -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 ); } } @@ -638,11 +638,11 @@ 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 ) { @@ -650,7 +650,7 @@ function test_correct_taxes_for_product_exemption_threshold_reduced_rates() { $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 ) { @@ -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 ) { @@ -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 ); } } diff --git a/tests/specs/test-customer-sync.php b/tests/specs/test-customer-sync.php index 7bcbafa..1ebada4 100644 --- a/tests/specs/test-customer-sync.php +++ b/tests/specs/test-customer-sync.php @@ -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 @@ -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(); @@ -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() );