summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJared Norman <jared@super.gd>2019-01-18 16:27:53 -0800
committerJared Norman <jared@super.gd>2019-01-18 16:31:11 -0800
commit6488fd15856d4db6204f8726d6b5f5c8d1abf14b (patch)
treed4d87a0cef8e997c8e3e347e1da85910149280c5 /spec
parent55cc66a4192ff80c06288c884c8458473dfe36ff (diff)
Support shipping taxes
Diffstat (limited to 'spec')
-rw-r--r--spec/super_good/solidus_taxjar/tax_calculator_spec.rb65
1 files changed, 62 insertions, 3 deletions
diff --git a/spec/super_good/solidus_taxjar/tax_calculator_spec.rb b/spec/super_good/solidus_taxjar/tax_calculator_spec.rb
index 02140da..19841a8 100644
--- a/spec/super_good/solidus_taxjar/tax_calculator_spec.rb
+++ b/spec/super_good/solidus_taxjar/tax_calculator_spec.rb
@@ -14,7 +14,40 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do
::Spree::Order.new(
id: 10,
store: store,
- ship_address: address
+ ship_address: address,
+ shipments: [
+ boring_shipment,
+ shipment_with_adjustment,
+ shipment_with_existing_tax
+ ]
+ )
+ end
+
+ let(:boring_shipment) do
+ ::Spree::Shipment.new(id: 1, cost: 7)
+ end
+
+ let(:shipment_with_adjustment) do
+ ::Spree::Shipment.new(
+ id: 2,
+ cost: 20,
+ adjustments: [
+ ::Spree::Adjustment.new(amount: -7)
+ ]
+ )
+ end
+
+ let(:shipment_with_existing_tax) do
+ ::Spree::Shipment.new(
+ id: 3,
+ cost: 10,
+ additional_tax_total: 3,
+ adjustments: [
+ ::Spree::Adjustment.new(
+ amount: 3,
+ source_type: "Spree::TaxRate"
+ )
+ ]
)
end
@@ -43,7 +76,11 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do
before do
allow(dummy_api).to receive(:tax_for).with(order).and_return(
- instance_double(::Taxjar::Tax, breakdown: breakdown)
+ instance_double(
+ ::Taxjar::Tax,
+ breakdown: breakdown,
+ shipping: 10.0
+ )
)
end
@@ -66,7 +103,6 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do
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
@@ -77,6 +113,29 @@ RSpec.describe ::SuperGood::SolidusTaxJar::TaxCalculator do
expect(item_tax.amount).to eq 6.66
expect(item_tax.included_in_price).to eq false
end
+
+ 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