-
Notifications
You must be signed in to change notification settings - Fork 66
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
[16] ART: Filter PoA results list #20255
Conversation
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.
Final tweak
poa_requests = poa_request_scope.includes(includes).limit(100) | ||
rel = poa_request_scope | ||
|
||
if params[:status]&.downcase == 'pending' | ||
rel = rel.unresolved | ||
elsif params[:status]&.downcase == 'completed' | ||
rel = rel.resolved | ||
elsif params[:status].present? # throw 400 for other non-blank statuses | ||
raise Common::Exceptions::BadRequest.new( | ||
errors: "Invalid status parameter. Values accepted: 'pending' or 'completed'." | ||
) | ||
end | ||
|
||
poa_requests = rel.includes(includes).limit(100) |
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.
Let's represent this enum with a module defined in this controller:
module Statuses
ALL = [
PENDING = 'pending',
COMPLETED = 'completed'
].freeze
end
And then represent exhaustively matching against it with a case statement:
rel = poa_request_scope
status = params[:status].presence
rel =
case status
when Statuses::PENDING
rel.unresolved
when Statuses::COMPLETED
rel.resolved
when NilClass
rel
else
# Throw 400 for unexpected, non-blank statuses
raise ActionController::BadRequest.new(<<~MSG.squish)
Invalid status parameter.
Must be one of (#{Statuses::ALL.join(', ')})
MSG
end
Note:
- Use of
ActionController::BadRequest
for now, which mirrors how we're using other native Rails controller exceptions for now in our semi-shared exception handling - Even stricter about inputs (no
downcase
or other normalization), since we shouldn't present clients a loose API contract
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.
These were measures I added to prevent extra frustration if the frontend accidentally sent a lowercase version but that's ok. I still think we should ignore an empty status string (this rewrite will throw a 400) Nevermind I see the use of presence
1a80fa3
to
865f399
Compare
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.
ActionController::BadRequest
@@ -23,6 +23,13 @@ module PowerOfAttorneyRequests | |||
status: :unprocessable_entity | |||
) | |||
end | |||
|
|||
rescue_from Common::Exceptions::BadRequest do |e| |
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.
This would need to handle ActionController::BadRequest
now since we switched to raising that.
d3bcc6c
to
a07f73c
Compare
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.
A couple additional things.
|
||
it 'throws an error if any other status filter provided' do | ||
get('/accredited_representative_portal/v0/power_of_attorney_requests?status=delete_all') | ||
expect(response).to have_http_status(:internal_server_error) |
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.
should be :bad_request after we reflect the changed exception type in our exception rendering.
AccreditedRepresentativePortal::PowerOfAttorneyForm.delete_all | ||
AccreditedRepresentativePortal::PowerOfAttorneyRequestResolution.delete_all | ||
AccreditedRepresentativePortal::PowerOfAttorneyRequest.delete_all |
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.
We shouldn't need these. I think we make our test suite run with transaction-oriented database cleaning on a per-spec-example basis and I think the let!
is defeating that idea. Kind of just guessing, but I tried changing to let
and causing the creation at the top of each spec example and I didn't need the delete_all
's. There are very few delete_all
's in the spec suite. For now, let's use let
and cause the creation at the top of each example.
b2b6092
to
ac0540e
Compare
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.
LGTM
9d322dd
to
a7955d6
Compare
The base branch was changed.
a5bc0bc
to
98ab588
Compare
98ab588
to
d4765a5
Compare
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 mentioned this in another PR https://github.com/department-of-veterans-affairs/vets-api/pull/20321/files
Please remove the Statuses module and use the constants directly
PENDING = 'pending'.freeze
COMPLETED = 'completed'.freeze
ALL = [PENDING, COMPLETED].freeze
73d90b6
to
97d0069
Compare
Linter is making me remove the Rebased with master and pushed |
97d0069
to
812046b
Compare
Sorry, old habit die hard.. no need to freeze |
@stevenjcumming @pixiitech Is it a requirement to remove the namespacing of our related constants? This is a pattern I have used and seen in many many places and indeed would encourage elsewhere within our module. This seems like more of a stylistic suggestion. Without the scoping I'd at least ask for the variable name to now reflect the repeated constant name prefix TL;DR: can we merge this with the original namespacing? |
@nihil2501 It is stylistic. I'm not a fan of it, unless it's used in outside the class (no issue with that). Prefixes are fine, you can call is STATUSES = [], or use a hash, etc. I meant to just illustrate my intent not specifically suggest that, apologies for the confusion. can we merge this with the original namespacing? |
812046b
to
26f41ac
Compare
dropped last commit and rebased |
@stevenjcumming I think I see the perspective about internal versus external. Of the other options I'd probably prefer: STATUSES = {
PENDING: 'pending',
COMPLETED: 'completed'
}
STATUSES.values # to get all of them In any event, this code is going to be modified more and more heavily to an encapsulated module for doing all the things that one needs to do for searching: defaulting, query building, invalidity, etc. So here I just wanted to suggest by example that that kind of encapsulation is forthcoming. |
Summary
status=Pending
orstatus=Completed
param to the power_of_attorney_requests endpoint to filter the listRelated issue(s)
Link to ticket created in va.gov-team repo OR screenshot of Jira ticket if your team uses Jira
Forward And Filter By Status In POA Request List Endpoint va.gov-team#98714
Link to previous change of the code/bug (if applicable)
Link to epic if not included in ticket
Testing done
New code is covered by unit tests
Describe what the old behavior was prior to the change
power_of_attorney_requests endpoint would return a list of all PoA request without filtering capability
Describe the steps required to verify your changes are working as expected. Exclusively stating 'Specs run' is NOT acceptable as appropriate testing
Run
rails accredited_representative_portal:seed
in developmentaccessing the power_of_attorney_requests endpoint with a logged in user with the
?status=Pending
should yield 12 PoA requestsaccessing the power_of_attorney_requests endpoint with a logged in user with the
?status=Completed
should yield 111 PoA requestsIf this work is behind a flipper:
Screenshots
Note: Optional
What areas of the site does it impact?
(Describe what parts of the site are impacted andifcode touched other areas)
Accredited Representative Portal
Acceptance criteria
Requested Feedback
(OPTIONAL)What should the reviewers know in addition to the above. Is there anything specific you wish the reviewer to assist with. Do you have any concerns with this PR, why?