diff options
author | Jared Norman <jared@super.gd> | 2019-01-20 16:10:35 -0800 |
---|---|---|
committer | Jared Norman <jared@super.gd> | 2019-01-20 16:10:35 -0800 |
commit | 3a1aea93e236ec0a52fae0ef4ab949acccd2088f (patch) | |
tree | 9bcf1596ea1f0cb8d69358b7f64b129e46f3ca35 /spec/super_good | |
parent | 4ddde7d3b241cd57f935bb74750d1ed574dd90c4 (diff) |
Use correctly value for shipping tax
Oops, was grabbing the total shipping tax for the order and using that
as the tax, instead of grabbing the collectable tax from the breakdown.
That makes more sense.
Diffstat (limited to 'spec/super_good')
-rw-r--r-- | spec/super_good/solidus_taxjar/tax_calculator_spec.rb | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/spec/super_good/solidus_taxjar/tax_calculator_spec.rb b/spec/super_good/solidus_taxjar/tax_calculator_spec.rb index b97f53b..bd74292 100644 --- a/spec/super_good/solidus_taxjar/tax_calculator_spec.rb +++ b/spec/super_good/solidus_taxjar/tax_calculator_spec.rb @@ -78,8 +78,7 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do allow(dummy_api).to receive(:tax_for).with(order).and_return( instance_double( ::Taxjar::Tax, - breakdown: breakdown, - shipping: shipping_tax + breakdown: breakdown ) ) end @@ -93,18 +92,22 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do ) end - let(:shipping_tax) { 10 } - let(:breakdown) do - instance_double ::Taxjar::Breakdown, line_items: [taxjar_line_item] + instance_double ::Taxjar::Breakdown, + line_items: [taxjar_line_item], + shipping?: !!shipping_tax_breakdown, + shipping: shipping_tax_breakdown end let(:taxjar_line_item) do instance_double ::Taxjar::BreakdownLineItem, id: "33", tax_collectable: 6.66 end + let(:shipping_tax_breakdown) { nil } + it "returns the taxes" do expect(subject.order_id).to eq order.id + expect(subject.shipment_taxes).to be_empty expect(subject.line_item_taxes.length).to eq 1 item_tax = subject.line_item_taxes.first @@ -115,35 +118,42 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do expect(item_tax.amount).to eq 6.66 expect(item_tax.included_in_price).to eq false end + end - shipment_taxes = subject.shipment_taxes - expect(shipment_taxes.length).to eq 3 + context "when there are shipping taxes" do + let(:shipping_tax_breakdown) do + instance_double ::Taxjar::Shipping, tax_collectable: 10.00 + end - aggregate_failures do - expect(shipment_taxes[0].item_id).to eq 1 - expect(shipment_taxes[0].label).to eq "Sales Tax" - expect(shipment_taxes[0].tax_rate).to eq tax_rate - expect(shipment_taxes[0].amount).to eq 2.33 - expect(shipment_taxes[0].included_in_price).to eq false - - expect(shipment_taxes[1].item_id).to eq 2 - expect(shipment_taxes[1].label).to eq "Sales Tax" - expect(shipment_taxes[1].tax_rate).to eq tax_rate - expect(shipment_taxes[1].amount).to eq 4.33 - expect(shipment_taxes[1].included_in_price).to eq false - - expect(shipment_taxes[2].item_id).to eq 3 - expect(shipment_taxes[2].label).to eq "Sales Tax" - expect(shipment_taxes[2].tax_rate).to eq tax_rate - expect(shipment_taxes[2].amount).to eq 3.34 - expect(shipment_taxes[2].included_in_price).to eq false + it "returns the shipping taxes" do + shipment_taxes = subject.shipment_taxes + expect(shipment_taxes.length).to eq 3 + + aggregate_failures do + expect(shipment_taxes[0].item_id).to eq 1 + expect(shipment_taxes[0].label).to eq "Sales Tax" + expect(shipment_taxes[0].tax_rate).to eq tax_rate + expect(shipment_taxes[0].amount).to eq 2.33 + expect(shipment_taxes[0].included_in_price).to eq false + + expect(shipment_taxes[1].item_id).to eq 2 + expect(shipment_taxes[1].label).to eq "Sales Tax" + expect(shipment_taxes[1].tax_rate).to eq tax_rate + expect(shipment_taxes[1].amount).to eq 4.33 + expect(shipment_taxes[1].included_in_price).to eq false + + expect(shipment_taxes[2].item_id).to eq 3 + expect(shipment_taxes[2].label).to eq "Sales Tax" + expect(shipment_taxes[2].tax_rate).to eq tax_rate + expect(shipment_taxes[2].amount).to eq 3.34 + expect(shipment_taxes[2].included_in_price).to eq false + end end end end context "and there is not a breakdown" do let(:breakdown) { nil } - let(:shipping_tax) { 0 } it "returns no taxes" do expect(subject.order_id).to eq order.id |