mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #8270 from achauve/8161-fix-sorting-admin-orders-by-total
Fix sorting admin orders by total
This commit is contained in:
@@ -12,7 +12,7 @@ module Spree
|
||||
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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user