Skip to content

Commit

Permalink
Expose Spree::Promotion::OrderAdjustmentsRecalculator#calculate_eligi…
Browse files Browse the repository at this point in the history
…bility bug

Spec to expose the inaccurate adjustment eligibility with shipping promotion action during Spree::Promotion::OrderAdjustmentsRecalculator call
  • Loading branch information
julienanne committed Mar 2, 2023
1 parent 6d55800 commit 254b9c6
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,45 @@
end
end

context "with a shipping promotion" do
let(:admin_user) { create(:admin_user) }

let(:order) { create(:order_with_line_items, line_items_count: 1, line_items_price: 10, user: admin_user) }

let(:promotion) { create(:promotion, :with_free_shipping) }
let!(:promotion_rule) do
rule = Spree::Promotion::Rules::UserRole.create!(
promotion: promotion,
preferred_role_ids: admin_user.spree_roles.ids,
preferred_match_policy: "all"
)
promotion.rules << rule
promotion.save!
rule
end

let(:shipment) { order.shipments.first }

before do
promotion.activate(order: order)
order.recalculate

# Spree::Promotion::Rules::UserRole only for admin role
# So we make the user not an admin
# and expect the subject will mark as non eligible the shipment adjustment
admin_user.spree_roles = []
admin_user.save!
end

it 'updates the promotion adjustments eligible attribute' do
expect {
subject
}.to change {
shipment.adjustments.first.eligible
}.from(true).to(false)
end
end

context 'promotion chooser customization' do
before do
class Spree::TestPromotionChooser
Expand Down

0 comments on commit 254b9c6

Please sign in to comment.