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

Make purchase helper pick default storage location #4722

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

lenikadali
Copy link

Resolves #4436

Description

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Screenshots

Changed the purchase helper to use the default storage location
of the organization first, before using any other storage locations
that are available.

Also added a (failing) spec to check that we can see the option
on the page. Should be fixed in the next commit
@lenikadali lenikadali force-pushed the 4436-default-storage-location-for-purchase-donation branch from 8f44b71 to bf3a652 Compare October 14, 2024 19:15
Fixed the failing test by using the extended format
of the test expectation and used `subject` to make
an assertion regarding the response body.
@lenikadali
Copy link
Author

The next step here is to apply the default storage location (if set) to donations.

I see that the donations form was implemented differently from the purchases form in that we directly set the location in the form as shown here while the purchases form uses a helper function as shown here.

The open question: should we switch the donation form to use a (new) method declared in app/helpers/donations_helper.rb or directly check that the organization has a default storage location in the form?

@dorner
Copy link
Collaborator

dorner commented Oct 22, 2024

Wouldn't switching the donation form to use the same helper as purchases do what we need here?

@cielf
Copy link
Collaborator

cielf commented Oct 22, 2024

I don't know of any functional reason they shouldn't behave exactly the same, fwiw.

Added a test that when we begin to make a new donation,
we have a default storage location set.
Switched to use the helper method from PurchasesHelper
to set the default storage location for a donation
@lenikadali
Copy link
Author

Wouldn't switching the donation form to use the same helper as purchases do what we need here?

I think so. Why I would be hestitant to use it is separation of concerns etc.

Also something strange: in commit 231b516, I added a test to check that the default storage location was being used by checking the content of the form. The test passed 🤔 which made me think that there may be something I am missing regarding the behaviour of the new donation form versus the new purchases form.

Anyway in the subsequent commit e048651, I updated the form to use the method from the PurchasesHelper module and the test still passes.

This should be good for another review 🙏🏿

@cielf
Copy link
Collaborator

cielf commented Oct 23, 2024

Hey @lenikadali -- when a PR is ready for review, please change its status to "Open".

@lenikadali lenikadali marked this pull request as ready for review October 23, 2024 18:45
@cielf cielf self-requested a review November 7, 2024 14:19
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

LGTM from a functional POV

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.

Minor suggestion, otherwise looks good.

app/views/donations/_donation_form.html.erb Outdated Show resolved Hide resolved
Addressed review feedback namely:
* Renaming new_purchase_default_location to set_default_location
and moving it to ApplicationHelper. This allows us to use across
both the donation and purchase forms.
* Updated the tests and forms accordingly
* Added specs to ApplicationHelper to test that we are able
to successfully set the default storage location for purchases
and donations.
@lenikadali
Copy link
Author

Hi @dorner

Thanks a lot for the review 🙌 I think you can give it another look and it should be good 🤞

app/helpers/application_helper.rb Outdated Show resolved Hide resolved
end
end

describe "#set_default_location for donation" do
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to copy the same test for all things that have storage locations - all we're doing is referencing the storage_location_id of that thing.

Copy link
Author

Choose a reason for hiding this comment

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

I've opted to keep one test as per commit 2716706 so that we guarantee the functionality of the method and any subsequent changes to it.

Let me know if that is in keeping with what you were suggesting or your proposal was to remove the test altogether.

Renamed the method as per review suggestion
and keep only one test since we only need to test
that the default storage location is successfully set
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.

Looks good!

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.

oof... @lenikadali tests are failing now. :(

@lenikadali
Copy link
Author

oof... @lenikadali tests are failing now. :(

Should be green in the next run @dorner

It seems I forgot to update the other usages of set_default_location to `default_location. Commit b88b36c should let the next run pass 🤞

@lenikadali
Copy link
Author

Found that I hadn't update the view code to use the new method; hopefully the pipeline passes now 🤞
Thanks a lot for your patience everybody 🙌

@lenikadali
Copy link
Author

lenikadali commented Nov 29, 2024

Took a look at the last failing spec and I am not sure how to fix it. Currently if you make the following changes to the spec/requests/donations_requests_spec.rb:

-        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 value=\"#{edited_source_drive_participant.id}\">#{edited_source_drive_participant_business_name}</option>")

The spec will pass. Probably because we've changed the form's behaviour:

-                        selected: donation_form.product_drive_participant_id,
+                        selected: default_location(@donation),

Should I update the spec? (I am not sure how or what the desired behaviour in this case would be)

@dorner
Copy link
Collaborator

dorner commented Nov 30, 2024

@lenikadali yes, let's update the spec so it matches the new behavior.

Updated spec to match the new behaviour of
the donation form.
@lenikadali
Copy link
Author

Updated the spec. The pipeline should be green now 🤞

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.

Storage Location on purchase and donation should default to the Default Intake Location
3 participants