Skip to content

Commit

Permalink
Merge pull request #8270 from achauve/8161-fix-sorting-admin-orders-b…
Browse files Browse the repository at this point in the history
…y-total

Fix sorting admin orders by total
  • Loading branch information
andrewpbrett authored Oct 5, 2021
2 parents 9b9db32 + 45eefb6 commit f3ef3bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Order < ApplicationRecord
include Balance

searchable_attributes :number, :state, :shipment_state, :payment_state, :distributor_id,
:order_cycle_id, :email
:order_cycle_id, :email, :total
searchable_associations :shipping_method, :bill_address
searchable_scopes :complete, :incomplete

Expand Down
21 changes: 17 additions & 4 deletions spec/controllers/api/v0/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ module Api
let!(:order_cycle2) { create(:simple_order_cycle, coordinator: coordinator2) }
let!(:order1) do
create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now,
distributor: distributor, billing_address: create(:address) )
distributor: distributor, billing_address: create(:address), total: 5.0)
end
let!(:order2) do
create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now,
distributor: distributor2, billing_address: create(:address) )
distributor: distributor2, billing_address: create(:address), total: 10.0)
end
let!(:order3) do
create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now,
distributor: distributor, billing_address: create(:address) )
distributor: distributor, billing_address: create(:address), total: 1.0 )
end
let!(:order4) do
create(:completed_order_with_fees, order_cycle: order_cycle2, distributor: distributor2)
create(:completed_order_with_fees, order_cycle: order_cycle2, distributor: distributor2, total: 15.0)
end
let!(:order5) { create(:order, state: 'cart', completed_at: nil) }
let!(:line_item1) do
Expand Down Expand Up @@ -123,6 +123,19 @@ module Api
end
end

context 'sorting' do
before do
allow(controller).to receive(:spree_current_user) { admin_user }
end

it 'can sort orders by total' do
get :index, params: { q: { completed_at_not_null: true, s: 'total desc' } },
as: :json

expect(json_response['orders']).to eq serialized_orders([order4, order2, order1, order3])
end
end

context 'with pagination' do
before do
allow(controller).to receive(:spree_current_user) { distributor.owner }
Expand Down

0 comments on commit f3ef3bb

Please sign in to comment.