Skip to content

Commit

Permalink
Merge pull request #3585 from coorasse/non-eligible-order-adjustments…
Browse files Browse the repository at this point in the history
…-with-test

Do not display non-eligible adjustments in the admin cart overview
  • Loading branch information
aldesantis authored Apr 21, 2020
2 parents 138bf61 + d898c02 commit 98d40b2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ Spree.Views.Order.DetailsAdjustments = Backbone.View.extend({
var totals = {};
var collection = this.collection ? this.collection.chain() : _.chain([this.model]);
collection
.map(function(item){ return item.get("adjustments") || [] })
.map(function(item) {
return (item.get("adjustments") || [])
.filter(function(adjustment) { return (adjustment.eligible === true); });
})
.flatten(true)
.each(function(adjustment){
var label = adjustment.label;
Expand Down
8 changes: 6 additions & 2 deletions backend/spec/features/admin/orders/adjustments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
let(:tax_category) { create(:tax_category) }
let(:variant) { create(:variant, tax_category: tax_category) }

let!(:non_eligible_adjustment) { order.adjustments.create!(order: order, label: 'Non-Eligible', amount: 10, eligible: false) }
let!(:adjustment) { order.adjustments.create!(order: order, label: 'Rebate', amount: 10) }

before(:each) do
Expand All @@ -40,8 +41,11 @@
end
end

it "only shows eligible adjustments" do
expect(page).not_to have_content("ineligible")
it "shows both eligible and non-eligible adjustments" do
expect(page).to have_content("Rebate")
expect(page).to have_content("Non-Eligible")
expect(find('tr', text: 'Rebate')[:class]).not_to eq('adjustment-ineligible')
expect(find('tr', text: 'Non-Eligible')[:class]).to eq('adjustment-ineligible')
end
end

Expand Down
15 changes: 15 additions & 0 deletions backend/spec/features/admin/orders/order_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,21 @@
end
end

context "with adjustments" do
let(:order) do
super().tap do |o|
o.adjustments.create!(order: order, label: 'Non-Eligible', amount: 10, eligible: false)
o.adjustments.create!(order: order, label: 'Rebate', amount: 10)
end
end

it "shows only eligible adjustments" do
visit spree.cart_admin_order_path(order)
expect(page).to have_content("Rebate")
expect(page).not_to have_content("Non-Eligible")
end
end

context "variant doesn't track inventory" do
let(:track_inventory) { false }
let(:backorderable) { false }
Expand Down

0 comments on commit 98d40b2

Please sign in to comment.