Skip to content

Commit

Permalink
Add reusable action adjustment trait on Promotion factory
Browse files Browse the repository at this point in the history
Currently, we do not have a factory for Promotion::Actions and the
existing adjustment traits are not flexible. This trait will be useful,
for more flexiblity when testing non out-of-the-box Promotion Actions
and different calculators.
  • Loading branch information
RyanofWoods committed Oct 21, 2022
1 parent d54172b commit f719ed8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/lib/spree/testing_support/factories/promotion_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
end
end

trait :with_adjustable_action do
transient do
preferred_amount { 10 }
calculator_class { Spree::Calculator::FlatRate }
promotion_action_class { Spree::Promotion::Actions::CreateItemAdjustments }
end

after(:create) do |promotion, evaluator|
calculator = evaluator.calculator_class.new
calculator.preferred_amount = evaluator.preferred_amount
evaluator.promotion_action_class.create!(calculator: calculator, promotion: promotion)
end
end

factory :promotion_with_action_adjustment, traits: [:with_adjustable_action]

trait :with_line_item_adjustment do
transient do
adjustment_rate { 10 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
it_behaves_like 'a working factory'
end

describe 'promotion with action adjustment' do
let(:factory) { :promotion_with_action_adjustment }

it_behaves_like 'a working factory'
end

describe 'promotion with item adjustment' do
let(:factory) { :promotion_with_item_adjustment }

Expand Down

0 comments on commit f719ed8

Please sign in to comment.