-
-
Notifications
You must be signed in to change notification settings - Fork 538
Fix #4172 donation validation display error #4483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
fc9cdb5
cbb2f85
a25a0d2
0585857
672e9b6
68cabfb
3560157
82a76fd
dfaa0e7
ba5af77
559b67d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -787,4 +787,4 @@ DEPENDENCIES | |
webmock (~> 3.23) | ||
|
||
BUNDLED WITH | ||
2.5.11 | ||
2.5.14 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,5 +172,77 @@ | |
expect(response.body).to_not include("you’ll need to make an adjustment to the inventory as well.") | ||
end | ||
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 and info the user entered" do | ||
item = create(:item, organization: organization, name: "Brightbloom Seed") | ||
storage_location = create(:storage_location, :with_items, item: item, item_quantity: 0, organization: organization) | ||
extra_item = create(:item, organization: organization, name: "Extra Item") | ||
TestInventory.create_inventory(organization, { storage_location.id => { item.id => 0, extra_item.id => 1 } }) | ||
original_quantity = 100 | ||
original_source = Donation::SOURCES[:manufacturer] | ||
original_date = DateTime.new(2024) | ||
donation = create(:manufacturer_donation, :with_items, item: item, item_quantity: original_quantity, issued_at: original_date, organization: organization, storage_location: storage_location, source: original_source) | ||
distribution = { | ||
storage_location_id: storage_location.id, | ||
partner_id: create(:partner).id, | ||
delivery_method: :delivery, | ||
line_items_attributes: { | ||
"0": { item_id: item.id, quantity: 90 } | ||
} | ||
} | ||
|
||
post distributions_path(distribution: distribution, format: :turbo_stream) | ||
|
||
edited_source = Donation::SOURCES[:product_drive] | ||
edited_source_drive = create(:product_drive, organization: organization) | ||
edited_source_drive_participant = create(:product_drive_participant, organization: organization) | ||
edited_storage_location = create(:storage_location, name: "Test Storage", organization: organization) | ||
edited_money = 10.0 | ||
edited_comment = "New test comment" | ||
edited_date = "2019-01-01" | ||
extra_quantity = 1 | ||
edited_quantity = 1 | ||
|
||
edited_donation = { | ||
source: edited_source, | ||
product_drive_id: edited_source_drive.id, | ||
product_drive_participant_id: edited_source_drive_participant.id, | ||
storage_location_id: edited_storage_location.id, | ||
money_raised_in_dollars: edited_money, | ||
comment: edited_comment, | ||
issued_at: edited_date, | ||
line_items_attributes: { | ||
"0": { item_id: item.id, quantity: edited_quantity }, | ||
"1": { item_id: extra_item.id, quantity: extra_quantity } | ||
} | ||
} | ||
|
||
put donation_path(id: donation.id, donation: edited_donation) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really what we're trying to hit, right? Why are we hitting all those other endpoints rather than just directly creating the data we want to interact with on this page? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think when I wrote this (several weeks ago at this point, I don't remember) I didn't know how the inventory system worked and that DistributionCreateService or TestInventory existed. I think this can be rewritten to just use TestInventory and set inventory to 0 before editing the donation, I will try that. I am thinking of adding TestInventory info and linking to the wiki Event page in CONTRIBUTING.md so new contributors have a easier time writing tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved by ba5af77 |
||
|
||
if Event.read_events?(organization) | ||
expect(flash[:alert]).to include("Error updating donation: Could not reduce quantity") | ||
else # TODO remove this branch when switching to events | ||
expect(flash[:alert]).to include("Error updating donation: Requested items exceed the available inventory") | ||
end | ||
|
||
expect(response.body).to include("Edit - Donations - #{original_source}") | ||
expect(response.body).to include("Editing Donation\n <small>from #{original_source}") | ||
expect(response.body).to include("<li class=\"breadcrumb-item\">\n <a href=\"#\">Editing #{original_source}") | ||
expect(response.body).to include("<option selected=\"selected\" value=\"#{edited_source}\">#{edited_source}</option>") | ||
expect(response.body).to include("<option selected=\"selected\" value=\"#{edited_source_drive.id}\">#{edited_source_drive.name}</option>") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to specify the name etc. (anything we're actually checking) when creating the data. This makes the tests less flaky and more easily reproducible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resolved by 82a76fd |
||
expect(response.body).to include("<option selected=\"selected\" value=\"#{edited_source_drive_participant.id}\">#{edited_source_drive_participant.business_name}</option>") | ||
expect(response.body).to include("<option selected=\"selected\" value=\"#{edited_storage_location.id}\">#{edited_storage_location.name}</option>") | ||
expect(response.body).to include(edited_comment) | ||
expect(response.body).to include("value=\"#{edited_money}\" type=\"text\" name=\"donation[money_raised_in_dollars]") | ||
expect(response.body).to include(edited_date) | ||
expect(response.body).to include("<option selected=\"selected\" value=\"#{item.id}\">#{item.name}</option>") | ||
expect(response.body).to include("value=\"#{edited_quantity}\" name=\"donation[line_items_attributes][0][quantity]") | ||
expect(response.body).to include("<option selected=\"selected\" value=\"#{extra_item.id}\">#{extra_item.name}</option>") | ||
expect(response.body).to include("value=\"#{extra_quantity}\" name=\"donation[line_items_attributes][1][quantity]") | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would put back any line items that the user removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you would have been right, but I originally put this line to pass donation controller request rspec tests which sent the _destroy parameter. Those tests I found out are outdated, the way the donation form is currently implemented the _destroy parameter is never sent, the donation object is just overridden with the new line_items_attributes. updated those rspec tests and removed this line in 3560157