From 1078e7cd369c9bdf29684c5a6bdb05813f8ad378 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 5 Sep 2024 10:26:45 +1000 Subject: [PATCH 1/3] Update specs The key here is the enterprise_relationship. This is required for the supplier to have permission to see the orders. Curiously, the unit test still passes. All will be revealed in the next commit.. --- ...plier_totals_by_distributor_report_spec.rb | 34 +++++++++++----- .../reports/orders_and_fulfillment_spec.rb | 39 ++++++++++--------- 2 files changed, 44 insertions(+), 29 deletions(-) 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 490787cf82..ff73f6d12e 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 @@ -7,12 +7,12 @@ module Reporting module OrdersAndFulfillment RSpec.describe OrderCycleSupplierTotalsByDistributor do let!(:distributor) { create(:distributor_enterprise) } - let!(:order) do - create(:completed_order_with_totals, line_items_count: 3, distributor:) - end - let(:supplier) { order.line_items.first.variant.supplier } + let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) } describe "as the distributor" do + let!(:order) do + create(:completed_order_with_totals, line_items_count: 3, distributor:) + end let(:current_user) { distributor.owner } let(:params) { { display_summary_row: true } } let(:report) do @@ -42,18 +42,32 @@ module Reporting end end - describe "as the supplier of the order cycle" do + describe "as the supplier permitting products in the order cycle" do + let!(:order) { + create(:completed_order_with_totals, line_items_count: 0, distributor:, + order_cycle_id: order_cycle.id) + } + let(:supplier){ order.line_items.first.variant.supplier } + before do - pending("S2 bug fix - #12835") + 3.times do + owner = create(:user) + s = create(:supplier_enterprise, owner:) + variant = create(:variant, supplier: s) + create(:line_item_with_shipment, variant:, quantity: 1, order:) + end + + create(:enterprise_relationship, parent: supplier, child: distributor, + permissions_list: [:add_to_order_cycle]) end - let!(:current_user) { supplier.owner } - let!(:params) { { display_summary_row: true } } - let!(:report) do + let(:current_user) { supplier.owner } + let(:params) { { display_summary_row: true } } + let(:report) do OrderCycleSupplierTotalsByDistributor.new(current_user, params) end - let!(:report_table) do + let(:report_table) do report.table_rows end diff --git a/spec/system/admin/reports/orders_and_fulfillment_spec.rb b/spec/system/admin/reports/orders_and_fulfillment_spec.rb index 4495b82700..036876aa87 100644 --- a/spec/system/admin/reports/orders_and_fulfillment_spec.rb +++ b/spec/system/admin/reports/orders_and_fulfillment_spec.rb @@ -423,14 +423,19 @@ RSpec.describe "Orders And Fulfillment" do end end - context "as the supplier" do + context "as the supplier granting P-OC to distributor" do let(:current_user) { supplier.owner } before do - pending("S2 bug fix - #12835") + create(:enterprise_relationship, parent: supplier, child: distributor, + permissions_list: [:add_to_order_cycle]) + login_as(current_user) - visit admin_reports_path - click_link "Order Cycle Supplier Totals by Distributor" + visit admin_report_path(:orders_and_fulfillment, + :order_cycle_supplier_totals_by_distributor) + + uncheck "Header Row" + pending("S2 bug fix - #12835") run_report end @@ -456,24 +461,20 @@ RSpec.describe "Orders And Fulfillment" do end it "aggregates results per variant" do - expect(all('table.report__table tbody tr').count).to eq(4) + rows = find("table.report__table").all("tbody tr") + table = rows.map { |r| r.all("td").map { |c| c.text.strip } } + + expect(table.count).to eq(4) # 1 row per variant = 2 rows - # 2 TOTAL rows + # 2 TOTAL rows for distributors # 4 rows total - expect(table_headers[0]).to eq( - ["Supplier Name", "Baked Beans", "1g Small", - "Distributor Name", "7", "10.0", "70.0", "UPS Ground"] - ) - expect(table_headers[1]).to eq( - ["", "", "", "TOTAL", "7", "", "70.0", ""] - ) - expect(table_headers[2]).to eq( - ["Supplier Name", "Baked Beans", "1g Big", - "Distributor Name", - "3", "10.0", "30.0", "UPS Ground"] - ) - expect(table_headers[3]).to eq(["", "", "", "TOTAL", "3", "", "30.0", ""]) + expect(table[0]).to eq(["Supplier Name", "Baked Beans", "1g Big", + "Distributor Name", "3", "10.0", "30.0", "UPS Ground"]) + expect(table[1]).to eq(["", "", "", "TOTAL", "3", "", "30.0", ""]) + expect(table[2]).to eq(["Supplier Name", "Baked Beans", "1g Small", + "Distributor Name", "7", "10.0", "70.0", "UPS Ground"]) + expect(table[3]).to eq(["", "", "", "TOTAL", "7", "", "70.0", ""]) end end end From a9ad6a28515adbc79f629930fc77520822ec8c86 Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 17 Sep 2024 11:15:21 +1000 Subject: [PATCH 2/3] Grant product managers ability to create reports We missed this in c31416c, oops. --- app/models/spree/ability.rb | 2 +- spec/system/admin/reports/orders_and_fulfillment_spec.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/spree/ability.rb b/app/models/spree/ability.rb index e7c050aa24..580416b60d 100644 --- a/app/models/spree/ability.rb +++ b/app/models/spree/ability.rb @@ -243,7 +243,7 @@ module Spree can [:admin, :index], ::Admin::DfcProductImportsController # Reports page - can [:admin, :index, :show], ::Admin::ReportsController + can [:admin, :index, :show, :create], ::Admin::ReportsController can [:admin, :show, :create, :customers, :orders_and_distributors, :group_buys, :payments, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management, :packing, :enterprise_fee_summary, :bulk_coop], :report diff --git a/spec/system/admin/reports/orders_and_fulfillment_spec.rb b/spec/system/admin/reports/orders_and_fulfillment_spec.rb index 036876aa87..49fd56071d 100644 --- a/spec/system/admin/reports/orders_and_fulfillment_spec.rb +++ b/spec/system/admin/reports/orders_and_fulfillment_spec.rb @@ -435,7 +435,6 @@ RSpec.describe "Orders And Fulfillment" do :order_cycle_supplier_totals_by_distributor) uncheck "Header Row" - pending("S2 bug fix - #12835") run_report end From 296997d558f8a7c6ae9d408de93f971db71c3ede Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 17 Sep 2024 13:23:14 +1000 Subject: [PATCH 3/3] Test to ensure report abilities --- spec/models/spree/ability_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index f8ed7b32f6..36990394a7 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -415,7 +415,7 @@ RSpec.describe Spree::Ability do it "should be able to read some reports" do is_expected.to have_ability( - [:admin, :index, :show], for: Admin::ReportsController + [:admin, :index, :show, :create], for: Admin::ReportsController ) is_expected.to have_ability( [:customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory, @@ -651,7 +651,7 @@ RSpec.describe Spree::Ability do it "should be able to read some reports" do is_expected.to have_ability( - [:admin, :index, :show], for: Admin::ReportsController + [:admin, :index, :show, :create], for: Admin::ReportsController ) is_expected.to have_ability( [:customers, :sales_tax, :group_buys, :bulk_coop, :payments,