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

Always use mhv_user_account cached response on User #20216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rileyanderson
Copy link
Contributor

@rileyanderson rileyanderson commented Jan 9, 2025

Summary

  • User#mhv_user_account will always use the cached version. If there is no cached version, it will return nil.

Related issue(s)

Testing

  • make sure your local cache is enabled rails dev:cache
  • Cache the mhv_user_account request for the user you will login with
    • start a rails server - rails s
    • in rails console - rails c:
      icn = 1012667122V019349 # change to the icn of the user you will login with (they need to have accepted TOU)
      
      user_account = User.find_by(icn:)
      user_verification = user_account.user_verifications.idme.first 
      
      MHV::UserAccount::Creator.new(user_verification:).perform
    • Check to make sure the response was cached
      cache_key = "mhv_account_creation_#{icn}"
      
      Rails.cache.read(cache_key)
      # => {:user_profile_id=>"12345678", :premium=>true, :champ_va=>true, :patient=>true, :sm_account_created=>true, :message=>"Existing MHV Account Found for ICN"} 
  • Start vets-website and login
  • go to http://localhost:3000/v0/user and copy uuid
  • Find your user in the rails console and call mhv_user_account:
    user = User.find(uuid)
    
    user.mhv_user_account
    this should return the MHVUserAccount since it is cached and not make a call to MHV
  • Delete response from cache and call user.mhv_user_account again, this should return nil and not make a call to MHV
    Rails.cache.delete(cache_key)
    
    user.mhv_user_account
    # => nil

What areas of the site does it impact?

User, mhv user account

Acceptance criteria

  • I fixed|updated|added unit tests and integration tests for each feature (if applicable).
  • No error nor warning in the console.
  • Events are being sent to the appropriate logging solution
  • No sensitive information (i.e. PII/credentials/internal URLs/etc.) is captured in logging, hardcoded, or specs
  • If app impacted requires authentication, did you login to a local build and verify all authenticated routes work as expected

@rileyanderson rileyanderson marked this pull request as ready for review January 9, 2025 22:40
@rileyanderson rileyanderson requested a review from a team as a code owner January 9, 2025 22:40
@@ -30,16 +31,17 @@ def perform
private

def create_mhv_user_account!
return mhv_account_creation_response if mhv_account_creation_response.nil? && from_cache_only
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this doesn't return a MHVUserAccount?

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 it to explicitly return nil. if there is nothing in the cache and we only want to pull from the cache we return nil, otherwise we try to create an MHVUserAccount

Copy link
Contributor

@bosawt bosawt left a comment

Choose a reason for hiding this comment

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

Confirmed user.mhv_correlation_id did not call service, and returned nil, until service was successfully called, and then returned account id after that

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

Successfully merging this pull request may close these issues.

3 participants