diff --git a/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor.rb b/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor.rb index 4152731bcf..728f01c35b 100644 --- a/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor.rb +++ b/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor.rb @@ -24,7 +24,8 @@ module Reporting header: true, }, { - group_by: proc { |line_items, _row| line_items.first.variant } + group_by: proc { |line_items, _row| line_items.first.variant }, + sort_by: proc { |variant| variant.product.name } }, { group_by: :hub, diff --git a/spec/lib/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor_report_spec.rb index d99bd2b28f..807089057e 100644 --- a/spec/lib/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor_report_spec.rb @@ -9,7 +9,7 @@ module Reporting let!(:distributor) { create(:distributor_enterprise) } let!(:order) do - create(:completed_order_with_totals, line_items_count: 1, distributor: distributor) + create(:completed_order_with_totals, line_items_count: 3, distributor: distributor) end let(:current_user) { distributor.owner } @@ -23,7 +23,7 @@ module Reporting end it "generates the report" do - expect(report_table.length).to eq(2) + expect(report_table.length).to eq(6) end it "has a variant row under the distributor" do @@ -31,6 +31,14 @@ module Reporting expect(report.rows.first.producer).to eq supplier.name expect(report.rows.first.hub).to eq distributor.name end + + it "lists products sorted by name" do + order.line_items[0].variant.product.update(name: "Cucumber") + order.line_items[1].variant.product.update(name: "Apple") + order.line_items[2].variant.product.update(name: "Banane") + product_names = report.rows.map(&:product).filter(&:present?) + expect(product_names).to eq(["Apple", "Banane", "Cucumber"]) + end end end end