mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Update checkout helper summing and add test coverage
This commit is contained in:
@@ -19,7 +19,7 @@ module CheckoutHelper
|
||||
adjustments.reject! { |a| a.originator_type == 'EnterpriseFee' && a.source_type != 'Spree::LineItem' }
|
||||
unless exclude.include? :admin_and_handling
|
||||
adjustments << Spree::Adjustment.new(
|
||||
label: I18n.t(:orders_form_admin), amount: enterprise_fee_adjustments.sum(:amount)
|
||||
label: I18n.t(:orders_form_admin), amount: enterprise_fee_adjustments.sum(&:amount)
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -31,4 +31,29 @@ describe CheckoutHelper, type: :helper do
|
||||
order.distributor.allow_guest_orders = false
|
||||
expect(helper.guest_checkout_allowed?).to be false
|
||||
end
|
||||
|
||||
describe "#checkout_adjustments_for" do
|
||||
let(:order) { create(:order_with_totals_and_distribution) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee, amount: 123) }
|
||||
let!(:fee_adjustment) {
|
||||
create(:adjustment, originator: enterprise_fee, adjustable: order, source: order)
|
||||
}
|
||||
|
||||
before do
|
||||
# Sanity check initial adjustments state
|
||||
expect(order.adjustments.shipping.count).to eq 1
|
||||
expect(order.adjustments.enterprise_fee.count).to eq 1
|
||||
end
|
||||
|
||||
it "collects adjustments on the order" do
|
||||
adjustments = helper.checkout_adjustments_for(order)
|
||||
|
||||
shipping_adjustment = order.adjustments.shipping.first
|
||||
expect(adjustments).to include shipping_adjustment
|
||||
|
||||
admin_fee_summary = adjustments.last
|
||||
expect(admin_fee_summary.label).to eq I18n.t(:orders_form_admin)
|
||||
expect(admin_fee_summary.amount).to eq 123
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user