mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-30 06:31:16 +00:00
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..
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user