Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not display non-eligible adjustments in the admin cart overview #3585

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page shows both eligible and non-eligible adjustments, and that's correct, because it highlights if they are not eligiblew by adding the class adjustment-ineligible. This test now checks that.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the regression test.


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