From 8254bd962595d2e926b141fed4513cefc55c7a6d Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Tue, 26 Sep 2023 15:24:29 +0200 Subject: [PATCH] Take into account voucher tax part when displaying tax included in price --- app/helpers/checkout_helper.rb | 4 +++- spec/helpers/checkout_helper_spec.rb | 25 +++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index b9b5ce8d40..dabbf3d4a6 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -53,7 +53,9 @@ module CheckoutHelper end def display_checkout_tax_total(order) - Spree::Money.new order.total_tax, currency: order.currency + total_tax = order.total_tax + VoucherAdjustmentsService.new(order).voucher_included_tax + + Spree::Money.new(total_tax, currency: order.currency) end def display_checkout_taxes_hash(order) diff --git a/spec/helpers/checkout_helper_spec.rb b/spec/helpers/checkout_helper_spec.rb index 31ad004106..9cedc34d44 100644 --- a/spec/helpers/checkout_helper_spec.rb +++ b/spec/helpers/checkout_helper_spec.rb @@ -15,12 +15,29 @@ describe CheckoutHelper, type: :helper do helper.validated_input("test", "foo", type: :email) end - describe "displaying the tax total for an order" do - let(:order) { double(:order, total_tax: 123.45, currency: 'AUD') } + describe "#display_checkout_tax_total" do + subject(:display_checkout_tax_total) { helper.display_checkout_tax_total(order) } + + let(:order) { instance_double(Spree::Order, total_tax: 123.45, currency: 'AUD') } + let(:service) do + instance_double(VoucherAdjustmentsService, voucher_included_tax: voucher_included_tax) + end + let(:voucher_included_tax) { 0.0 } + + before do + allow(VoucherAdjustmentsService).to receive(:new).and_return(service) + end it "retrieves the total tax on the order" do - expect(helper.display_checkout_tax_total(order)).to eq(Spree::Money.new(123.45, - currency: 'AUD')) + expect(display_checkout_tax_total).to eq(Spree::Money.new(123.45, currency: 'AUD')) + end + + context "with a voucher" do + let(:voucher_included_tax) { -0.45 } + + it "displays the discounted total tax" do + expect(display_checkout_tax_total).to eq(Spree::Money.new(123.00, currency: 'AUD')) + end end end