summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Silvera <noah@super.gd>2021-04-09 13:59:41 -0700
committerNoah Silvera <noah@super.gd>2021-04-13 08:45:30 -0700
commit351cd0a842afc664d02161ff9c6a8fc0186eae27 (patch)
tree0fea31e2865ea3abec9cdd607f6941852ac07dfa
parenta5f76766988f529de8cd9dc568237fbcde2fc311 (diff)
Consider promotions in default shipping calculator
Previously, the shipment_total method on order was used, which does not take into account shipment promotions. Instead, we should manually sum the shipment cost taking into account any adjustments. Co-authored-by: Nick Van Doorn <nick@super.gd>
-rw-r--r--lib/super_good/solidus_taxjar.rb2
-rw-r--r--spec/super_good/solidus_taxjar/api_params_spec.rb4
-rw-r--r--spec/super_good/solidus_taxjar_spec.rb9
3 files changed, 11 insertions, 4 deletions
diff --git a/lib/super_good/solidus_taxjar.rb b/lib/super_good/solidus_taxjar.rb
index 36b5d85..a3cb730 100644
--- a/lib/super_good/solidus_taxjar.rb
+++ b/lib/super_good/solidus_taxjar.rb
@@ -44,7 +44,7 @@ module SuperGood
}
self.line_item_tax_label_maker = ->(taxjar_line_item, spree_line_item) { "Sales Tax" }
self.logging_enabled = false
- self.shipping_calculator = ->(order) { order.shipment_total }
+ self.shipping_calculator = ->(order) { order.shipments.sum(&:total_before_tax) }
self.shipping_tax_label_maker = ->(shipment, shipping_tax) { "Sales Tax" }
self.taxable_address_check = ->(address) { true }
self.taxable_order_check = ->(order) { true }
diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb
index 6c13e03..1e879e7 100644
--- a/spec/super_good/solidus_taxjar/api_params_spec.rb
+++ b/spec/super_good/solidus_taxjar/api_params_spec.rb
@@ -8,9 +8,9 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
line_items: [line_item],
number: "R111222333",
ship_address: ship_address,
- shipment_total: BigDecimal("3.01"),
store: store,
total: order_total,
+ shipments: [shipment],
user_id: 12345
).tap do |order|
order.update! completed_at: DateTime.new(2018, 3, 6, 12, 10, 33)
@@ -119,6 +119,8 @@ RSpec.describe SuperGood::SolidusTaxjar::ApiParams do
)
end
+ let(:shipment) { Spree::Shipment.create!(cost: BigDecimal("3.01")) }
+
describe "#order_params" do
subject { described_class.order_params(order) }
diff --git a/spec/super_good/solidus_taxjar_spec.rb b/spec/super_good/solidus_taxjar_spec.rb
index 7fe0dee..d9ef1d4 100644
--- a/spec/super_good/solidus_taxjar_spec.rb
+++ b/spec/super_good/solidus_taxjar_spec.rb
@@ -77,9 +77,14 @@ RSpec.describe SuperGood::SolidusTaxjar do
describe ".shipping_calculator" do
subject { described_class.shipping_calculator.call(order) }
- let(:order) { instance_double(Spree::Order, shipment_total: 10) }
+ let(:order) { create :order }
+ let(:shipment) { create :shipment, order: order, cost: 20 }
- it "returns the shipment total" do
+ before do
+ create :adjustment, order: order, adjustable: shipment, amount: -10, eligible: true, source: create(:shipping_rate, shipment: shipment)
+ end
+
+ it "returns the shipment total including promotions" do
expect(subject).to eq(10)
end
end