diff options
author | Jared Norman <jared@super.gd> | 2019-01-24 17:57:06 -0800 |
---|---|---|
committer | Jared Norman <jared@super.gd> | 2019-01-28 10:35:05 -0800 |
commit | c9633203f85fc690ec0213aca4da7198dcd43f16 (patch) | |
tree | cb974be0ec61c1da8969bdb443e1cc5c35ecbd55 | |
parent | 0eb33f99cd2054230c5a3ba80ab8d3633f16c04b (diff) |
Introduce DiscountCalculator
This extracts the functionality of calculating the discount for a line
item in the interest of making this behaviour configurable for stores
that would like to factor in order level adjustments in some way.
-rw-r--r-- | lib/super_good/solidus_taxjar/discount_calculator.rb | 17 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar/discount_calculator_spec.rb | 13 |
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/super_good/solidus_taxjar/discount_calculator.rb b/lib/super_good/solidus_taxjar/discount_calculator.rb new file mode 100644 index 0000000..747a9d0 --- /dev/null +++ b/lib/super_good/solidus_taxjar/discount_calculator.rb @@ -0,0 +1,17 @@ +module SuperGood + module SolidusTaxJar + class DiscountCalculator + def initialize(line_item) + @line_item = line_item + end + + def discount + -line_item.promo_total + end + + private + + attr_reader :line_item + end + end +end diff --git a/spec/super_good/solidus_taxjar/discount_calculator_spec.rb b/spec/super_good/solidus_taxjar/discount_calculator_spec.rb new file mode 100644 index 0000000..b89b4dc --- /dev/null +++ b/spec/super_good/solidus_taxjar/discount_calculator_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +RSpec.describe SuperGood::SolidusTaxJar::DiscountCalculator do + describe "#discount" do + subject { calculator.discount } + + let(:calculator) { described_class.new line_item } + + let(:line_item) { ::Spree::LineItem.new(promo_total: 12.34) } + + it { is_expected.to eq(-12.34) } + end +end |