mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Can sort orders via bill_address.lastname
We only need to check the orders sort Fix ordering in api/v0/orders_controller_spec
This commit is contained in:
committed by
Jean-Baptiste Bellet
parent
45beefc533
commit
35e20fc179
@@ -19,7 +19,7 @@ class SearchOrders
|
||||
includes(:payments, :subscription, :shipments, :bill_address, :distributor, :order_cycle).
|
||||
ransack(params[:q])
|
||||
|
||||
@search.result(distinct: true)
|
||||
@search.result(distinct: true).joins(:bill_address)
|
||||
end
|
||||
|
||||
def search_query
|
||||
|
||||
@@ -21,18 +21,19 @@ 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), total: 5.0)
|
||||
distributor: distributor, billing_address: create(:address, lastname: "c"), 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), total: 10.0)
|
||||
distributor: distributor2, billing_address: create(:address, lastname: "a"), 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), total: 1.0 )
|
||||
distributor: distributor, billing_address: create(:address, lastname: "b"), total: 1.0 )
|
||||
end
|
||||
let!(:order4) do
|
||||
create(:completed_order_with_fees, order_cycle: order_cycle2, distributor: distributor2, total: 15.0)
|
||||
create(:completed_order_with_fees, order_cycle: order_cycle2, distributor: distributor2,
|
||||
billing_address: create(:address, lastname: "d"), total: 15.0)
|
||||
end
|
||||
let!(:order5) { create(:order, state: 'cart', completed_at: nil) }
|
||||
let!(:line_item1) do
|
||||
@@ -134,6 +135,13 @@ module Api
|
||||
|
||||
expect(json_response['orders']).to eq serialized_orders([order4, order2, order1, order3])
|
||||
end
|
||||
|
||||
it 'can sort orders by bill_address.lastname' do
|
||||
get :index, params: { q: { completed_at_not_null: true, s: 'bill_address_lastname ASC' } },
|
||||
as: :json
|
||||
|
||||
expect(json_response['orders'].map{ |o| o[:id] }).to eq serialized_orders([order2, order3, order1, order4]).map{ |o| o["id"] }
|
||||
end
|
||||
end
|
||||
|
||||
context 'with pagination' do
|
||||
|
||||
Reference in New Issue
Block a user