mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #3076 from Matt-Yorkley/orders_checkboxes
Fix checkbox values on orders page
This commit is contained in:
@@ -25,8 +25,9 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, RequestMonitor,
|
||||
'q[email_cont]': $scope['q']['email_cont'],
|
||||
'q[bill_address_firstname_start]': $scope['q']['bill_address_firstname_start'],
|
||||
'q[bill_address_lastname_start]': $scope['q']['bill_address_lastname_start'],
|
||||
'q[completed_at_not_null]': $scope['q']['completed_at_not_null'],
|
||||
'q[inventory_units_shipment_id_null]': $scope['q']['inventory_units_shipment_id_null'],
|
||||
# Set default checkbox values to null. See: https://github.com/openfoodfoundation/openfoodnetwork/pull/3076#issuecomment-440010498
|
||||
'q[completed_at_not_null]': $scope['q']['completed_at_not_null'] || null,
|
||||
'q[inventory_units_shipment_id_null]': $scope['q']['inventory_units_shipment_id_null'] || null,
|
||||
'q[distributor_id_in]': $scope['q']['distributor_id_in'],
|
||||
'q[order_cycle_id_in]': $scope['q']['order_cycle_id_in'],
|
||||
'q[order_cycle_id_in]': $scope['q']['order_cycle_id_in'],
|
||||
|
||||
@@ -26,11 +26,11 @@ class SearchOrders
|
||||
@search = OpenFoodNetwork::Permissions.new(current_user).editable_orders.ransack(params[:q])
|
||||
|
||||
return paginated_results if using_pagination?
|
||||
@search.result
|
||||
@search.result(distinct: true)
|
||||
end
|
||||
|
||||
def paginated_results
|
||||
@search.result
|
||||
@search.result(distinct: true)
|
||||
.page(params[:page])
|
||||
.per(params[:per_page])
|
||||
end
|
||||
|
||||
@@ -24,6 +24,8 @@ module Api
|
||||
create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now,
|
||||
distributor: distributor, billing_address: create(:address) )
|
||||
end
|
||||
let!(:order4) { create(:completed_order_with_fees) }
|
||||
let!(:order5) { create(:order, state: 'cart', completed_at: nil) }
|
||||
let!(:line_item1) do
|
||||
create(:line_item, order: order1,
|
||||
product: create(:product, supplier: supplier))
|
||||
@@ -119,6 +121,24 @@ module Api
|
||||
end
|
||||
end
|
||||
|
||||
context 'using search filters' do
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { admin_user }
|
||||
end
|
||||
|
||||
it 'can show only completed orders' do
|
||||
get :index, format: :json, q: { completed_at_not_null: true, s: 'created_at desc' }
|
||||
|
||||
expect(json_response['orders']).to eq serialized_orders([order4, order3, order2, order1])
|
||||
end
|
||||
|
||||
it 'can show only unfulfilled orders' do
|
||||
get :index, format: :json, q: { inventory_units_shipment_id_null: true, s: 'created_at desc' }
|
||||
|
||||
expect(json_response['orders']).to eq serialized_orders([order3, order2, order1])
|
||||
end
|
||||
end
|
||||
|
||||
context 'with pagination' do
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { distributor.owner }
|
||||
@@ -128,7 +148,7 @@ module Api
|
||||
get :index, per_page: 15, page: 1
|
||||
|
||||
pagination_data = {
|
||||
'results' => 2,
|
||||
'results' => 3,
|
||||
'pages' => 1,
|
||||
'page' => 1,
|
||||
'per_page' => 15
|
||||
@@ -141,6 +161,16 @@ module Api
|
||||
|
||||
private
|
||||
|
||||
def serialized_orders(orders)
|
||||
serialized_orders = ActiveModel::ArraySerializer.new(
|
||||
orders,
|
||||
each_serializer: Api::Admin::OrderSerializer,
|
||||
root: false
|
||||
)
|
||||
|
||||
JSON.parse(serialized_orders.to_json)
|
||||
end
|
||||
|
||||
def returns_orders(response)
|
||||
keys = response['orders'].first.keys.map(&:to_sym)
|
||||
expect(order_attributes.all?{ |attr| keys.include? attr }).to be_truthy
|
||||
|
||||
Reference in New Issue
Block a user