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

handling old/stale account requests #4622

Merged

Conversation

manuel1280
Copy link
Contributor

@manuel1280 manuel1280 commented Aug 30, 2024

Checklist:

  • I have performed a self-review of my own code,
  • I have commented my code, particularly in hard-to-understand areas,
  • I have made corresponding changes to the documentation,
  • I have added tests that prove my fix is effective or that my feature works,
  • New and existing unit tests pass locally with my changes ("bundle exec rake"),
  • Title includes "WIP" if work is in progress.

Resolves #4514

Description

This new button allows admin users to close old and stale Account requests without sending emails or notifications. this new feature is relevant to clean up data easily. my approach for the solution was:

  • I reused the existing button 'Reject' and its modal by a dynamic code in javascript
  • unnecessary code was removed and reactors were made
  • following the current pattern of no-rest actions, the 'close' action was created
  • create test files

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

running these files

  • account_request_spec.rb
  • account_requests_controller_spec.rb
  • manually testing

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.

Looks really great -- one very minor request to change the type of db update to ! method so it'll raise an exception as needed.

# @param reason [String]
def close!(reason)
return false unless can_be_closed?
update(status: 'admin_closed', rejection_reason: reason)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
update(status: 'admin_closed', rejection_reason: reason)
update!(status: 'admin_closed', rejection_reason: reason)

Use an ! method like the others here so that it'll raise an exception if anything goes wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

@awwaiid
Copy link
Collaborator

awwaiid commented Aug 30, 2024

Ah -- I also ran all of the tests and you can see that a browser (system) spec failed, please take a look at that as well.

@manuel1280 manuel1280 force-pushed the 4514-closing-stale-account-requests branch 2 times, most recently from f3fffdf to b885cea Compare August 31, 2024 00:47
@manuel1280 manuel1280 force-pushed the 4514-closing-stale-account-requests branch 2 times, most recently from 06edd02 to a84ada2 Compare September 2, 2024 14:42
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.

Minor issue: During functional testing, I noted that the rejection reason has an asterisk on it, which indicates that it's mandatory, but I was able to complete the close without providing the reason.
Can you make the field mandatory, on close, please?

@manuel1280 manuel1280 force-pushed the 4514-closing-stale-account-requests branch from a84ada2 to 18606cd Compare September 5, 2024 15:48
@manuel1280
Copy link
Contributor Author

@cielf Hi, the Change is done, I made some code changes to make the validation easier

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.

Functionality looks good now.

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.

Had some further notes.

# @param reason [String]
def close!(reason)
return false unless can_be_closed?
update!(status: 'admin_closed', rejection_reason: reason)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry - changing this to update! means that this method will never return false - it'll raise an error if it can't save. That means you need to handle this error and return the message to the user rather than rely on true/false returns from this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed, what do you think?

app/views/admin/account_requests/_rejection_modal.html.erb Outdated Show resolved Hide resolved
expect(account_request.reload).to be_admin_closed
expect(flash[:notice]).to eq("Account request closed!")
expect(response).to redirect_to(admin_account_requests_path)
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should test where the update errors out (e.g. introduce a validation error). That would have caught the mistake above 😄

@@ -40,6 +40,19 @@
expect(page).not_to have_content(request4.name)
end
end

it 'should close the account', js: true do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we combine the expectations here with the request specs, so we don't need to do the same actions twice? We can just remove the request specs.

Copy link
Contributor Author

@manuel1280 manuel1280 Sep 7, 2024

Choose a reason for hiding this comment

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

I Couldn't test the validation errors in this spec because the button to "Close" is only displayed on the open requests, therefore I tested the validation on the controller spec (above), also I removed the duplicated tests in that controller to avoid the same action twice

@manuel1280 manuel1280 force-pushed the 4514-closing-stale-account-requests branch 2 times, most recently from 35f548b to 7ab5c1c Compare September 7, 2024 19:14
@manuel1280 manuel1280 force-pushed the 4514-closing-stale-account-requests branch from 7ab5c1c to 87a9697 Compare September 7, 2024 19:29
@dorner
Copy link
Collaborator

dorner commented Sep 12, 2024

Looks good on my end. @cielf it's probably worth it to do one more test for function.

@cielf cielf dismissed awwaiid’s stale review September 12, 2024 18:36

If I understand correctly, this requested change wasn't actually going to work correctly -- and @dorner has approved the final version.

@cielf cielf merged commit badeff0 into rubyforgood:main Sep 12, 2024
12 checks passed
Copy link
Contributor

@manuel1280: Your PR handling old/stale account requests is part of today's Human Essentials production release: 2024.09.15.
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.

Handling old/stale account requests
4 participants