From da4504fff140285c12b7f29d45288fce8a2be638 Mon Sep 17 00:00:00 2001 From: Giovanny Cordeiro Date: Tue, 10 Jun 2025 16:08:24 +0000 Subject: [PATCH 1/4] refact: change of unknown for zero --- app/views/reports/itemized_distributions.html.erb | 2 +- app/views/reports/itemized_donations.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/reports/itemized_distributions.html.erb b/app/views/reports/itemized_distributions.html.erb index 2cc88311a6..f111604f63 100644 --- a/app/views/reports/itemized_distributions.html.erb +++ b/app/views/reports/itemized_distributions.html.erb @@ -27,7 +27,7 @@ <%= item[:name] %> <%= item[:distributed] %> - <%= item[:current_onhand] || "Unknown" %> + <%= item[:current_onhand] || "0" %> <% end %> diff --git a/app/views/reports/itemized_donations.html.erb b/app/views/reports/itemized_donations.html.erb index dfdba32ad0..96c7306518 100644 --- a/app/views/reports/itemized_donations.html.erb +++ b/app/views/reports/itemized_donations.html.erb @@ -27,7 +27,7 @@ <%= item[:name] %> <%= item[:donated] %> - <%= item[:current_onhand] || "Unknown" %> + <%= item[:current_onhand] || "0" %> <% end %> From 74c3bc3f5208e086ecd025db5ed99a3fcc201a0f Mon Sep 17 00:00:00 2001 From: Giovanny Cordeiro Date: Wed, 11 Jun 2025 13:59:29 +0000 Subject: [PATCH 2/4] test: ensure that the default value is 0 instead of unknown --- .../reports_distributions_system_spec.rb | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 spec/system/reports_distributions_system_spec.rb diff --git a/spec/system/reports_distributions_system_spec.rb b/spec/system/reports_distributions_system_spec.rb new file mode 100644 index 0000000000..518b935c16 --- /dev/null +++ b/spec/system/reports_distributions_system_spec.rb @@ -0,0 +1,96 @@ +RSpec.describe "Reports Distributions", type: :system, js: true do + let(:organization) { create(:organization) } + let(:user) { create(:user, organization: organization) } + let(:organization_admin) { create(:organization_admin, organization: organization) } + let!(:partner) { create(:partner, organization: organization, name: "Test Partner") } + let!(:storage_location) { create(:storage_location, organization: organization, name: "Test Storage Location") } + + context "while logged in" do + before do + sign_in(user) + end + + context "Distributions - Itemized" do + before do + create(:item, organization: organization) + create(:storage_location, organization: organization) + create(:donation_site, organization: organization) + create(:product_drive, organization: organization) + create(:product_drive_participant, organization: organization) + create(:product_drive_participant, organization: organization, contact_name: "contact without business name", business_name: "") + create(:manufacturer, organization: organization) + organization.reload + + visit new_donation_path + + select Donation::SOURCES[:misc], from: "donation_source" + select StorageLocation.first.name, from: "donation_storage_location_id" + select Item.alphabetized.first.name, from: "donation_line_items_attributes_0_item_id" + fill_in "donation_line_items_attributes_0_quantity", with: "5" + fill_in "donation_issued_at", with: "2001-01-01" + + click_button "Save" + + visit new_distribution_path + end + + it "Ensuring that the result of the distribution index is zero instead of Unknow" do + select "Test Partner", from: "Partner" + select "Test Storage Location", from: "From storage location" + fill_in "distribution_line_items_attributes_0_quantity", with: "5" + choose "Pick up" + + click_button "Save", match: :first + within "#distributionConfirmationModal" do + click_button "Yes, it's correct" + end + + visit reports_itemized_distributions_path + + expect(page).to have_selector(:table_row, "Total On Hand" => "0") + end + end + + context "Donations - Itemized" do + let(:donation) { create :donation, :with_items } + + before do + create(:item, organization: organization) + create(:storage_location, organization: organization) + create(:donation_site, organization: organization) + create(:product_drive, organization: organization) + create(:product_drive_participant, organization: organization) + create(:product_drive_participant, organization: organization, contact_name: "contact without business name", business_name: "") + create(:manufacturer, organization: organization) + organization.reload + end + + it "Ensuring that the result of the donation index is zero instead of Unknow" do + visit new_donation_path + select Donation::SOURCES[:misc], from: "donation_source" + select StorageLocation.first.name, from: "donation_storage_location_id" + select Item.alphabetized.first.name, from: "donation_line_items_attributes_0_item_id" + fill_in "donation_line_items_attributes_0_quantity", with: "20" + fill_in "donation_issued_at", with: "2025-04-15" + + click_button "Save" + + visit new_distribution_path + + select "Test Partner", from: "Partner" + select "Test Storage Location", from: "From storage location" + fill_in "distribution_line_items_attributes_0_quantity", with: "20" + choose "Pick up" + + click_button "Save", match: :first + + within "#distributionConfirmationModal" do + click_button "Yes, it's correct" + end + + visit reports_itemized_donations_path + expect(page).to have_selector(:table_row, "Total On Hand" => "0") + end + end + end +end From 31b38c6104ce60782c2c41229d24180ad8dde892 Mon Sep 17 00:00:00 2001 From: Giovanny Cordeiro Date: Wed, 18 Jun 2025 18:09:57 +0000 Subject: [PATCH 3/4] fix: Error due to missing filter setting --- spec/system/reports_distributions_system_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/system/reports_distributions_system_spec.rb b/spec/system/reports_distributions_system_spec.rb index 518b935c16..12c4b21412 100644 --- a/spec/system/reports_distributions_system_spec.rb +++ b/spec/system/reports_distributions_system_spec.rb @@ -89,6 +89,9 @@ end visit reports_itemized_donations_path + fill_in "filters_date_range", with: "April 15, 2025 - July 15, 2025" + click_button "Filter" + expect(page).to have_selector(:table_row, "Total On Hand" => "0") end end From 43f0c716663054cf8203fe619887e663ca802101 Mon Sep 17 00:00:00 2001 From: Giovanny Cordeiro Date: Mon, 7 Jul 2025 12:47:37 +0000 Subject: [PATCH 4/4] refact: changing for requests test --- .../reports_distributions_system_spec.rb | 134 ++++++++---------- 1 file changed, 61 insertions(+), 73 deletions(-) diff --git a/spec/system/reports_distributions_system_spec.rb b/spec/system/reports_distributions_system_spec.rb index 12c4b21412..9b68be66d2 100644 --- a/spec/system/reports_distributions_system_spec.rb +++ b/spec/system/reports_distributions_system_spec.rb @@ -1,98 +1,86 @@ -RSpec.describe "Reports Distributions", type: :system, js: true do +RSpec.describe "Reports Distributions", type: :request do let(:organization) { create(:organization) } + let(:storage_location) { create(:storage_location, name: "Pawane Location", organization: organization) } let(:user) { create(:user, organization: organization) } let(:organization_admin) { create(:organization_admin, organization: organization) } - let!(:partner) { create(:partner, organization: organization, name: "Test Partner") } - let!(:storage_location) { create(:storage_location, organization: organization, name: "Test Storage Location") } - context "while logged in" do + describe "while signed in" do before do sign_in(user) end - context "Distributions - Itemized" do - before do - create(:item, organization: organization) - create(:storage_location, organization: organization) - create(:donation_site, organization: organization) - create(:product_drive, organization: organization) - create(:product_drive_participant, organization: organization) - create(:product_drive_participant, organization: organization, contact_name: "contact without business name", business_name: "") - create(:manufacturer, organization: organization) - organization.reload - - visit new_donation_path - - select Donation::SOURCES[:misc], from: "donation_source" - select StorageLocation.first.name, from: "donation_storage_location_id" - select Item.alphabetized.first.name, from: "donation_line_items_attributes_0_item_id" - fill_in "donation_line_items_attributes_0_quantity", with: "5" - fill_in "donation_issued_at", with: "2001-01-01" - - click_button "Save" + describe "Distributions - Itemized" do + let(:product_drive) { create(:product_drive, organization:) } + let(:storage_location) { create(:storage_location, organization:) } + let(:manufacturer) { create(:manufacturer, organization:) } + let(:source) { Donation::SOURCES[:manufacturer] } + let(:issued_at) { Date.yesterday } + let(:money_raised) { 5 } + let(:item) { create(:item, organization:) } + + let(:params) do + { + donation: { + source: Donation::SOURCES[:manufacturer], + manufacturer_id: manufacturer.id, + product_drive_id: product_drive.id, + storage_location_id: storage_location.id, + money_raised_in_dollars: money_raised, + product_drive_participant_id: nil, + comment: "", + issued_at: issued_at, + line_items_attributes: { + "0": {item_id: item.id, quantity: 10} + } + } + } + end - visit new_distribution_path + let!(:partner) { create(:partner, organization: organization) } + let(:distribution) do + { + storage_location_id: storage_location.id, + partner_id: partner.id, + issued_at:, + delivery_method: :delivery, + line_items_attributes: { + "0": {item_id: item.id, quantity: 10} + } + } end it "Ensuring that the result of the distribution index is zero instead of Unknow" do - select "Test Partner", from: "Partner" - select "Test Storage Location", from: "From storage location" - fill_in "distribution_line_items_attributes_0_quantity", with: "5" - choose "Pick up" - - click_button "Save", match: :first - within "#distributionConfirmationModal" do - click_button "Yes, it's correct" - end - - visit reports_itemized_distributions_path + post donations_path(params) + expect(response).to redirect_to(donations_path) - expect(page).to have_selector(:table_row, "Total On Hand" => "0") - end - end + post distributions_path(distribution:, format: :turbo_stream) + expect(response).to have_http_status(:redirect) - context "Donations - Itemized" do - let(:donation) { create :donation, :with_items } + get reports_itemized_distributions_path - before do - create(:item, organization: organization) - create(:storage_location, organization: organization) - create(:donation_site, organization: organization) - create(:product_drive, organization: organization) - create(:product_drive_participant, organization: organization) - create(:product_drive_participant, organization: organization, contact_name: "contact without business name", business_name: "") - create(:manufacturer, organization: organization) - organization.reload + expect(response).to have_http_status(:ok) + expect(response.body).to include("Total On Hand") + page = Nokogiri::HTML(response.body) + page.css("table tbody tr td:last-child").each do |item| + expect(item.content.strip).to eq("0") + end end it "Ensuring that the result of the donation index is zero instead of Unknow" do - visit new_donation_path - select Donation::SOURCES[:misc], from: "donation_source" - select StorageLocation.first.name, from: "donation_storage_location_id" - select Item.alphabetized.first.name, from: "donation_line_items_attributes_0_item_id" - fill_in "donation_line_items_attributes_0_quantity", with: "20" - fill_in "donation_issued_at", with: "2025-04-15" - - click_button "Save" + post donations_path(params) + expect(response).to redirect_to(donations_path) - visit new_distribution_path + post distributions_path(distribution:, format: :turbo_stream) + expect(response).to have_http_status(:redirect) - select "Test Partner", from: "Partner" - select "Test Storage Location", from: "From storage location" - fill_in "distribution_line_items_attributes_0_quantity", with: "20" - choose "Pick up" + get reports_itemized_donations_path - click_button "Save", match: :first - - within "#distributionConfirmationModal" do - click_button "Yes, it's correct" + expect(response).to have_http_status(:ok) + expect(response.body).to include("Total On Hand") + page = Nokogiri::HTML(response.body) + page.css("table tbody tr td:last-child").each do |item| + expect(item.content.strip).to eq("0") end - - visit reports_itemized_donations_path - fill_in "filters_date_range", with: "April 15, 2025 - July 15, 2025" - click_button "Filter" - - expect(page).to have_selector(:table_row, "Total On Hand" => "0") end end end