Skip to content

Commit

Permalink
RED donation quantity edit validation system test
Browse files Browse the repository at this point in the history
When edited donation amount plus available inventory is less than requested
inventory for distribution, it should redirect to the edit donation page,
display an error, the original donated item name, and the original amount
  • Loading branch information
jimmyli97 committed Jun 27, 2024
1 parent d0e678f commit 5c4780d
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions spec/system/donation_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -561,13 +561,13 @@

context "When editing an existing donation" do
before do
item = create(:item, organization: organization, name: "Rare Candy")
create(:storage_location, organization: organization)
@item = create(:item, organization: organization, name: "Rare Candy")
@storage_location = create(:storage_location, organization: organization)
create(:donation_site, organization: organization)
create(:product_drive, organization: organization)
create(:product_drive_participant, organization: organization)
create(:manufacturer, organization: organization)
create(:donation, :with_items, item: item, organization: organization)
create(:donation, :with_items, item: @item, organization: organization, storage_location: @storage_location)
organization.reload
visit donations_path
end
Expand Down Expand Up @@ -599,6 +599,29 @@
expect(donation.money_raised).to eq(10002)
end

# Bug fix - Issue #4172
context "when donated items are distributed to less than donated amount " \
"and you edit the donation to less than distributed amount" do
it "shows a warning and displays original names and amounts" do
partner = create(:partner)
visit new_distribution_path
select partner.name, from: "Partner"
select @storage_location.name, from: "From storage location"
fill_in "distribution_line_items_attributes_0_quantity", with: "99"
click_button "Save"
click_button "Yes, it's correct"

visit donations_path
click_on "View"
click_on "Make a correction"
fill_in "donation_line_items_attributes_0_quantity", with: "1"
click_on "Save"

expect(page).to have_content("Error updating donation: Requested items exceed the available inventory")
expect(page).to have_xpath("//select[@id='donation_line_items_attributes_0_item_id']", text: @item.name)
end
end

it "Does not default a selection if item lookup fails" do
total_quantity = find("#donation_quantity").text
expect(total_quantity).to_not eq "0"
Expand Down

0 comments on commit 5c4780d

Please sign in to comment.