From 4740c2b0dbc37e94744fb2dfb703367d3aa17bd5 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Tue, 18 Oct 2022 07:47:16 +0100 Subject: [PATCH 1/4] add sort by product name to order_cycle_supplier_totals_by_distributor report rules --- .../order_cycle_supplier_totals_by_distributor.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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, From 39e567d3868257105911cb0576a92ec8401521aa Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Mon, 24 Oct 2022 08:58:55 +0100 Subject: [PATCH 2/4] set line_items_count to 3 --- .../order_cycle_supplier_totals_by_distributor_report_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..eb81de9872 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 } From 732ebd84570cba9ba5fd63f9f917168eb744e448 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Mon, 24 Oct 2022 08:59:49 +0100 Subject: [PATCH 3/4] fix the expected table size in "generates the report" test --- .../order_cycle_supplier_totals_by_distributor_report_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 eb81de9872..a6f8e0a9d6 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 @@ -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 From da9a4803ff1c9af4b905b1629080d7992fb6ca08 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Mon, 24 Oct 2022 09:00:41 +0100 Subject: [PATCH 4/4] add it "lists products sorted by name" test --- ...er_cycle_supplier_totals_by_distributor_report_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) 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 a6f8e0a9d6..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 @@ -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