Update checkout helper summing and add test coverage

This commit is contained in:
Matt-Yorkley
2021-01-15 17:23:58 +00:00
parent aacd942697
commit c0c7c6ec78
2 changed files with 26 additions and 1 deletions

View File

@@ -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

View File

@@ -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