Skip to content
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

Fix #4172 donation validation display error #4483

Merged
merged 11 commits into from
Aug 4, 2024

Conversation

jimmyli97
Copy link
Contributor

@jimmyli97 jimmyli97 commented Jun 28, 2024

Resolves #4172

Description

  • donation items are now correctly displayed after invalid edit would bring inventory to below distributed amount
  • rspec request test for above

Alternatives considered

  • in the rspec, not sure how specific to be in the error message test, I added tests for both using Events and not using Events
  • in the rspec, not sure if it's better to use factorybot create(:distribution) instead of PUT

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • manual testing
  • bundle exec rake

Screenshots

image

    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
…t edit

* direct call to render doesn't load @Items causing partial to be unable
  to match item IDs to item names, resulting in displaying numbers
* replace with redirect to edit
@jimmyli97 jimmyli97 force-pushed the 4172-fix-donation-validation branch from 2b03b55 to e49ef32 Compare June 28, 2024 00:55
Error message changes if using events or not, add cases for both
@jimmyli97 jimmyli97 force-pushed the 4172-fix-donation-validation branch from e49ef32 to 0585857 Compare June 28, 2024 01:25
@cielf cielf requested a review from dorner June 29, 2024 19:53
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this approach won't do what we want. Can you verify?

@@ -84,7 +84,7 @@ def update
redirect_to donations_path
rescue => e
flash[:alert] = "Error updating donation: #{e.message}"
render "edit"
redirect_back(fallback_location: edit_donation_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this lose all the information you've entered?

Copy link
Contributor Author

@jimmyli97 jimmyli97 Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the existing behavior when I tested right now on the main branch commit e12311, I can try to change it and add a test so that it keeps all entered information except for the incorrect edited quantity if you want?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to be the correct thing to do, yes.

Copy link
Contributor Author

@jimmyli97 jimmyli97 Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up keeping all entered information including the incorrect edited quantity in commit 68cabfb, if that doesn't work let me know.

Note that per #4508 when testing READ_EVENTS must be set to true before a fixed donation can be submitted after an error.

…ate error

* Page should still display original donation source pre-edit in the title
  and breadcrumbs
@jimmyli97 jimmyli97 force-pushed the 4172-fix-donation-validation branch 5 times, most recently from 223b647 to 708bbbb Compare July 12, 2024 03:34
@jimmyli97 jimmyli97 force-pushed the 4172-fix-donation-validation branch from 708bbbb to 68cabfb Compare July 12, 2024 03:43
@jimmyli97 jimmyli97 requested a review from dorner July 12, 2024 03:55
donation_params[:line_items_attributes].values.each { |attr|
attr.delete(:_destroy)
line_items.push(attr)
}
Copy link
Collaborator

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?

Copy link
Contributor Author

@jimmyli97 jimmyli97 Jul 16, 2024

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

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>")
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

@jimmyli97 jimmyli97 Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved by 82a76fd

@jimmyli97 jimmyli97 force-pushed the 4172-fix-donation-validation branch 4 times, most recently from 1920943 to 44a6ef4 Compare July 17, 2024 03:24
@jimmyli97 jimmyli97 requested a review from dorner July 17, 2024 03:52
* _destroy parameter is not sent when deleting line items when tested on
  commit [#f747006](rubyforgood@f747006)
  (could not find commit when this change occurred)
* remove _destroy parameter reference in outdated rspec tests and donations
  controller code
@jimmyli97 jimmyli97 force-pushed the 4172-fix-donation-validation branch from 14dfdc6 to dfaa0e7 Compare July 17, 2024 19:45
dorner
dorner previously requested changes Jul 19, 2024
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, but there's a really huge test I'd like to try to sanitize if possible.

}
}

put donation_path(id: donation.id, donation: edited_donation)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

@jimmyli97 jimmyli97 Jul 20, 2024

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved by ba5af77

* Use TestInventory instead of distribution endpoint in rspec
* Use build(:line_item) instead of as_json merge
@jimmyli97 jimmyli97 requested a review from dorner July 23, 2024 02:09
@dorner
Copy link
Collaborator

dorner commented Jul 26, 2024

Looks good to me! @cielf did you want to take a look?

@cielf
Copy link
Collaborator

cielf commented Jul 27, 2024

Passes my manual testing

@awwaiid awwaiid dismissed dorner’s stale review August 4, 2024 19:52

Pending changes were addressed

Copy link
Collaborator

@awwaiid awwaiid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All set, thank you!

@awwaiid awwaiid merged commit be14a90 into rubyforgood:main Aug 4, 2024
19 checks passed
@jimmyli97 jimmyli97 deleted the 4172-fix-donation-validation branch August 5, 2024 00:25
Copy link
Contributor

@jimmyli97: Your PR Fix #4172 donation validation display error is part of today's Human Essentials production release: 2024.08.11.
Thank you very much for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] On Donation, drop down changes to show item number rather than description on edit error. It shouldn't.
4 participants